fix(llm.gblib): Tool fix.

This commit is contained in:
Rodrigo Rodriguez 2024-09-04 15:23:56 -03:00
parent 63efa588a8
commit a7887fad93
4 changed files with 53 additions and 41 deletions

View file

@ -2718,14 +2718,25 @@ export class SystemKeywords {
const { min } = await DialogKeywords.getProcessInfo(pid); const { min } = await DialogKeywords.getProcessInfo(pid);
GBLogEx.info(min, `BASIC GET (pdf): ${file}`); GBLogEx.info(min, `BASIC GET (pdf): ${file}`);
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min); let data ;
const gbaiName = DialogKeywords.getGBAIPath(min.botId);
let path = '/' + urlJoin(gbaiName, `${min.botId}.gbdrive`); if (GBConfigService.get('STORAGE_NAME')) {
let template = await this.internalGetDocument(client, baseUrl, path, file); let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
let url = template['@microsoft.graph.downloadUrl']; const gbaiName = DialogKeywords.getGBAIPath(min.botId);
const res = await fetch(url); let path = '/' + urlJoin(gbaiName, `${min.botId}.gbdrive`);
let buf: any = Buffer.from(await res.arrayBuffer()); let template = await this.internalGetDocument(client, baseUrl, path, file);
const data = new Uint8Array(buf); let url = template['@microsoft.graph.downloadUrl'];
const res = await fetch(url);
let buf: any = Buffer.from(await res.arrayBuffer());
data = new Uint8Array(buf);
}
else {
let path = DialogKeywords.getGBAIPath(min.botId, `gbdrive`);
let filePath = Path.join(GBConfigService.get('STORAGE_LIBRARY'), path, file);
data = Fs.readFileSync(filePath, 'utf8');
data = new Uint8Array(Buffer.from(data, 'utf8'));
}
const pdf = await getDocument({ data }).promise; const pdf = await getDocument({ data }).promise;
let pages = []; let pages = [];

View file

