Chat

class Chat

Class for a chat session.

add_message(message: Message) None

Add a message to the chat.

Parameters:

message (Message) – Message to be added to the chat.

Returns:

None

Return type:

None

generate_prompt_anthropic() str

Generate prompt from the chat in Anthropic’s format.

Returns:

Prompt string in Anthropic’s format.

Return type:

str

generate_messages_openai() list[dict]

Generate message list from the chat in OpenAI’s format.

Returns:

List of messages in OpenAI’s format.

Return type:

list

property messages

List of messages in the chat.

Returns:

List of messages.

Return type:

list

class Message(text: str, role: Role)

Class for a message.

Parameters:
  • text (str) – Text of the message.

  • role (Role) – Role of the message.

Example

from llmbox.chat import Message, Role

message = Message(text='How big is the earth?', role=Role.User)
class Role(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

List of roles.

User = 'user'
Assistant = 'assistant'