diff --git a/packages/core.gbapp/services/GBMinService.ts b/packages/core.gbapp/services/GBMinService.ts index 679ce33e..27d9fac8 100644 --- a/packages/core.gbapp/services/GBMinService.ts +++ b/packages/core.gbapp/services/GBMinService.ts @@ -100,6 +100,7 @@ import { DebuggerService } from '../../basic.gblib/services/DebuggerService.js'; import { ImageProcessingServices } from '../../basic.gblib/services/ImageProcessingServices.js'; import { ScheduleServices } from '../../basic.gblib/services/ScheduleServices.js'; import mime from 'mime'; +import { ChatServices } from '../../gpt.gblib/services/ChatServices.js'; /** * Minimal service layer for a bot and encapsulation of BOT Framework calls. */ diff --git a/packages/gpt.gblib/services/ChatServices.ts b/packages/gpt.gblib/services/ChatServices.ts index 2711dbd6..ceaf060f 100644 --- a/packages/gpt.gblib/services/ChatServices.ts +++ b/packages/gpt.gblib/services/ChatServices.ts @@ -32,20 +32,35 @@ 'use strict'; -import { GBSSR }from '../../core.gbapp/services/GBSSR.js'; +import { GBMinInstance } from 'botlib'; +import { Configuration, OpenAIApi } from "openai"; export class ChatServices { - /** * Generate text - * + * * CONTINUE keword. - * + * * result = CONTINUE text - * + * */ - public static async continue (text, chatId) { - - } + public static async continue(min: GBMinInstance, text: string, chatId) { + let key = min.core.getParam(min.instance, 'Open AI Key', null); + + if (!key) { + throw new Error('Open AI Key not configured in .gbot.'); + } + + const configuration = new Configuration({ + apiKey: key, + }); + const openai = new OpenAIApi(configuration); + + const chatCompletion = await openai.createChatCompletion({ + model: "gpt-3.5-turbo", + messages: [{role: "user", content: text}], + }); + return chatCompletion.data.choices[0].message; } +} diff --git a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts index 87e76630..a84eca60 100644 --- a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts +++ b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts @@ -48,6 +48,7 @@ import express from 'express'; import { GBSSR } from '../../core.gbapp/services/GBSSR.js'; import pkg from 'whatsapp-web.js'; import { DialogKeywords } from '../../basic.gblib/services/DialogKeywords.js'; +import { ChatServices } from '../../gpt.gblib/services/ChatServices.js'; const { List, Buttons, Client, MessageMedia } = pkg; /** @@ -552,6 +553,10 @@ export class WhatsappDirectLine extends GBService { await this.endTransfer(from, locale, user, agent, sec); } else { GBLog.info(`USER (${from}) TO AGENT ${agent.userSystemId}: ${text}`); + + const prompt = `the person said: ${text}. what can I tell her?`; + const answer = ChatServices.continue(this.min, prompt, 0); + text = `${text} \n\nGeneral Bots: ${answer}` if (user.agentSystemId.indexOf('@') !== -1) { // Agent is from Teams or Google Chat.