fix(kb.gbapp): #361 GPT functions in Word.

This commit is contained in:
Rodrigo Rodriguez 2023-09-20 15:25:44 -03:00
parent d7cb00f4ce
commit edd800f36e
2 changed files with 20 additions and 20 deletions

View file

@ -198,7 +198,7 @@ export class GBVMService extends GBService {
} }
} while (include); } while (include);
let { code, map: jsonMap, metadata } = await this.convert(mainName, basicCode); let { code, map, metadata } = await this.convert(mainName, basicCode);
// Generates function JSON metadata to be used later. // Generates function JSON metadata to be used later.
@ -207,7 +207,7 @@ export class GBVMService extends GBService {
const mapFile = `${filename}.map`; const mapFile = `${filename}.map`;
Fs.writeFileSync(mapFile, JSON.stringify(jsonMap)); Fs.writeFileSync(mapFile, JSON.stringify(map));
// Run JS into the GB context. // Run JS into the GB context.

View file

@ -36,6 +36,9 @@ import { GBMinInstance } from 'botlib';
import OpenAI from "openai"; import OpenAI from "openai";
import { ChatGPTAPIBrowser, getOpenAIAuth } from 'chatgpt' import { ChatGPTAPIBrowser, getOpenAIAuth } from 'chatgpt'
import { CollectionUtil } from 'pragmatismo-io-framework'; import { CollectionUtil } from 'pragmatismo-io-framework';
import { DialogKeywords } from '../../basic.gblib/services/DialogKeywords';
import Path from 'path';
import * as Fs from 'fs';
export class ChatServices { export class ChatServices {
@ -53,23 +56,20 @@ export class ChatServices {
} }
let functions = []; let functions = [];
await CollectionUtil.asyncForEach(Object.values(min.scriptMap), async script => { // Adds .gbdialog as functions if any to GPT Functions.
functions.push({ await CollectionUtil.asyncForEach(Object.values(min.scriptMap), async script => {
"name": "get_current_weather", const path = DialogKeywords.getGBAIPath(min.botId, "gbdialog", null);
"description": "Get the current weather in a given location", const localFolder = Path.join('work', path, `${script}.json`);
"parameters": {
"type": "object", if (Fs.existsSync(localFolder)) {
"properties": { const func = Fs.readFileSync(localFolder).toJSON();
"location": { functions.push(func);
"type": "string", }
"description": "The city and state, e.g. San Francisco, CA",
}, });
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
}, // Calls Model.
"required": ["location"],
} });
});
const openai = new OpenAI({ const openai = new OpenAI({
apiKey: key apiKey: key