Class Chat

A chat is a conversation between a user and a machine. The machine can interact with external services (see Service).

Example

const chat = new Chat();
chat.registerService('currency', new CurrencyService());
chat.addUserInput('Hello bot!');
chat.addAssistantOutput('{"message":"Hello human!"}');

Hierarchy

  • Chat

Constructors

  • Parameters

    • Optional config: {
          prompt?: string;
      }
      • Optional prompt?: string

    Returns Chat

Properties

_messages: ChatMessage[] = []
_prompt: string
_services: Record<string, Service> = {}

Accessors

  • get lastMessage(): ChatMessage
  • Returns the last message in the chat. The message is returned as a deep clone to prevent accidental mutation.

    Returns ChatMessage

  • get messages(): ChatMessage[]
  • Returns the messages in the chat. The messages are returned as a deep clone to prevent accidental mutation. The messages are returned in the order they were added. The first message is the prompt.

    Returns ChatMessage[]

  • get prompt(): string
  • Returns the prompt for the chat.

    Returns string

Methods

  • Adds a message from the user to the chat.

    Parameters

    • message: string

    Returns void

  • Starts the conversation

    Returns void

  • Type Parameters

    • N extends string

    • S extends Service

    Parameters

    • name: N & (N extends keyof Chat
          ? never
          : N)
    • service: S

    Returns Chat & {
        [K in string]: S
    }

Generated using TypeDoc