new(all): Auto import for logo, colors and website content.
This commit is contained in:
parent
533fefe0da
commit
69ae924937
1 changed files with 30 additions and 16 deletions
|
@ -267,16 +267,13 @@ export class ChatServices {
|
||||||
memory = new BufferWindowMemory({
|
memory = new BufferWindowMemory({
|
||||||
returnMessages: true,
|
returnMessages: true,
|
||||||
memoryKey: 'chat_history',
|
memoryKey: 'chat_history',
|
||||||
humanPrefix: 'input',
|
inputKey: 'input',
|
||||||
aiPrefix: 'output',
|
|
||||||
k: 2
|
k: 2
|
||||||
});
|
});
|
||||||
|
|
||||||
this.memoryMap[user.userSystemId] = memory;
|
this.memoryMap[user.userSystemId] = memory;
|
||||||
}
|
} else {
|
||||||
else
|
memory = this.memoryMap[user.userSystemId];
|
||||||
{
|
|
||||||
memory = this.memoryMap[user.userSystemId]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const systemPrompt = user ? this.userSystemPrompt[user.userSystemId] : '';
|
const systemPrompt = user ? this.userSystemPrompt[user.userSystemId] : '';
|
||||||
|
@ -312,6 +309,13 @@ export class ChatServices {
|
||||||
Standalone question:`)
|
Standalone question:`)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const directPrompt = ChatPromptTemplate.fromMessages([
|
||||||
|
['system', systemPrompt],
|
||||||
|
new MessagesPlaceholder('chat_history'),
|
||||||
|
HumanMessagePromptTemplate.fromTemplate(`Follow Up Input: {question}
|
||||||
|
Standalone question:`)
|
||||||
|
]);
|
||||||
|
|
||||||
const toolsResultPrompt = ChatPromptTemplate.fromMessages([
|
const toolsResultPrompt = ChatPromptTemplate.fromMessages([
|
||||||
AIMessagePromptTemplate.fromTemplate(
|
AIMessagePromptTemplate.fromTemplate(
|
||||||
`The tool just returned value in last call. Using {chat_history}
|
`The tool just returned value in last call. Using {chat_history}
|
||||||
|
@ -348,7 +352,7 @@ export class ChatServices {
|
||||||
of the answer, utilize any relevant context provided to answer the question effectively.
|
of the answer, utilize any relevant context provided to answer the question effectively.
|
||||||
Don´t output MD images tags url previously shown.
|
Don´t output MD images tags url previously shown.
|
||||||
|
|
||||||
${LLMMode==='document-ref'? jsonInformation: ''}
|
${LLMMode === 'document-ref' ? jsonInformation : ''}
|
||||||
|
|
||||||
And based on this chat history and question, answer combined.
|
And based on this chat history and question, answer combined.
|
||||||
`
|
`
|
||||||
|
@ -357,6 +361,19 @@ export class ChatServices {
|
||||||
HumanMessagePromptTemplate.fromTemplate('Question: {question}')
|
HumanMessagePromptTemplate.fromTemplate('Question: {question}')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const directChain = RunnableSequence.from([
|
||||||
|
{
|
||||||
|
question: (question: string) => question,
|
||||||
|
chat_history: async () => {
|
||||||
|
const { chat_history } = await memory.loadMemoryVariables({});
|
||||||
|
return chat_history;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
directPrompt,
|
||||||
|
model,
|
||||||
|
new StringOutputParser()
|
||||||
|
]);
|
||||||
|
|
||||||
const callToolChain = RunnableSequence.from([
|
const callToolChain = RunnableSequence.from([
|
||||||
{
|
{
|
||||||
tool_output: async (output: object) => {
|
tool_output: async (output: object) => {
|
||||||
|
@ -415,16 +432,13 @@ export class ChatServices {
|
||||||
// .gbot switch LLMMode and choose the corresponding chain.
|
// .gbot switch LLMMode and choose the corresponding chain.
|
||||||
|
|
||||||
if (LLMMode === 'direct') {
|
if (LLMMode === 'direct') {
|
||||||
result = await (tools.length > 0 ? modelWithTools : model).invoke(`
|
|
||||||
${systemPrompt}
|
|
||||||
|
|
||||||
${question}`);
|
|
||||||
|
|
||||||
result = result.content;
|
result = directChain.invoke(question);
|
||||||
} else if (LLMMode === 'document-ref' || LLMMode === 'document') {
|
|
||||||
const res = await combineDocumentsChain.invoke(question);
|
|
||||||
|
|
||||||
result = res.text? res.text: res;
|
} else if (LLMMode === 'document-ref' || LLMMode === 'document') {
|
||||||
|
const res = await combineDocumentsChain.invoke(question);
|
||||||
|
|
||||||
|
result = res.text ? res.text : res;
|
||||||
sources = res.sources;
|
sources = res.sources;
|
||||||
} else if (LLMMode === 'function') {
|
} else if (LLMMode === 'function') {
|
||||||
result = await conversationalToolChain.invoke({
|
result = await conversationalToolChain.invoke({
|
||||||
|
|
Loading…
Add table
Reference in a new issue