Class ConversationHistoryInternal

The request options for a conversation.

This class is used internally by the library and is not meant to be instantiated by consumers of the library.

Hierarchy

  • ConversationHistory

Constructors

  • Parameters

    • pluginService: ConversationPluginService<ConversationPlugin<string, any, any>[]>
    • config: ConversationConfig
    • options: {
          messages?: ({ role: "function" | "user" | "assistant" | "system"; content: string | null; id?: string | undefined; name?: string | undefined; function_call?: { name: string; arguments: Record<string, any>; } | undefined; model?: string | undefined; flags?: string[] | ... 1 more ... | undefined; })[];
      } = {}
      • Optional messages?: ({ role: "function" | "user" | "assistant" | "system"; content: string | null; id?: string | undefined; name?: string | undefined; function_call?: { name: string; arguments: Record<string, any>; } | undefined; model?: string | undefined; flags?: string[] | ... 1 more ... | undefined; })[]

    Returns ConversationHistory

Properties

addMessageEvents: EventManager<AddMessageListener> = ...
messages: Message[] = []
pluginService: ConversationPluginService<ConversationPlugin<string, any, any>[]>
removeMessageEvents: EventManager<RemoveMessageListener> = ...

Methods

  • Adds a message with the role of "assistant" to the conversation with the function call generated by the assistant.

    Parameters

    • functionCall: {
          arguments: Record<string, any>;
          name: string;
      }

      The name and arguments of the function to call, generated by the assistant.

      • arguments: Record<string, any>
      • name: string

    Returns Message

    The Message object that was added to the conversation

  • Adds a message with the role of "function" to the conversation with the content being the return value of the function call, called by your own code.

    Parameters

    • message: string

      The return value of the function call, stringified if needed.

    • name: string

      The name of the function that was called.

    Returns Message

    The Message object that was added to the conversation

  • Adds a message to the conversation.

    Parameters

    • message: Message

      The message instance to add to the conversation.

    Returns Message

    The added message.

    Remarks

    This method is mostly meant to be internal, but exposed for convenience. You should use the addAssistantMessage, addUserMessage, addFunctionCallMessage, or addFunctionMessage methods when possible.

  • Adds a listener function that is called whenever a message is added to the conversation.

    Parameters

    • listener: AddMessageListener

      The function to call when a message is added to the conversation.

    Returns (() => void)

    A function that removes the listener from the list of listeners.

      • (): void
      • Returns void

  • Adds a listener function that is called whenever a message is removed to the conversation.

    Parameters

    Returns (() => void)

    A function that removes the listener from the list of listeners.

      • (): void
      • Returns void

  • Adds a listener function that is called only once whenever a message is added to the conversation.

    Parameters

    • listener: AddMessageListener

      The function to call when a message is added to the conversation.

    Returns (() => void)

    A function that removes the listener from the list of listeners.

      • (): void
      • Returns void

  • Adds a listener function that is called only once whenever a message is removed to the conversation.

    Parameters

    Returns (() => void)

    A function that removes the listener from the list of listeners.

      • (): void
      • Returns void

  • Removes a message from the conversation's history.

    Parameters

    • message: string | Message

      Either the ID of the message to remove, or the message object itself (where the ID will be extracted from).

    Returns void

  • Sets the first message sent to the OpenAI API with the role of "system". This gives context the Chat Completion and can be used to customize its behavior.

    Parameters

    • context: string

      The content of the system message.

    Returns void

  • Internal

    Serializes the ConversationHistory to JSON.

    Returns {
        messages?: ({ role: "function" | "user" | "assistant" | "system"; content: string | null; id?: string | undefined; name?: string | undefined; function_call?: { name: string; arguments: Record<string, any>; } | undefined; model?: string | undefined; flags?: string[] | ... 1 more ... | undefined; })[];
    }

    A JSON representation of the ConversationHistory instance.

    This method is used internally by the library and is not meant to be used by consumers of the library.

    • Optional messages?: ({ role: "function" | "user" | "assistant" | "system"; content: string | null; id?: string | undefined; name?: string | undefined; function_call?: { name: string; arguments: Record<string, any>; } | undefined; model?: string | undefined; flags?: string[] | ... 1 more ... | undefined; })[]

Generated using TypeDoc