fix(llm.gblib): Tool fix. More templates.

This commit is contained in:
Rodrigo Rodriguez 2024-09-02 20:16:56 -03:00
parent 6aaae55a61
commit 6d814c0c1d
13 changed files with 122 additions and 105 deletions

View file

@ -168,13 +168,6 @@ export class GBAdminService implements IGBAdminService {
) {
const packageName = text.split(' ')[1];
if (!this.isSharePointPath(packageName)) {
const additionalPath = GBConfigService.get('ADDITIONAL_DEPLOY_PATH');
if (additionalPath === undefined) {
throw new Error('ADDITIONAL_DEPLOY_PATH is not set and deployPackage was called.');
}
await deployer['deployPackage2'](min, user, urlJoin(additionalPath, packageName));
} else {
const folderName = text.split(' ')[2];
const packageType = Path.extname(folderName).substr(1);
const gbaiPath = DialogKeywords.getGBAIPath(min.instance.botId, packageType, null);
@ -195,7 +188,7 @@ export class GBAdminService implements IGBAdminService {
await deployer['downloadFolder'](min, Path.join('work', `${gbai}`), Path.basename(localFolder));
}
await deployer['deployPackage2'](min, user, localFolder);
}
}
public static async rebuildIndexPackageCommand(min: GBMinInstance, deployer: GBDeployer) {
const service = await AzureDeployerService.createInstance(deployer);

View file

@ -986,7 +986,6 @@ export class AzureDeployerService implements IGBInstallationDeployer {
appSettings: [
{ name: 'WEBSITES_CONTAINER_START_TIME_LIMIT', value: `${WebSiteResponseTimeout}` },
{ name: 'WEBSITE_NODE_DEFAULT_VERSION', value: GBAdminService.getNodeVersion() },
{ name: 'ADDITIONAL_DEPLOY_PATH', value: `` },
{ name: 'ADMIN_PASS', value: `${instance.adminPass}` },
{ name: 'BOT_ID', value: `${instance.botId}` },
{ name: 'CLOUD_SUBSCRIPTIONID', value: `${instance.cloudSubscriptionId}` },

View file

@ -453,6 +453,7 @@ export class GBVMService extends GBService {
// Converts General Bots BASIC into regular VBS
let basicCode: string = Fs.readFileSync(filename, 'utf8');
basicCode = GBVMService.normalizeQuotes(basicCode);
// Pre process SET SCHEDULE calls.
@ -764,9 +765,6 @@ export class GBVMService extends GBService {
}
}
if (text) {
text = GBVMService.normalizeQuotes(text);
}
resolve(text);
});
});
@ -783,12 +781,13 @@ export class GBVMService extends GBService {
return text;
}
public static getMetadata(mainName: string, propertiesText, description) {
public static getMetadata(mainName: string, propertiesText: string[][], description: string) {
let properties = {};
if (!propertiesText || !description) {
return {};
}
const getType = asClause => {
const getType = (asClause: string) => {
asClause = asClause.trim().toUpperCase();
if (asClause.indexOf('STRING') !== -1) {
@ -808,29 +807,34 @@ export class GBVMService extends GBService {
let element;
if (t === 'enum') {
element = z.enum(propertiesExp[2].split(','));
const list = propertiesExp[2] as any;
element = z.enum(list.split(','));
} else if (t === 'string') {
element = z.string();
} else if (t === 'object') {
element = z.string();
element = z.string(); // Assuming 'object' is represented as a string here
} else if (t === 'number') {
element = z.number();
} else {
GBLog.warn(`Element type invalid specified on .docx: ${propertiesExp[0]}`);
}
element.describe(propertiesExp[3]);
element['description'] = propertiesExp[4]?.trim(); // Assuming description is in the 4th index
element['type'] = t;
properties[propertiesExp[1].trim()] = element;
}
let json = {
const json = {
type: 'function',
function: {
name: `${mainName}`,
name: mainName,
description: description ? description : '',
parameters: zodToJsonSchema(z.object(properties))
}
},
arguments: propertiesText.reduce((acc, prop) => {
acc[prop[1].trim()] = prop[3]?.trim(); // Assuming value is in the 3rd index
return acc;
}, {})
};
return json;
@ -913,7 +917,7 @@ export class GBVMService extends GBService {
// Pre-process "off-line" static KEYWORDS.
let emmit = true;
const params = /^\s*PARAM\s*(.*)\s*AS\s*(.*)\s*LIKE\s*(.*)/gim;
const params = /^\s*PARAM\s*(.*)\s*AS\s*(.*)\s*LIKE\s*(.*)\s*DESCRIPTION\s*(.*)/gim;
const param = params.exec(line);
if (param) {
properties.push(param);

View file

@ -48,7 +48,7 @@ import { GBSSR } from '../../core.gbapp/services/GBSSR.js';
import urlJoin from 'url-join';
import Excel from 'exceljs';
import { BufferWindowMemory } from 'langchain/memory';
import { TwitterApi } from 'twitter-api-v2';
import csvdb from 'csv-database';
import Path from 'path';
import ComputerVisionClient from '@azure/cognitiveservices-computervision';
import ApiKeyCredentials from '@azure/ms-rest-js';
@ -355,7 +355,10 @@ export class SystemKeywords {
// Capture memory usage after GC
const memoryAfterGC = process.memoryUsage().heapUsed / 1024 / 1024; // in MB
GBLogEx.info(min, `BASIC: Closing Handles... From ${memoryBeforeGC.toFixed(2)} MB to ${memoryAfterGC.toFixed(2)} MB`);
GBLogEx.info(
min,
`BASIC: Closing Handles... From ${memoryBeforeGC.toFixed(2)} MB to ${memoryAfterGC.toFixed(2)} MB`
);
}
public async asPDF({ pid, data }) {
@ -755,7 +758,6 @@ export class SystemKeywords {
let rowsDest = [];
rows.forEach(row => {
if (GBUtil.hasSubObject(row)) {
row = this.flattenJSON(row);
}
@ -1039,7 +1041,7 @@ export class SystemKeywords {
public static async getFilter(text) {
let filter;
const operators = [/\<\=/, /\<\>/, /\>\=/, /\</, /\>/, /\bnot in\b/, /\bin\b/, /\=/];
const operators = [/\<\=/, /\<\>/, /\>\=/, /\</, /\>/,/\blike\b/, /\bnot in\b/, /\bin\b/, /\=/];
let done = false;
await CollectionUtil.asyncForEach(operators, async op => {
var re = new RegExp(op, 'gi');
@ -1193,6 +1195,23 @@ export class SystemKeywords {
header = results.text[0];
rows = results.text;
} else if (file.indexOf('.csv') !== -1) {
let res;
let path = DialogKeywords.getGBAIPath(min.botId, `gbdata`);
const csvFile = Path.join(GBConfigService.get('STORAGE_LIBRARY'), path, file);
const firstLine = Fs.readFileSync(csvFile, 'utf8').split('\n')[0];
const headers = firstLine.split(',');
const db = await csvdb(csvFile, headers, ',');
if (args[0]) {
const systemFilter = await SystemKeywords.getFilter(args[0]);
let filter = {};
filter[systemFilter.columnName] = systemFilter.value;
res = await db.get(filter);
} else {
res = await db.get();
}
return res.length > 1 ? res : res[0];
} else {
const t = this.getTableFromName(file, min);
@ -2446,31 +2465,24 @@ export class SystemKeywords {
}
/**
* Publishs a tweet to X.
* Publishs a post to BlueSky .
*
* TWEET "My tweet text"
* BlueSky "My BlueSky text"
*/
public async tweet({ pid, text }) {
public async postToBlueSky({ pid, text }) {
const { min, user } = await DialogKeywords.getProcessInfo(pid);
const consumer_key = min.core.getParam(min.instance, 'Twitter Consumer Key', null);
const consumer_secret = min.core.getParam(min.instance, 'Twitter Consumer Key Secret', null);
const access_token_key = min.core.getParam(min.instance, 'Twitter Access Token', null);
const access_token_secret = min.core.getParam(min.instance, 'Twitter Access Token Secret', null);
const consumer_key = min.core.getParam(min.instance, 'BlueSky Consumer Key', null);
const consumer_secret = min.core.getParam(min.instance, 'BlueSky Consumer Key Secret', null);
const access_token_key = min.core.getParam(min.instance, 'BlueSky Access Token', null);
const access_token_secret = min.core.getParam(min.instance, 'BlueSky Access Token Secret', null);
if (!consumer_key || !consumer_secret || !access_token_key || !access_token_secret) {
GBLogEx.info(min, 'Twitter not configured in .gbot.');
GBLogEx.info(min, 'BlueSky not configured in .gbot.');
}
throw new Error('Not implemented yet.');
const client = new TwitterApi({
appKey: consumer_key,
appSecret: consumer_secret,
accessToken: access_token_key,
accessSecret: access_token_secret
});
await client.v2.tweet(text);
GBLogEx.info(min, `Twitter Automation: ${text}.`);
GBLogEx.info(min, `BlueSky Automation: ${text}.`);
}
/**

View file

@ -424,10 +424,12 @@ export class GBMinService {
GBServer.globals.server
.all(`/${min.instance.botId}/whatsapp`, async (req, res) => {
if (req.query['hub.mode'] === 'subscribe') {
const val = req.query['hub.verify_token'];
const challenge = min.core.getParam<string>(min.instance, `Meta Challenge`, null);
if (val === process.env.META_CHALLENGE) {
if (challenge && val === challenge) {
res.send(req.query['hub.challenge']);
res.status(200);
GBLogEx.info(min, `Meta callback OK. ${JSON.stringify(req.query)}`);

View file

@ -621,7 +621,16 @@ export class ChatServices {
private static getToolsAsText(tools) {
return Object.keys(tools)
.map(toolname => `- ${tools[toolname].name}: ${tools[toolname].description}`)
.map(toolname => {
const tool = tools[toolname];
const properties = tool.lc_kwargs.parameters.properties;
const params = Object.keys(properties).map(param => {
const { description, type } = properties[param];
return `${param} (${type}): ${description}`;
}).join(', ');
return `- ${tool.name}: ${tool.description}\n Parameters: ${params?? 'No parameters'}`;
})
.join('\n');
}

View file

@ -1,7 +1,5 @@
name,price
Product A, 230
Product B, 120
Product C, 180
Product D, 250
Product E, 200
Product F, 150
fax, 500
TV, 1200
mobile,200
console, 250

1 name price
2 Product A fax 230 500
3 Product B TV 120 1200
4 Product C mobile 180 200
5 Product D console 250
Product E 200
Product F 150

View file

@ -1,6 +1,6 @@
PARAM product AS string LIKE "Product A"
DESCRIPTION "Returns the price of the given product."
PARAM product AS string LIKE telephone DESCRIPTION The name of the product to have the price retrieved.
DESCRIPTION Returns the price of the given product.
product = FIND "products.csv", "name LIKE ${product}"
product = FIND "products.csv", "name = ${product}"
price = product.price
RETURN price

View file

@ -4,6 +4,5 @@ There exist some helpful predefined internal tools which can help me by
extending my functionalities or get me helpful information.
These tools **should** be abstracted away from the user.
These tools can be invoked only by me before I respond to a user.
Here is the list of my internal tools:
END SYSTEM PROMPT

View file

@ -0,0 +1 @@
Meta Challenge,
1 Meta Challenge