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.
Extends
Implements
Constructors
new ContextChatEngine()
new ContextChatEngine(
init
):ContextChatEngine
Parameters
• init
• init.chatHistory?: ChatMessage
[]
• init.chatModel?: LLM
<object
, object
>
• init.contextRole?: MessageType
• init.contextSystemPrompt?
• init.nodePostprocessors?: BaseNodePostprocessor
[]
• init.retriever: BaseRetriever
• init.systemPrompt?: string
Returns
Overrides
Source
packages/core/src/engines/chat/ContextChatEngine.ts:36
Properties
chatHistory
chatHistory:
ChatHistory
<object
>
Source
packages/core/src/engines/chat/ContextChatEngine.ts:32
chatModel
chatModel:
LLM
<object
,object
>
Source
packages/core/src/engines/chat/ContextChatEngine.ts:31
contextGenerator
contextGenerator:
ContextGenerator
Source
packages/core/src/engines/chat/ContextChatEngine.ts:33
systemPrompt?
optional
systemPrompt:string
Source
packages/core/src/engines/chat/ContextChatEngine.ts:34
Methods
_getPromptModules()
protected
_getPromptModules():Record
<string
,ContextGenerator
>
Returns
Record
<string
, ContextGenerator
>
Overrides
PromptMixin
. _getPromptModules
Source
packages/core/src/engines/chat/ContextChatEngine.ts:57
_getPrompts()
protected
_getPrompts():PromptsDict
Returns
PromptsDict
Inherited from
Source
packages/core/src/prompts/Mixin.ts:78
_updatePrompts()
protected
_updatePrompts(promptsDict
):void
Parameters
• promptsDict: PromptsDict
Returns
void
Inherited from
Source
packages/core/src/prompts/Mixin.ts:86
chat()
chat(params)
chat(
params
):Promise
<AsyncIterable
<Response
>>
Send message along with the class's current chat history to the LLM.
Parameters
• params: ChatEngineParamsStreaming
Returns
Promise
<AsyncIterable
<Response
>>
Implementation of
Source
packages/core/src/engines/chat/ContextChatEngine.ts:63
chat(params)
chat(
params
):Promise
<Response
>
Parameters
• params: ChatEngineParamsNonStreaming
Returns
Promise
<Response
>
Implementation of
Source
packages/core/src/engines/chat/ContextChatEngine.ts:64
getPrompts()
getPrompts():
PromptsDict
Returns all prompts from the mixin and its modules
Returns
PromptsDict
Inherited from
Source
packages/core/src/prompts/Mixin.ts:27
prepareRequestMessages()
private
prepareRequestMessages(message
,chatHistory
):Promise
<object
>
Parameters
• message: MessageContent
• chatHistory: ChatHistory
<object
>
Returns
Promise
<object
>
messages
messages:
ChatMessage
<object
>[]
nodes
nodes:
NodeWithScore
<Metadata
>[] =context.nodes
Source
packages/core/src/engines/chat/ContextChatEngine.ts:108
prependSystemPrompt()
private
prependSystemPrompt(message
):ChatMessage
Parameters
• message: ChatMessage
Returns
Source
packages/core/src/engines/chat/ContextChatEngine.ts:123
reset()
reset():
void
Resets the chat history so that it's empty.
Returns
void