new(whatsapp.gblib): Let GPT help call centers...

This commit is contained in:
Rodrigo Rodriguez 2023-08-02 13:58:11 -03:00
parent ef42aed4a3
commit 4c26cdf9db
3 changed files with 29 additions and 8 deletions

View file

@ -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.
*/

View file

@ -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;
}
}

View file

@ -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.