fix (templates): llm-server OK.
This commit is contained in:
parent
d78fc1bbbb
commit
210ad2f885
9 changed files with 73 additions and 72 deletions
|
@ -1366,17 +1366,17 @@ export class DialogKeywords {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async start({ botId, botApiKey, userSystemId, text }) {
|
public async start({ botId, botApiKey, userSystemId, text }) {
|
||||||
|
|
||||||
let min: GBMinInstance = GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0];
|
let min: GBMinInstance = GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0];
|
||||||
let sec = new SecService();
|
let sec = new SecService();
|
||||||
let user = await sec.getUserFromSystemId(userSystemId);
|
let user = await sec.getUserFromSystemId(userSystemId);
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
user = await sec.ensureUser(min, userSystemId, userSystemId, null, 'api', 'API User', null);
|
user = await sec.ensureUser(min, userSystemId, userSystemId, null, 'api', 'API User', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
const pid = GBVMService.createProcessInfo(user, min, 'api', null);
|
const pid = GBVMService.createProcessInfo(user, min, 'api', null);
|
||||||
|
|
||||||
const conversation = min['apiConversations'][pid];
|
const conversation = min['apiConversations'][pid];
|
||||||
|
|
||||||
const client = await GBUtil.getDirectLineClient(min);
|
const client = await GBUtil.getDirectLineClient(min);
|
||||||
conversation.client = client;
|
conversation.client = client;
|
||||||
const response = await client.apis.Conversations.Conversations_StartConversation();
|
const response = await client.apis.Conversations.Conversations_StartConversation();
|
||||||
|
|
|
@ -217,7 +217,7 @@ export class GBVMService extends GBService {
|
||||||
}`;
|
}`;
|
||||||
await fs.writeFile(urlJoin(folder, 'package.json'), packageJson);
|
await fs.writeFile(urlJoin(folder, 'package.json'), packageJson);
|
||||||
|
|
||||||
GBLogEx.info(min, `Installing .gbdialog node_modules for ${min.botId}...`);
|
GBLogEx.info(min, `Installing node_modules...`);
|
||||||
const npmPath = urlJoin(process.env.PWD, 'node_modules', '.bin', 'npm');
|
const npmPath = urlJoin(process.env.PWD, 'node_modules', '.bin', 'npm');
|
||||||
child_process.exec(`${npmPath} install`, { cwd: folder });
|
child_process.exec(`${npmPath} install`, { cwd: folder });
|
||||||
}
|
}
|
||||||
|
@ -280,7 +280,7 @@ export class GBVMService extends GBService {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!min[connectionName]) {
|
if (!min[connectionName]) {
|
||||||
GBLogEx.info(min, `Loading custom connection ${connectionName}...`);
|
GBLogEx.info(min, `Loading data connection ${connectionName}...`);
|
||||||
min[connectionName] = new Sequelize(storageName, username, password, sequelizeOptions);
|
min[connectionName] = new Sequelize(storageName, username, password, sequelizeOptions);
|
||||||
min[connectionName]['gbconnection'] = con;
|
min[connectionName]['gbconnection'] = con;
|
||||||
}
|
}
|
||||||
|
@ -712,7 +712,7 @@ await fs.writeFile(mapFile, JSON.stringify(map));
|
||||||
code = ji.default(code, ' ');
|
code = ji.default(code, ' ');
|
||||||
|
|
||||||
await fs.writeFile(jsfile, code);
|
await fs.writeFile(jsfile, code);
|
||||||
GBLogEx.info(min, `[GBVMService] Finished loading of ${filename}, JavaScript from Word: \n ${code}`);
|
GBLogEx.info(min, `Code reloaded: ${path.basename(filename)}.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async executeTasks(min, tasks) {
|
private async executeTasks(min, tasks) {
|
||||||
|
|
|
@ -59,6 +59,7 @@ import { GBLogEx } from './GBLogEx.js';
|
||||||
import { GBUtil } from '../../../src/util.js';
|
import { GBUtil } from '../../../src/util.js';
|
||||||
import { HNSWLib } from '@langchain/community/vectorstores/hnswlib';
|
import { HNSWLib } from '@langchain/community/vectorstores/hnswlib';
|
||||||
import { OpenAIEmbeddings } from '@langchain/openai';
|
import { OpenAIEmbeddings } from '@langchain/openai';
|
||||||
|
import { GBMinService } from './GBMinService.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deployer service for bots, themes, ai and more.
|
* Deployer service for bots, themes, ai and more.
|
||||||
|
@ -688,6 +689,7 @@ export class GBDeployer implements IGBDeployer {
|
||||||
await this.core.saveInstance(min.instance);
|
await this.core.saveInstance(min.instance);
|
||||||
GBServer.globals.minService.unmountBot(min.botId);
|
GBServer.globals.minService.unmountBot(min.botId);
|
||||||
GBServer.globals.minService.mountBot(min.instance);
|
GBServer.globals.minService.mountBot(min.instance);
|
||||||
|
|
||||||
GBLogEx.info(min, `Bot ${min.botId} reloaded.`);
|
GBLogEx.info(min, `Bot ${min.botId} reloaded.`);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -40,48 +40,48 @@ import { GBServer } from '../../../src/app.js';
|
||||||
import { GBConfigService } from './GBConfigService.js';
|
import { GBConfigService } from './GBConfigService.js';
|
||||||
|
|
||||||
export class GBLogEx {
|
export class GBLogEx {
|
||||||
public static async error(minOrInstanceId: any, message: string) {
|
private static async logWithLevel(
|
||||||
|
level: 'error' | 'debug' | 'info' | 'verbose',
|
||||||
|
minOrInstanceId: any,
|
||||||
|
message: string
|
||||||
|
) {
|
||||||
|
const instanceId = this.normalizeInstanceId(minOrInstanceId);
|
||||||
|
GBLog[level](`${instanceId}: ${message}`);
|
||||||
|
await this.log(instanceId, level.charAt(0), message);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static normalizeInstanceId(minOrInstanceId: any): string | number {
|
||||||
if (typeof minOrInstanceId === 'object') {
|
if (typeof minOrInstanceId === 'object') {
|
||||||
minOrInstanceId = minOrInstanceId.instance.instanceId;
|
return minOrInstanceId.instance ? minOrInstanceId.instance.botId : minOrInstanceId.botId;
|
||||||
}
|
}
|
||||||
GBLog.error(`${minOrInstanceId}: ${message}`);
|
return minOrInstanceId === 0 ? 'default' : minOrInstanceId;
|
||||||
await this.log(minOrInstanceId, 'e', message);
|
}
|
||||||
|
|
||||||
|
public static async error(minOrInstanceId: any, message: string) {
|
||||||
|
await this.logWithLevel('error', minOrInstanceId, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async debug(minOrInstanceId: any, message: string) {
|
public static async debug(minOrInstanceId: any, message: string) {
|
||||||
if (typeof minOrInstanceId === 'object') {
|
await this.logWithLevel('debug', minOrInstanceId, message);
|
||||||
minOrInstanceId = minOrInstanceId.instance.instanceId;
|
|
||||||
}
|
|
||||||
GBLog.debug(`${minOrInstanceId}: ${message}`);
|
|
||||||
await this.log(minOrInstanceId, 'd', message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async info(minOrInstanceId: any, message: string) {
|
public static async info(minOrInstanceId: any, message: string) {
|
||||||
|
await this.logWithLevel('info', minOrInstanceId, message);
|
||||||
if (typeof minOrInstanceId === 'object') {
|
|
||||||
minOrInstanceId = minOrInstanceId.instance.instanceId;
|
|
||||||
}
|
|
||||||
GBLog.info(`${minOrInstanceId}: ${message}`);
|
|
||||||
await this.log(minOrInstanceId, 'i', message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async verbose(minOrInstanceId: any, message: string) {
|
public static async verbose(minOrInstanceId: any, message: string) {
|
||||||
if (typeof minOrInstanceId === 'object') {
|
await this.logWithLevel('verbose', minOrInstanceId, message);
|
||||||
minOrInstanceId = minOrInstanceId.instance.instanceId;
|
|
||||||
}
|
|
||||||
GBLog.verbose(`${minOrInstanceId}: ${message}`);
|
|
||||||
await this.log(minOrInstanceId, 'v', message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds and update user agent information to a next available person.
|
* Finds and update user agent information to a next available person.
|
||||||
*/
|
*/
|
||||||
public static async log(instance: IGBInstance, kind: string, message: string): Promise<GuaribasLog> {
|
public static async log(instance, kind: string, message: string): Promise<GuaribasLog> {
|
||||||
if (GBConfigService.get('LOG_ON_STORAGE')) {
|
if (GBConfigService.get('LOG_ON_STORAGE')) {
|
||||||
message = message ? message.substring(0, 1023) : null;
|
message = message ? message.substring(0, 1023) : null;
|
||||||
|
|
||||||
return await GuaribasLog.create(<GuaribasLog>{
|
return await GuaribasLog.create(<GuaribasLog>{
|
||||||
instanceId: instance ? instance.instanceId : GBServer.globals,
|
instanceId: instance ? instance : 0,
|
||||||
message: message,
|
message: message,
|
||||||
kind: kind
|
kind: kind
|
||||||
});
|
});
|
||||||
|
|
|
@ -181,11 +181,11 @@ export class GBMinService {
|
||||||
instances,
|
instances,
|
||||||
(async instance => {
|
(async instance => {
|
||||||
try {
|
try {
|
||||||
GBLog.info(`Mounting ${instance.botId}...`);
|
GBLogEx.info(instance, `Mounting...`);
|
||||||
const min = await this['mountBot'](instance);
|
const min = await this['mountBot'](instance);
|
||||||
minInstances.push(min);
|
minInstances.push(min);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
GBLog.error(`Error mounting bot ${instance.botId}: ${error.message}\n${error.stack}`);
|
GBLogEx.error(instance, `Error mounting bot: ${error.message}\n${error.stack}`);
|
||||||
}
|
}
|
||||||
}).bind(this)
|
}).bind(this)
|
||||||
);
|
);
|
||||||
|
@ -400,6 +400,7 @@ export class GBMinService {
|
||||||
res.end();
|
res.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await GBMinService.ensureAPI(min);
|
||||||
GBLog.verbose(`GeneralBots(${instance.engineName}) listening on: ${url}.`);
|
GBLog.verbose(`GeneralBots(${instance.engineName}) listening on: ${url}.`);
|
||||||
|
|
||||||
// Generates MS Teams manifest.
|
// Generates MS Teams manifest.
|
||||||
|
@ -480,10 +481,6 @@ export class GBMinService {
|
||||||
|
|
||||||
GBDeployer.mountGBKBAssets(`${botId}.gbkb`, botId, `${botId}.gbkb`);
|
GBDeployer.mountGBKBAssets(`${botId}.gbkb`, botId, `${botId}.gbkb`);
|
||||||
|
|
||||||
// Loads API.
|
|
||||||
|
|
||||||
await this.ensureAPI();
|
|
||||||
|
|
||||||
return min;
|
return min;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1651,8 +1648,14 @@ export class GBMinService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async ensureAPI() {
|
public static async ensureAPI(min: GBMinInstance) {
|
||||||
const mins = GBServer.globals.minInstances;
|
const api = min.core.getParam(min.instance, 'Server API', null);
|
||||||
|
if (!api) {
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GBLogEx.info(min, `Enabling API...`);
|
||||||
|
|
||||||
function getRemoteId(ctx: Koa.Context) {
|
function getRemoteId(ctx: Koa.Context) {
|
||||||
return '1'; // Each bot has its own API.
|
return '1'; // Each bot has its own API.
|
||||||
|
@ -1666,7 +1669,7 @@ export class GBMinService {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
resolve(true);
|
resolve(true);
|
||||||
GBLogEx.info(0, 'Loading General Bots API...');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -1674,10 +1677,15 @@ export class GBMinService {
|
||||||
await close();
|
await close();
|
||||||
|
|
||||||
let proxies = {};
|
let proxies = {};
|
||||||
await CollectionUtil.asyncForEach(mins, async min => {
|
let dialogs = {};
|
||||||
let dialogs = {};
|
await CollectionUtil.asyncForEach(Object.values(min.scriptMap), async script => {
|
||||||
await CollectionUtil.asyncForEach(Object.values(min.scriptMap), async script => {
|
dialogs[script] = async data => {
|
||||||
dialogs[script] = async data => {
|
|
||||||
|
if (!data.userSystemId){
|
||||||
|
throw new Error('UserSystemId is required.');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
let sec = new SecService();
|
let sec = new SecService();
|
||||||
const user = await sec.ensureUser(
|
const user = await sec.ensureUser(
|
||||||
min,
|
min,
|
||||||
|
@ -1706,8 +1714,8 @@ export class GBMinService {
|
||||||
ret = pid;
|
ret = pid;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
};
|
|
||||||
});
|
};
|
||||||
|
|
||||||
const proxy = {
|
const proxy = {
|
||||||
dk: new DialogKeywords(),
|
dk: new DialogKeywords(),
|
||||||
|
|
|
@ -62,6 +62,7 @@ export const getRouter = (
|
||||||
};
|
};
|
||||||
|
|
||||||
router.post('/v3/directline/conversations', reqs);
|
router.post('/v3/directline/conversations', reqs);
|
||||||
|
router.post(`/api/messages/${botId}/v3/directline/conversations`, reqs);
|
||||||
router.post(`/directline/${botId}/conversations`, reqs);
|
router.post(`/directline/${botId}/conversations`, reqs);
|
||||||
router.post(`/directline/conversations`, reqs);
|
router.post(`/directline/conversations`, reqs);
|
||||||
|
|
||||||
|
|
11
templates/llm-server.gbai/llm-server.gbdata/products.csv
Normal file
11
templates/llm-server.gbai/llm-server.gbdata/products.csv
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
Product ID,Product Name,Category,Price,Stock Quantity,Expiration Date,Supplier Name,Discount (%),Rating
|
||||||
|
101,Apple,Fruits,0.50,200,2024-09-20,Fresh Farms,5,4.5
|
||||||
|
102,Banana,Fruits,0.30,150,2024-09-15,Green Valley,10,4.7
|
||||||
|
103,Carrot,Vegetables,0.20,180,2024-10-10,Organic Harvest,0,4.3
|
||||||
|
104,Bread,Bakery,1.00,50,2024-09-12,BakeHouse,15,4.1
|
||||||
|
105,Milk,Dairy,1.50,80,2024-09-18,DairyPure,0,4.6
|
||||||
|
106,Chicken Breast,Meat,5.00,120,2024-09-25,Farm Fresh,5,4.8
|
||||||
|
107,Orange Juice,Beverages,2.00,60,2024-09-22,Fruit Press,10,4.4
|
||||||
|
108,Almonds,Snacks,4.00,40,2024-11-30,Nutty Harvest,0,4.7
|
||||||
|
109,Rice,Grains,2.50,300,2025-01-01,Whole Foods,0,4.2
|
||||||
|
110,Pasta,Grains,1.20,250,2025-02-15,GrainLand,0,4.0
|
|
|
@ -1,31 +1,7 @@
|
||||||
|
PARAM operator AS number LIKE 12312312 DESCRIPTION "Operator code."
|
||||||
|
DESCRIPTION It is a WebService of GB.
|
||||||
|
|
||||||
PARAM stall AS number LIKE Stall Code
|
products = FIND "products.csv"
|
||||||
PARAM operator AS number LIKE Operator Code
|
|
||||||
DESCRIPTION This function (tool) is never called by LLM. It is a WebService of GB.
|
|
||||||
|
|
||||||
REM Login as Waiter
|
|
||||||
data = NEW OBJECT
|
|
||||||
data.OperatorIdentifier = operator
|
|
||||||
data.StallId = stall
|
|
||||||
login = POST host + "/login", data
|
|
||||||
SET HEADER "Authorization" AS login.accessToken
|
|
||||||
|
|
||||||
REM Get the menu - Use the token retrieved above.
|
|
||||||
data = GET host + "/Stall/${stall}"
|
|
||||||
products = NEW ARRAY
|
|
||||||
|
|
||||||
FOR EACH item IN data[0].items
|
|
||||||
IF item.itemStatus = "Active" THEN
|
|
||||||
product = NEW OBJECT
|
|
||||||
product.id = item.id
|
|
||||||
product.price = item.price
|
|
||||||
product.name = item.product.name
|
|
||||||
product.detail = item.detail
|
|
||||||
product.sides = item.sideGroups
|
|
||||||
|
|
||||||
products.push(product)
|
|
||||||
END IF
|
|
||||||
NEXT
|
|
||||||
|
|
||||||
BEGIN SYSTEM PROMPT
|
BEGIN SYSTEM PROMPT
|
||||||
|
|
||||||
|
@ -68,7 +44,6 @@ Here is an example of the Order JSON, clear the items and send one with the orde
|
||||||
notes: none
|
notes: none
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
stallId: ${stall},
|
|
||||||
userId: ${operator},
|
userId: ${operator},
|
||||||
accountIdentifier: Areia,
|
accountIdentifier: Areia,
|
||||||
deliveryTypeId: 2,
|
deliveryTypeId: 2,
|
||||||
|
|
4
templates/llm-server.gbai/llm-server.gbot/config.csv
Normal file
4
templates/llm-server.gbai/llm-server.gbot/config.csv
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
name,value
|
||||||
|
Answer Mode,direct
|
||||||
|
Server API,true
|
||||||
|
Start Dialog,start
|
|
Loading…
Add table
Reference in a new issue