Ana içeriğe geç

Class: ContextChatEngine

ContextChatEngine uses the Index to get the appropriate context for each query. The context is stored in the system prompt, and the chat history is preserved, ideally allowing the appropriate context to be surfaced for each query.

Hierarchy

Implements

Constructors

constructor

new ContextChatEngine(init): ContextChatEngine

Parameters

NameType
initObject
init.chatHistory?ChatMessage[]
init.chatModel?LLM<object, object>
init.contextSystemPrompt?(__namedParameters: { context: undefined | string = "" }) => string
init.nodePostprocessors?BaseNodePostprocessor[]
init.retrieverBaseRetriever<unknown>

Returns

ContextChatEngine

Overrides

PromptMixin.constructor

Defined in

packages/core/src/engines/chat/ContextChatEngine.ts:39

Properties

chatHistory

chatHistory: ChatHistory<object>

Defined in

packages/core/src/engines/chat/ContextChatEngine.ts:36


chatModel

chatModel: LLM<object, object>

Defined in

packages/core/src/engines/chat/ContextChatEngine.ts:35


contextGenerator

contextGenerator: ContextGenerator

Defined in

packages/core/src/engines/chat/ContextChatEngine.ts:37

Methods

_getPromptModules

_getPromptModules(): Record<string, ContextGenerator>

Returns

Record<string, ContextGenerator>

Overrides

PromptMixin._getPromptModules

Defined in

packages/core/src/engines/chat/ContextChatEngine.ts:58


_getPrompts

_getPrompts(): PromptsDict

Returns

PromptsDict

Inherited from

PromptMixin._getPrompts

Defined in

packages/core/src/prompts/Mixin.ts:79


_updatePrompts

_updatePrompts(promptsDict): void

Parameters

NameType
promptsDictPromptsDict

Returns

void

Inherited from

PromptMixin._updatePrompts

Defined in

packages/core/src/prompts/Mixin.ts:87


chat

chat(params): Promise<AsyncIterable<Response>>

Send message along with the class's current chat history to the LLM.

Parameters

NameType
paramsChatEngineParamsStreaming

Returns

Promise<AsyncIterable<Response>>

Implementation of

ChatEngine.chat

Defined in

packages/core/src/engines/chat/ContextChatEngine.ts:64

chat(params): Promise<Response>

Parameters

NameType
paramsChatEngineParamsNonStreaming

Returns

Promise<Response>

Implementation of

ChatEngine.chat

Defined in

packages/core/src/engines/chat/ContextChatEngine.ts:65


getPrompts

getPrompts(): PromptsDict

Returns all prompts from the mixin and its modules

Returns

PromptsDict

Inherited from

PromptMixin.getPrompts

Defined in

packages/core/src/prompts/Mixin.ts:27


prepareRequestMessages

prepareRequestMessages(message, chatHistory): Promise<{ messages: ChatMessage<object>[] ; nodes: NodeWithScore<Metadata>[] = context.nodes }>

Parameters

NameType
messageMessageContent
chatHistoryChatHistory<object>

Returns

Promise<{ messages: ChatMessage<object>[] ; nodes: NodeWithScore<Metadata>[] = context.nodes }>

Defined in

packages/core/src/engines/chat/ContextChatEngine.ts:110


reset

reset(): void

Resets the chat history so that it's empty.

Returns

void

Implementation of

ChatEngine.reset

Defined in

packages/core/src/engines/chat/ContextChatEngine.ts:106


updatePrompts

updatePrompts(promptsDict): void

Updates the prompts in the mixin and its modules

Parameters

NameType
promptsDictPromptsDict

Returns

void

Inherited from

PromptMixin.updatePrompts

Defined in

packages/core/src/prompts/Mixin.ts:48


validatePrompts

validatePrompts(promptsDict, moduleDict): void

Validates the prompt keys and module keys

Parameters

NameType
promptsDictPromptsDict
moduleDictModuleDict

Returns

void

Inherited from

PromptMixin.validatePrompts

Defined in

packages/core/src/prompts/Mixin.ts:10