fix(basic.gblib): FUNCTION GPT.
This commit is contained in:
parent
49af4cfab7
commit
c6cd7cd5b8
3 changed files with 36 additions and 30 deletions
|
@ -266,7 +266,6 @@ export class GBVMService extends GBService {
|
|||
let connections = null;
|
||||
if (Fs.existsSync(filePath)) {
|
||||
connections = JSON.parse(Fs.readFileSync(filePath, 'utf8'));
|
||||
|
||||
}
|
||||
tableDef.forEach(async t => {
|
||||
|
||||
|
@ -725,19 +724,22 @@ export class GBVMService extends GBService {
|
|||
}
|
||||
|
||||
public static getMetadata(mainName: string, propertiesText, description) {
|
||||
let properties;
|
||||
if (!propertiesText) {
|
||||
|
||||
let properties = {};
|
||||
if (!propertiesText || !description) {
|
||||
|
||||
return {}
|
||||
}
|
||||
const getType = asClause => {
|
||||
if (asClause.indexOf('AS STRING') !== -1) {
|
||||
|
||||
asClause = asClause.trim().toUpperCase();
|
||||
|
||||
if (asClause.indexOf('STRING') !== -1) {
|
||||
return 'string';
|
||||
}
|
||||
else if (asClause.indexOf('AS OBJECT') !== -1) {
|
||||
else if (asClause.indexOf('OBJECT') !== -1) {
|
||||
return 'object';
|
||||
}
|
||||
else if (asClause.indexOf('AS INTEGER') !== -1 || asClause.indexOf('AS NUMBER') !== -1) {
|
||||
else if (asClause.indexOf('INTEGER') !== -1 || asClause.indexOf('NUMBER') !== -1) {
|
||||
return 'number';
|
||||
} else {
|
||||
return 'enum';
|
||||
|
@ -755,13 +757,16 @@ export class GBVMService extends GBService {
|
|||
} else if (t === 'string') {
|
||||
element = z.string();
|
||||
} else if (t === 'object') {
|
||||
element = z.quotelessJson({});
|
||||
element = z.string();
|
||||
} else if (t === 'number') {
|
||||
element = z.number();
|
||||
} else {
|
||||
GBLog.warn(`Element type invalid specified on .docx: ${propertiesExp[0]}`);
|
||||
}
|
||||
|
||||
element.describe(propertiesExp[3]);
|
||||
element['type'] = t;
|
||||
properties[propertiesExp[1]] = element;
|
||||
properties[propertiesExp[1].trim()] = element;
|
||||
}
|
||||
|
||||
|
||||
|
@ -862,7 +867,7 @@ export class GBVMService extends GBService {
|
|||
emmit = false;
|
||||
}
|
||||
|
||||
const descriptionKeyword = /^\s*DESCRIPTION\s*\"(.*)\"/gim;
|
||||
const descriptionKeyword = /^\s*DESCRIPTION\s(.*)/gim;
|
||||
let descriptionReg = descriptionKeyword.exec(line);
|
||||
if (descriptionReg) {
|
||||
description = descriptionReg[1];
|
||||
|
|
|
@ -81,7 +81,7 @@ export class ChatServices {
|
|||
subjects: GuaribasSubject[]
|
||||
) {
|
||||
|
||||
if (!process.env.OPENAI_KEY) {
|
||||
if (!process.env.OPENAI_API_KEY) {
|
||||
return { answer: undefined, questionId: 0 };
|
||||
}
|
||||
|
||||
|
@ -99,12 +99,13 @@ export class ChatServices {
|
|||
|
||||
// Adds .gbdialog as functions if any to GPT Functions.
|
||||
|
||||
await CollectionUtil.asyncForEach(Object.values(min.scriptMap), async script => {
|
||||
await CollectionUtil.asyncForEach(Object.keys(min.scriptMap), async script => {
|
||||
const path = DialogKeywords.getGBAIPath(min.botId, "gbdialog", null);
|
||||
const localFolder = Path.join('work', path, `${script}.json`);
|
||||
const functionJSON = Path.join('work', path, `${script}.json`);
|
||||
|
||||
if (Fs.existsSync(localFolder)) {
|
||||
const func = Fs.readFileSync(localFolder).toJSON();
|
||||
if (Fs.existsSync(functionJSON)) {
|
||||
const func = JSON.parse(Fs.readFileSync(functionJSON, 'utf8'));
|
||||
|
||||
functions.push(func);
|
||||
}
|
||||
|
||||
|
@ -117,7 +118,7 @@ export class ChatServices {
|
|||
// in plain text to be used in system prompt.
|
||||
|
||||
let functionDef = Object.keys(functions)
|
||||
.map((toolname) => `${toolname}: ${functions[toolname].description}`)
|
||||
.map((toolname) => `${functions[toolname].function.name}: ${functions[toolname].function.description}`)
|
||||
.join("\n");
|
||||
|
||||
let promptTemplate = `Answer in ${contentLocale}.
|
||||
|
@ -152,6 +153,7 @@ export class ChatServices {
|
|||
});
|
||||
|
||||
const llm = new ChatOpenAI({
|
||||
openAIApiKey: process.env.OPENAI_API_KEY,
|
||||
modelName: "gpt-3.5-turbo-0125",
|
||||
temperature: 0,
|
||||
});
|
||||
|
|
|
@ -314,7 +314,7 @@ export class KBService implements IGBKBService {
|
|||
query = `${query} ${text}`;
|
||||
}
|
||||
}
|
||||
|
||||
let returnedScore = 0;
|
||||
const key = instance.searchKey ? instance.searchKey :
|
||||
GBServer.globals.minBoot.instance.searchKey;
|
||||
const host = instance.searchHost ? instance.searchHost :
|
||||
|
@ -346,7 +346,7 @@ export class KBService implements IGBKBService {
|
|||
top: 1
|
||||
});
|
||||
|
||||
let returnedScore = 0;
|
||||
|
||||
|
||||
// Searches via Search (Azure Search).
|
||||
|
||||
|
@ -370,19 +370,18 @@ export class KBService implements IGBKBService {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
GBLog.info(
|
||||
`SEARCH returned LOW level score, calling GPT
|
||||
returnedScore: ${returnedScore} < required (searchScore): ${searchScore}`
|
||||
);
|
||||
|
||||
return await ChatServices.answerByGPT(min,pid,
|
||||
query,
|
||||
searchScore,
|
||||
subjects
|
||||
);
|
||||
|
||||
}
|
||||
GBLog.info(
|
||||
`SEARCH returned LOW level score, calling GPT
|
||||
returnedScore: ${returnedScore} < required (searchScore): ${searchScore}`
|
||||
);
|
||||
|
||||
return await ChatServices.answerByGPT(min,pid,
|
||||
query,
|
||||
searchScore,
|
||||
subjects
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue