From f42e42c5e2aa7bcc93ade9500cc6e8de1e4e277d Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Wed, 22 May 2024 22:42:52 -0300 Subject: [PATCH] new(all): Auto import for logo, colors and website content. --- packages/gpt.gblib/services/ChatServices.ts | 21 ++++++++----------- .../services/WhatsappDirectLine.ts | 2 +- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/packages/gpt.gblib/services/ChatServices.ts b/packages/gpt.gblib/services/ChatServices.ts index 06ab28c9..90187636 100644 --- a/packages/gpt.gblib/services/ChatServices.ts +++ b/packages/gpt.gblib/services/ChatServices.ts @@ -41,7 +41,7 @@ import { import { RunnableSequence } from '@langchain/core/runnables'; import { convertToOpenAITool } from '@langchain/core/utils/function_calling'; import { ChatOpenAI } from '@langchain/openai'; -import { GBLog, GBMinInstance } from 'botlib'; +import { GBMinInstance } from 'botlib'; import * as Fs from 'fs'; import { jsonSchemaToZod } from 'json-schema-to-zod'; import { BufferWindowMemory } from 'langchain/memory'; @@ -49,8 +49,6 @@ import Path from 'path'; import { CollectionUtil } from 'pragmatismo-io-framework'; import { DialogKeywords } from '../../basic.gblib/services/DialogKeywords.js'; import { GBVMService } from '../../basic.gblib/services/GBVMService.js'; -import { GBConfigService } from '../../core.gbapp/services/GBConfigService.js'; -import { GuaribasSubject } from '../../kb.gbapp/models/index.js'; import { Serialized } from '@langchain/core/load/serializable'; import { BaseCallbackHandler } from '@langchain/core/callbacks/base'; import { pdfToPng, PngPageOutput } from 'pdf-to-png-converter'; @@ -252,7 +250,7 @@ export class ChatServices { */ public static async continue(min: GBMinInstance, question: string, chatId) {} - private static memoryMap = {}; + public static memoryMap = {}; public static userSystemPrompt = {}; public static async answerByGPT(min: GBMinInstance, user, question: string, mode = null) { @@ -269,7 +267,8 @@ export class ChatServices { memory = new BufferWindowMemory({ returnMessages: true, memoryKey: 'chat_history', - inputKey: 'input', + humanPrefix: 'input', + aiPrefix: 'output', k: 2 }); @@ -305,7 +304,7 @@ export class ChatServices { ${toolsAsText} - Do not use any previous tools output in the chat_history. + Do not use any previous tools output in the {chat_history}. ` ), new MessagesPlaceholder('chat_history'), @@ -343,17 +342,15 @@ export class ChatServices { *********************** \n\n{context}\n\n *********************** - - AND based on this chat history: - ************************ - \n\n{chat_history}\n\n - ************************ - Rephrase the response to the Human using the aforementioned context, considering this a high + + rephrase the response to the Human using the aforementioned context, considering this a high attention in answers, to give meaning with everything that has been said. If you're unsure of the answer, utilize any relevant context provided to answer the question effectively. Don“t output MD images tags url previously shown. ${LLMMode==='document-ref'? jsonInformation: ''} + + And based on this chat history and question, answer combined. ` ), new MessagesPlaceholder('chat_history'), diff --git a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts index 7fa72e15..1d9e28a4 100644 --- a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts +++ b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts @@ -1070,7 +1070,7 @@ export class WhatsappDirectLine extends GBService { user = await sec.updateUserInstance(id, instance.instanceId); await (activeMin as any).whatsAppDirectLine.resetConversationId(activeMin.botId, id, ''); const startDialog = activeMin.core.getParam(activeMin.instance, 'Start Dialog', null); - + ChatServices.memoryMap [user.userSystemId] = null; if (startDialog) { GBLogEx.info(this.min, `Calling /start for Auto start : ${startDialog} for ${activeMin.instance.botId}...`);