From e4a4c127c9728c0a5fd2509fb5adb07deaaa351a Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Wed, 13 Mar 2024 09:04:30 -0300 Subject: [PATCH] new(security.gblib): SMS Auth. --- boot.mjs | 14 ++------- packages/gpt.gblib/services/ChatServices.ts | 31 ++++++++----------- .../services/WhatsappDirectLine.ts | 5 ++- 3 files changed, 19 insertions(+), 31 deletions(-) diff --git a/boot.mjs b/boot.mjs index b7433a56..45bc5470 100644 --- a/boot.mjs +++ b/boot.mjs @@ -9,18 +9,8 @@ import { GBUtil } from './dist/src/util.js'; // Displays version of Node JS being used at runtime and others attributes. -await GBUtil.sleep(80); -console.log(``); -console.log(``); -console.log(``); -await chalkAnimation.karaoke(` - █████ █████ ██ █ █████ █████ ████ ██ ████ █████ █████ ███ ® -██ █ ███ █ █ ██ ██ ██ ██ ██ ██ █ ██ ██ █ █ -██ ███ ████ █ ██ █ ████ █████ ██████ ██ ████ █ █ █ ██ -██ ██ █ █ ██ █ █ ██ ██ ██ ██ ██ ██ █ ██ ██ █ █ - █████ █████ █ ███ █████ ██ ██ ██ ██ █████ ████ █████ █ ███ -`,1000); -await GBUtil.sleep(80); +console.log(`General Bots is loading source code files...`); + var __dirname = process.env.PWD || process.cwd(); try { var run = () => { diff --git a/packages/gpt.gblib/services/ChatServices.ts b/packages/gpt.gblib/services/ChatServices.ts index 19bb6d74..76b1d585 100644 --- a/packages/gpt.gblib/services/ChatServices.ts +++ b/packages/gpt.gblib/services/ChatServices.ts @@ -67,9 +67,7 @@ import { ChatGeneration, Generation } from "@langchain/core/outputs"; export interface CustomOutputParserFields { } // This can be more generic, like Record -export type ExpectedOutput = { - greeting: string; -}; +export type ExpectedOutput = string; function isChatGeneration( llmOutput: ChatGeneration | Generation @@ -178,11 +176,7 @@ export class ChatServices { const context = min['vectorStore']; const modelWithTools = model.bind({ - tools: tools.map(convertToOpenAITool), - tool_choice: { - type: "function", - function: { name: "multiply" }, - }, + tools: tools.map(convertToOpenAITool) }); // Function for dynamically constructing the end of the chain based on the model-selected tool. @@ -209,7 +203,13 @@ export class ChatServices { const questionGeneratorTemplate = ChatPromptTemplate.fromMessages([ AIMessagePromptTemplate.fromTemplate( - "Given the following conversation about a codebase and a follow up question, rephrase the follow up question to be a standalone question." + `Answer the question without calling any tool, but if there is a need to call: + + + You have access to the following set of tools. Here are the names and descriptions for each tool: + + ${toolsAsText} + ` ), new MessagesPlaceholder("chat_history"), AIMessagePromptTemplate.fromTemplate(`Follow Up Input: {question} @@ -221,9 +221,7 @@ export class ChatServices { `Use the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer. \n\n{context}\n\n - You have the following tools to call: - ${toolsAsText}` - + ` ), new MessagesPlaceholder("chat_history"), HumanMessagePromptTemplate.fromTemplate("Question: {question}"), @@ -243,7 +241,7 @@ export class ChatServices { }, combineDocumentsPrompt, modelWithTools, - new CustomLLMOutputParser(), + ]); const conversationalQaChain = RunnableSequence.from([ @@ -256,11 +254,8 @@ export class ChatServices { }, questionGeneratorTemplate, modelWithTools, - new StringOutputParser(), - combineDocumentsChain, + new CustomLLMOutputParser() ]); - - const systemPrompt = user['systemPrompt']; @@ -283,7 +278,7 @@ export class ChatServices { private static getToolsAsText(tools) { return Object.keys(tools) - .map((toolname) => `${tools[toolname].name}: ${tools[toolname].description}`) + .map((toolname) => `- ${tools[toolname].name}: ${tools[toolname].description}`) .join("\n"); } diff --git a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts index 93572094..f3b69d88 100644 --- a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts +++ b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts @@ -802,6 +802,7 @@ export class WhatsappDirectLine extends GBService { id = req.from.split('@')[0]; senderName = req._data.notifyName; text = req.body; + botId=botId?? this.botId; break; } @@ -813,9 +814,11 @@ export class WhatsappDirectLine extends GBService { let toSwitchMin = GBServer.globals.minInstances.filter( p => p.instance.botId.toLowerCase() === text.toLowerCase() )[0]; + + botId = botId??GBServer.globals.minBoot.botId; GBLog.info(`A WhatsApp mobile requested instance for: ${botId}.`); - + let urlMin: any = GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0]; // Detects user typed language and updates their locale profile if applies. let min = urlMin;