fix(kb.gbapp): #361 GPT functions in Word.
This commit is contained in:
parent
d7cb00f4ce
commit
edd800f36e
2 changed files with 20 additions and 20 deletions
|
@ -198,7 +198,7 @@ export class GBVMService extends GBService {
|
|||
}
|
||||
} 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.
|
||||
|
||||
|
@ -207,7 +207,7 @@ export class GBVMService extends GBService {
|
|||
|
||||
const mapFile = `${filename}.map`;
|
||||
|
||||
Fs.writeFileSync(mapFile, JSON.stringify(jsonMap));
|
||||
Fs.writeFileSync(mapFile, JSON.stringify(map));
|
||||
|
||||
// Run JS into the GB context.
|
||||
|
||||
|
|
|
@ -36,6 +36,9 @@ import { GBMinInstance } from 'botlib';
|
|||
import OpenAI from "openai";
|
||||
import { ChatGPTAPIBrowser, getOpenAIAuth } from 'chatgpt'
|
||||
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 {
|
||||
|
||||
|
@ -52,24 +55,21 @@ export class ChatServices {
|
|||
throw new Error('Open AI Key not configured in .gbot.');
|
||||
}
|
||||
let functions = [];
|
||||
|
||||
|
||||
// Adds .gbdialog as functions if any to GPT Functions.
|
||||
|
||||
await CollectionUtil.asyncForEach(Object.values(min.scriptMap), async script => {
|
||||
|
||||
functions.push({
|
||||
"name": "get_current_weather",
|
||||
"description": "Get the current weather in a given location",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"location": {
|
||||
"type": "string",
|
||||
"description": "The city and state, e.g. San Francisco, CA",
|
||||
},
|
||||
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
|
||||
},
|
||||
"required": ["location"],
|
||||
} });
|
||||
});
|
||||
const path = DialogKeywords.getGBAIPath(min.botId, "gbdialog", null);
|
||||
const localFolder = Path.join('work', path, `${script}.json`);
|
||||
|
||||
if (Fs.existsSync(localFolder)) {
|
||||
const func = Fs.readFileSync(localFolder).toJSON();
|
||||
functions.push(func);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Calls Model.
|
||||
|
||||
const openai = new OpenAI({
|
||||
apiKey: key
|
||||
|
@ -110,7 +110,7 @@ export class ChatServices {
|
|||
const chatCompletion = await openai.chat.completions.create({
|
||||
model: "gpt-3.5-turbo",
|
||||
messages: [{ role: "user", content: text }]
|
||||
|
||||
|
||||
});
|
||||
return chatCompletion.choices[0].message.content;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue