fix(llm.gblib): Tool fix. More templates.
This commit is contained in:
parent
6aaae55a61
commit
6d814c0c1d
13 changed files with 122 additions and 105 deletions
|
@ -168,13 +168,6 @@ export class GBAdminService implements IGBAdminService {
|
||||||
) {
|
) {
|
||||||
const packageName = text.split(' ')[1];
|
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 folderName = text.split(' ')[2];
|
||||||
const packageType = Path.extname(folderName).substr(1);
|
const packageType = Path.extname(folderName).substr(1);
|
||||||
const gbaiPath = DialogKeywords.getGBAIPath(min.instance.botId, packageType, null);
|
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['downloadFolder'](min, Path.join('work', `${gbai}`), Path.basename(localFolder));
|
||||||
}
|
}
|
||||||
await deployer['deployPackage2'](min, user, localFolder);
|
await deployer['deployPackage2'](min, user, localFolder);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
public static async rebuildIndexPackageCommand(min: GBMinInstance, deployer: GBDeployer) {
|
public static async rebuildIndexPackageCommand(min: GBMinInstance, deployer: GBDeployer) {
|
||||||
const service = await AzureDeployerService.createInstance(deployer);
|
const service = await AzureDeployerService.createInstance(deployer);
|
||||||
|
|
|
@ -986,7 +986,6 @@ export class AzureDeployerService implements IGBInstallationDeployer {
|
||||||
appSettings: [
|
appSettings: [
|
||||||
{ name: 'WEBSITES_CONTAINER_START_TIME_LIMIT', value: `${WebSiteResponseTimeout}` },
|
{ name: 'WEBSITES_CONTAINER_START_TIME_LIMIT', value: `${WebSiteResponseTimeout}` },
|
||||||
{ name: 'WEBSITE_NODE_DEFAULT_VERSION', value: GBAdminService.getNodeVersion() },
|
{ name: 'WEBSITE_NODE_DEFAULT_VERSION', value: GBAdminService.getNodeVersion() },
|
||||||
{ name: 'ADDITIONAL_DEPLOY_PATH', value: `` },
|
|
||||||
{ name: 'ADMIN_PASS', value: `${instance.adminPass}` },
|
{ name: 'ADMIN_PASS', value: `${instance.adminPass}` },
|
||||||
{ name: 'BOT_ID', value: `${instance.botId}` },
|
{ name: 'BOT_ID', value: `${instance.botId}` },
|
||||||
{ name: 'CLOUD_SUBSCRIPTIONID', value: `${instance.cloudSubscriptionId}` },
|
{ name: 'CLOUD_SUBSCRIPTIONID', value: `${instance.cloudSubscriptionId}` },
|
||||||
|
|
|
@ -453,6 +453,7 @@ export class GBVMService extends GBService {
|
||||||
// Converts General Bots BASIC into regular VBS
|
// Converts General Bots BASIC into regular VBS
|
||||||
|
|
||||||
let basicCode: string = Fs.readFileSync(filename, 'utf8');
|
let basicCode: string = Fs.readFileSync(filename, 'utf8');
|
||||||
|
basicCode = GBVMService.normalizeQuotes(basicCode);
|
||||||
|
|
||||||
// Pre process SET SCHEDULE calls.
|
// Pre process SET SCHEDULE calls.
|
||||||
|
|
||||||
|
@ -764,9 +765,6 @@ export class GBVMService extends GBService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (text) {
|
|
||||||
text = GBVMService.normalizeQuotes(text);
|
|
||||||
}
|
|
||||||
resolve(text);
|
resolve(text);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -783,12 +781,13 @@ export class GBVMService extends GBService {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static getMetadata(mainName: string, propertiesText, description) {
|
public static getMetadata(mainName: string, propertiesText: string[][], description: string) {
|
||||||
let properties = {};
|
let properties = {};
|
||||||
if (!propertiesText || !description) {
|
if (!propertiesText || !description) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
const getType = asClause => {
|
|
||||||
|
const getType = (asClause: string) => {
|
||||||
asClause = asClause.trim().toUpperCase();
|
asClause = asClause.trim().toUpperCase();
|
||||||
|
|
||||||
if (asClause.indexOf('STRING') !== -1) {
|
if (asClause.indexOf('STRING') !== -1) {
|
||||||
|
@ -808,29 +807,34 @@ export class GBVMService extends GBService {
|
||||||
let element;
|
let element;
|
||||||
|
|
||||||
if (t === 'enum') {
|
if (t === 'enum') {
|
||||||
element = z.enum(propertiesExp[2].split(','));
|
const list = propertiesExp[2] as any;
|
||||||
|
element = z.enum(list.split(','));
|
||||||
} else if (t === 'string') {
|
} else if (t === 'string') {
|
||||||
element = z.string();
|
element = z.string();
|
||||||
} else if (t === 'object') {
|
} else if (t === 'object') {
|
||||||
element = z.string();
|
element = z.string(); // Assuming 'object' is represented as a string here
|
||||||
} else if (t === 'number') {
|
} else if (t === 'number') {
|
||||||
element = z.number();
|
element = z.number();
|
||||||
} else {
|
} else {
|
||||||
GBLog.warn(`Element type invalid specified on .docx: ${propertiesExp[0]}`);
|
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;
|
element['type'] = t;
|
||||||
properties[propertiesExp[1].trim()] = element;
|
properties[propertiesExp[1].trim()] = element;
|
||||||
}
|
}
|
||||||
|
|
||||||
let json = {
|
const json = {
|
||||||
type: 'function',
|
type: 'function',
|
||||||
function: {
|
function: {
|
||||||
name: `${mainName}`,
|
name: mainName,
|
||||||
description: description ? description : '',
|
description: description ? description : '',
|
||||||
parameters: zodToJsonSchema(z.object(properties))
|
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;
|
return json;
|
||||||
|
@ -913,7 +917,7 @@ export class GBVMService extends GBService {
|
||||||
// Pre-process "off-line" static KEYWORDS.
|
// Pre-process "off-line" static KEYWORDS.
|
||||||
|
|
||||||
let emmit = true;
|
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);
|
const param = params.exec(line);
|
||||||
if (param) {
|
if (param) {
|
||||||
properties.push(param);
|
properties.push(param);
|
||||||
|
|
|
@ -48,7 +48,7 @@ import { GBSSR } from '../../core.gbapp/services/GBSSR.js';
|
||||||
import urlJoin from 'url-join';
|
import urlJoin from 'url-join';
|
||||||
import Excel from 'exceljs';
|
import Excel from 'exceljs';
|
||||||
import { BufferWindowMemory } from 'langchain/memory';
|
import { BufferWindowMemory } from 'langchain/memory';
|
||||||
import { TwitterApi } from 'twitter-api-v2';
|
import csvdb from 'csv-database';
|
||||||
import Path from 'path';
|
import Path from 'path';
|
||||||
import ComputerVisionClient from '@azure/cognitiveservices-computervision';
|
import ComputerVisionClient from '@azure/cognitiveservices-computervision';
|
||||||
import ApiKeyCredentials from '@azure/ms-rest-js';
|
import ApiKeyCredentials from '@azure/ms-rest-js';
|
||||||
|
@ -355,7 +355,10 @@ export class SystemKeywords {
|
||||||
|
|
||||||
// Capture memory usage after GC
|
// Capture memory usage after GC
|
||||||
const memoryAfterGC = process.memoryUsage().heapUsed / 1024 / 1024; // in MB
|
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 }) {
|
public async asPDF({ pid, data }) {
|
||||||
|
@ -755,7 +758,6 @@ export class SystemKeywords {
|
||||||
let rowsDest = [];
|
let rowsDest = [];
|
||||||
|
|
||||||
rows.forEach(row => {
|
rows.forEach(row => {
|
||||||
|
|
||||||
if (GBUtil.hasSubObject(row)) {
|
if (GBUtil.hasSubObject(row)) {
|
||||||
row = this.flattenJSON(row);
|
row = this.flattenJSON(row);
|
||||||
}
|
}
|
||||||
|
@ -1039,7 +1041,7 @@ export class SystemKeywords {
|
||||||
|
|
||||||
public static async getFilter(text) {
|
public static async getFilter(text) {
|
||||||
let filter;
|
let filter;
|
||||||
const operators = [/\<\=/, /\<\>/, /\>\=/, /\</, /\>/, /\bnot in\b/, /\bin\b/, /\=/];
|
const operators = [/\<\=/, /\<\>/, /\>\=/, /\</, /\>/,/\blike\b/, /\bnot in\b/, /\bin\b/, /\=/];
|
||||||
let done = false;
|
let done = false;
|
||||||
await CollectionUtil.asyncForEach(operators, async op => {
|
await CollectionUtil.asyncForEach(operators, async op => {
|
||||||
var re = new RegExp(op, 'gi');
|
var re = new RegExp(op, 'gi');
|
||||||
|
@ -1193,6 +1195,23 @@ export class SystemKeywords {
|
||||||
|
|
||||||
header = results.text[0];
|
header = results.text[0];
|
||||||
rows = results.text;
|
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 {
|
} else {
|
||||||
const t = this.getTableFromName(file, min);
|
const t = this.getTableFromName(file, min);
|
||||||
|
|
||||||
|
@ -1765,7 +1784,7 @@ export class SystemKeywords {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getCustomToken({ pid, tokenName }) {
|
public async getCustomToken({ pid, tokenName }) {
|
||||||
const { min } = await DialogKeywords.getProcessInfo(pid);
|
const { min } = await DialogKeywords.getProcessInfo(pid);
|
||||||
|
@ -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 { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
|
|
||||||
const consumer_key = min.core.getParam(min.instance, 'Twitter Consumer Key', null);
|
const consumer_key = min.core.getParam(min.instance, 'BlueSky Consumer Key', null);
|
||||||
const consumer_secret = min.core.getParam(min.instance, 'Twitter Consumer Key Secret', null);
|
const consumer_secret = min.core.getParam(min.instance, 'BlueSky Consumer Key Secret', null);
|
||||||
const access_token_key = min.core.getParam(min.instance, 'Twitter Access Token', null);
|
const access_token_key = min.core.getParam(min.instance, 'BlueSky Access Token', null);
|
||||||
const access_token_secret = min.core.getParam(min.instance, 'Twitter Access Token Secret', 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) {
|
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({
|
GBLogEx.info(min, `BlueSky Automation: ${text}.`);
|
||||||
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}.`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -424,10 +424,12 @@ export class GBMinService {
|
||||||
|
|
||||||
GBServer.globals.server
|
GBServer.globals.server
|
||||||
.all(`/${min.instance.botId}/whatsapp`, async (req, res) => {
|
.all(`/${min.instance.botId}/whatsapp`, async (req, res) => {
|
||||||
|
|
||||||
if (req.query['hub.mode'] === 'subscribe') {
|
if (req.query['hub.mode'] === 'subscribe') {
|
||||||
const val = req.query['hub.verify_token'];
|
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.send(req.query['hub.challenge']);
|
||||||
res.status(200);
|
res.status(200);
|
||||||
GBLogEx.info(min, `Meta callback OK. ${JSON.stringify(req.query)}`);
|
GBLogEx.info(min, `Meta callback OK. ${JSON.stringify(req.query)}`);
|
||||||
|
|
|
@ -621,7 +621,16 @@ export class ChatServices {
|
||||||
|
|
||||||
private static getToolsAsText(tools) {
|
private static getToolsAsText(tools) {
|
||||||
return Object.keys(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');
|
.join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
name,price
|
name,price
|
||||||
Product A, 230
|
fax, 500
|
||||||
Product B, 120
|
TV, 1200
|
||||||
Product C, 180
|
mobile,200
|
||||||
Product D, 250
|
console, 250
|
||||||
Product E, 200
|
|
||||||
Product F, 150
|
|
||||||
|
|
|
|
@ -1,6 +1,6 @@
|
||||||
PARAM product AS string LIKE "Product A"
|
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."
|
DESCRIPTION Returns the price of the given product.
|
||||||
|
|
||||||
product = FIND "products.csv", "name LIKE ${product}"
|
product = FIND "products.csv", "name = ${product}"
|
||||||
price = product.price
|
price = product.price
|
||||||
RETURN price
|
RETURN price
|
|
@ -4,6 +4,5 @@ There exist some helpful predefined internal tools which can help me by
|
||||||
extending my functionalities or get me helpful information.
|
extending my functionalities or get me helpful information.
|
||||||
These tools **should** be abstracted away from the user.
|
These tools **should** be abstracted away from the user.
|
||||||
These tools can be invoked only by me before I respond to a 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
|
END SYSTEM PROMPT
|
1
templates/whatsapp.gbai/whatsapp.gbot/config.csv
Normal file
1
templates/whatsapp.gbai/whatsapp.gbot/config.csv
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Meta Challenge,
|
|
Loading…
Add table
Reference in a new issue