@ -931,6 +931,10 @@ export class GBDeployer implements IGBDeployer {
express.static(urlJoin('work', gbaiName, filename, 'videos')) express.static(urlJoin('work', gbaiName, filename, 'videos'))
); );
GBServer.globals.server.use(`/${botId}/cache`, express.static(urlJoin('work', gbaiName, 'cache'))); GBServer.globals.server.use(`/${botId}/cache`, express.static(urlJoin('work', gbaiName, 'cache')));
// FEAT-A7B1F6
GBServer.globals.server.use( GBServer.globals.server.use(
`/${gbaiName}/${botId}.gbdrive/public`, `/${gbaiName}/${botId}.gbdrive/public`,
express.static(urlJoin('work', gbaiName, `${botId}.gbdata`, 'public')) express.static(urlJoin('work', gbaiName, `${botId}.gbdata`, 'public'))

View file

@ -147,7 +147,7 @@ export class GBMinService {
/** /**
* Constructs a new minimal instance for each bot. * Constructs a new minimal instance for each bot.
*/ */
public async buildMin(instances: IGBInstance[]) : Promise<GBMinInstance[]> { public async buildMin(instances: IGBInstance[]): Promise<GBMinInstance[]> {
// Servers default UI on root address '/' if web enabled. // Servers default UI on root address '/' if web enabled.
if (process.env.DISABLE_WEB !== 'true') { if (process.env.DISABLE_WEB !== 'true') {
@ -171,7 +171,6 @@ export class GBMinService {
await CollectionUtil.asyncForEach( await CollectionUtil.asyncForEach(
instances, instances,
(async instance => { (async instance => {
try { try {
GBLog.info(`Mounting ${instance.botId}...`); GBLog.info(`Mounting ${instance.botId}...`);
const min = await this['mountBot'](instance); const min = await this['mountBot'](instance);
@ -180,7 +179,6 @@ export class GBMinService {
GBLog.error(`Error mounting bot ${instance.botId}: ${error.message}\n${error.stack}`); GBLog.error(`Error mounting bot ${instance.botId}: ${error.message}\n${error.stack}`);
} }
}).bind(this) }).bind(this)
); );
// Loads schedules. // Loads schedules.
@ -194,7 +192,7 @@ export class GBMinService {
return minInstances; return minInstances;
} }
public async startSimpleTest(min) { public async startSimpleTest(min) {
if (process.env.TEST_MESSAGE && min['isDefault']) { if (process.env.TEST_MESSAGE && min['isDefault']) {
GBLogEx.info(min, `Starting auto test with '${process.env.TEST_MESSAGE}'.`); GBLogEx.info(min, `Starting auto test with '${process.env.TEST_MESSAGE}'.`);
@ -206,7 +204,7 @@ export class GBMinService {
const steps = process.env.TEST_MESSAGE.split(';'); const steps = process.env.TEST_MESSAGE.split(';');
await CollectionUtil.asyncForEach(steps, async (step) => { await CollectionUtil.asyncForEach(steps, async step => {
client.apis.Conversations.Conversations_PostActivity({ client.apis.Conversations.Conversations_PostActivity({
conversationId: conversationId, conversationId: conversationId,
activity: { activity: {
@ -271,8 +269,6 @@ export class GBMinService {
* installing all BASIC artifacts from .gbdialog and OAuth2. * installing all BASIC artifacts from .gbdialog and OAuth2.
*/ */
public async mountBot(instance: IGBInstance) { public async mountBot(instance: IGBInstance) {
// Build bot adapter. // Build bot adapter.
const { min, adapter, conversationState } = await this.buildBotAdapter( const { min, adapter, conversationState } = await this.buildBotAdapter(
@ -284,12 +280,11 @@ export class GBMinService {
// https://github.com/GeneralBots/BotServer/issues/286 // https://github.com/GeneralBots/BotServer/issues/286
// min['groupCache'] = await KBService.getGroupReplies(instance.instanceId); // min['groupCache'] = await KBService.getGroupReplies(instance.instanceId);
min['isDefault'] = GBServer.globals.minInstances.length === 0; min['isDefault'] = GBServer.globals.minInstances.length === 0;
GBServer.globals.minInstances.push(min); GBServer.globals.minInstances.push(min);
const user = null; // No user context. const user = null; // No user context.
await GBVMService.loadConnections(min); await GBVMService.loadConnections(min);
// Serves individual URL for each bot conversational interface. // Serves individual URL for each bot conversational interface.
@ -359,9 +354,20 @@ export class GBMinService {
await this.invokeLoadBot(min.appPackages, GBServer.globals.sysPackages, min); await this.invokeLoadBot(min.appPackages, GBServer.globals.sysPackages, min);
const receiver = async (req, res) => { const receiver = async (req, res) => {
await this.receiver(req, res, conversationState, min, instance, GBServer.globals.appPackages); let path = /(http[s]?:\/\/)?([^\/\s]+\/)(.*)/gi;
const botId = req.url.substr(req.url.lastIndexOf('/') +1);
const min = GBServer.globals.minInstances.filter(p => p.instance.botId == botId)[0];
await this.receiver(req, res, conversationState, min, GBServer.globals.appPackages);
}; };
let url = `/api/messages/${instance.botId}`; let url = `/api/messages/${instance.botId}`;
GBServer.globals.server.post(url, receiver);
if (min['default']) {
url = `/api/messages`;
GBServer.globals.server.post(url, receiver);
}
GBServer.globals.server.get(url, (req, res) => { GBServer.globals.server.get(url, (req, res) => {
if (req.query['hub.mode'] === 'subscribe') { if (req.query['hub.mode'] === 'subscribe') {
@ -378,17 +384,17 @@ export class GBMinService {
GBLog.verbose(`GeneralBots(${instance.engineName}) listening on: ${url}.`); GBLog.verbose(`GeneralBots(${instance.engineName}) listening on: ${url}.`);
// Generates MS Teams manifest. // Generates MS Teams manifest.
const manifest = `${instance.botId}-Teams.zip`; const manifest = `${instance.botId}-Teams.zip`;
const packageTeams = urlJoin(`work`, DialogKeywords.getGBAIPath(instance.botId), manifest); const packageTeams = urlJoin(`work`, DialogKeywords.getGBAIPath(instance.botId), manifest);
if (!Fs.existsSync(packageTeams)) { if (!Fs.existsSync(packageTeams)) {
GBLogEx.info(min, 'Generating MS Teams manifest....'); GBLogEx.info(min, 'Generating MS Teams manifest....');
const data = await this.deployer.getBotManifest(instance); const data = await this.deployer.getBotManifest(instance);
Fs.writeFileSync(packageTeams, data); Fs.writeFileSync(packageTeams, data);
} }
// Serves individual URL for each bot user interface. // Serves individual URL for each bot user interface.
if (process.env.DISABLE_WEB !== 'true') { if (process.env.DISABLE_WEB !== 'true') {
const uiUrl = `/${instance.botId}`; const uiUrl = `/${instance.botId}`;
@ -424,7 +430,6 @@ 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); const challenge = min.core.getParam<string>(min.instance, `Meta Challenge`, null);
@ -463,7 +468,6 @@ export class GBMinService {
await this.ensureAPI(); await this.ensureAPI();
return min; return min;
} }
public static getProviderName(req: any, res: any) { public static getProviderName(req: any, res: any) {
@ -835,15 +839,6 @@ export class GBMinService {
min['apiConversations'] = {}; min['apiConversations'] = {};
min.packages = sysPackages; min.packages = sysPackages;
const receiver = async (req, res) => {
await this.receiver(req, res, conversationState, min, instance, GBServer.globals.appPackages);
};
let url = `/api/messages/${instance.botId}`;
GBServer.globals.server.post(url, receiver);
url = `/api/messages`;
GBServer.globals.server.post(url, receiver);
// NLP Manager. // NLP Manager.
const manager = new NlpManager({ languages: ['pt'], forceNER: true }); const manager = new NlpManager({ languages: ['pt'], forceNER: true });
@ -931,6 +926,8 @@ export class GBMinService {
WhatsappDirectLine.botsByNumber[botNumber] = min.whatsAppDirectLine; WhatsappDirectLine.botsByNumber[botNumber] = min.whatsAppDirectLine;
} }
min['default'] = min === minBoot;
return { min, adapter, conversationState }; return { min, adapter, conversationState };
} }
@ -989,7 +986,6 @@ export class GBMinService {
res: any, res: any,
conversationState: ConversationState, conversationState: ConversationState,
min: GBMinInstance, min: GBMinInstance,
instance: any,
appPackages: any[] appPackages: any[]
) { ) {
// Uses standard or Facebook Adapter. // Uses standard or Facebook Adapter.
@ -1065,7 +1061,7 @@ export class GBMinService {
if (step.context.activity.channelId !== 'msteams') { if (step.context.activity.channelId !== 'msteams') {
const service = new KBService(min.core.sequelize); const service = new KBService(min.core.sequelize);
const data = await service.getFaqBySubjectArray(instance.instanceId, 'faq', undefined); const data = await service.getFaqBySubjectArray(min.instance.instanceId, 'faq', undefined);
await min.conversationalService.sendEvent(min, step, 'play', { await min.conversationalService.sendEvent(min, step, 'play', {
playerType: 'bullet', playerType: 'bullet',
data: data.slice(0, 10) data: data.slice(0, 10)

View file

@ -3,4 +3,5 @@ HEAR processo
text = GET "processo.pdf" text = GET "processo.pdf"
text = "Com base neste documento, responda as dúvidas da pessoa: \n\n" + text text = "Com base neste documento, responda as dúvidas da pessoa: \n\n" + text
SET CONTEXT text SET CONTEXT text
SET
TALK "Processo ${processo} carregado. Pode me perguntar qualquer coisa do processo ou me peça um resumo da forma que você precisar. " TALK "Processo ${processo} carregado. Pode me perguntar qualquer coisa do processo ou me peça um resumo da forma que você precisar. "