new(gpt.gblib): PDF opener.
This commit is contained in:
parent
81237bd787
commit
4fa02a625b
6 changed files with 38 additions and 17 deletions
|
@ -339,7 +339,8 @@ export class GBConversationalService {
|
|||
}
|
||||
|
||||
public async sendEvent(min: GBMinInstance, step: GBDialogStep, name: string, value: Object): Promise<any> {
|
||||
if (!this.userMobile(step) && step.context.activity.channelId !== 'msteams') {
|
||||
if ( step.context.activity.channelId !== 'msteams' &&
|
||||
step.context.activity.channelId !== 'omnichannel') {
|
||||
GBLog.info(
|
||||
`Sending event ${name}:${typeof value === 'object' ? JSON.stringify(value) : value ? value : ''} to client...`
|
||||
);
|
||||
|
|
|
@ -891,6 +891,10 @@ export class GBDeployer implements IGBDeployer {
|
|||
`/kb/${gbaiName}/${packageName}/images`,
|
||||
express.static(urlJoin('work', gbaiName, filename, 'images'))
|
||||
);
|
||||
GBServer.globals.server.use(
|
||||
`/kb/${gbaiName}/${packageName}/docs`,
|
||||
express.static(urlJoin('work', gbaiName, filename, 'docs'))
|
||||
);
|
||||
GBServer.globals.server.use(
|
||||
`/kb/${gbaiName}/${packageName}/audios`,
|
||||
express.static(urlJoin('work', gbaiName, filename, 'audios'))
|
||||
|
|
|
@ -717,9 +717,9 @@ export class GBMinService {
|
|||
'Ocp-Apim-Subscription-Key': instance.speechKey
|
||||
}
|
||||
};
|
||||
|
||||
const url = urlJoin(instance.speechEndpoint, '/sts/v1.0/issueToken');
|
||||
try {
|
||||
const res = await fetch(instance.speechEndpoint, options);
|
||||
const res = await fetch(url, options);
|
||||
return res.text();
|
||||
} catch (error) {
|
||||
const msg = `Error calling Speech to Text client. Error is: ${error}.`;
|
||||
|
|
|
@ -64,7 +64,7 @@ import { GBLogEx } from '../../core.gbapp/services/GBLogEx.js';
|
|||
|
||||
|
||||
export interface CustomOutputParserFields { }
|
||||
export type ExpectedOutput = string;
|
||||
export type ExpectedOutput = any;
|
||||
|
||||
function isChatGeneration(
|
||||
llmOutput: ChatGeneration | Generation
|
||||
|
@ -94,7 +94,8 @@ class CustomHandler extends BaseCallbackHandler {
|
|||
|
||||
const logHandler = new CustomHandler();
|
||||
|
||||
export class GBLLMOutputParser extends BaseLLMOutputParser<ExpectedOutput> {
|
||||
export class GBLLMOutputParser extends
|
||||
BaseLLMOutputParser<ExpectedOutput> {
|
||||
lc_namespace = ["langchain", "output_parsers"];
|
||||
|
||||
private toolChain: RunnableSequence
|
||||
|
@ -148,7 +149,9 @@ export class GBLLMOutputParser extends BaseLLMOutputParser<ExpectedOutput> {
|
|||
const {url} = await ChatServices.pdfPageAsImage(this.min, metadata.file,
|
||||
metadata.page);
|
||||
result = `
|
||||
${result}`;
|
||||
${text}`;
|
||||
|
||||
return [ result, metadata.file, metadata.page];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -403,6 +406,7 @@ export class ChatServices {
|
|||
]);
|
||||
|
||||
let result;
|
||||
let text, file, page;
|
||||
|
||||
|
||||
// Choose the operation mode of answer generation, based on
|
||||
|
@ -418,7 +422,8 @@ export class ChatServices {
|
|||
}
|
||||
else if (LLMMode === "document") {
|
||||
|
||||
result = await combineDocumentsChain.invoke(question);
|
||||
[text, file, page] = await combineDocumentsChain.invoke(question);
|
||||
result = text;
|
||||
|
||||
} else if (LLMMode === "function") {
|
||||
|
||||
|
@ -435,18 +440,18 @@ export class ChatServices {
|
|||
GBLog.info(`Invalid Answer Mode in Config.xlsx: ${LLMMode}.`);
|
||||
}
|
||||
|
||||
const resultToPersist = result.replace(/\!\[.*\)/gi, ''); // Removes .MD url.
|
||||
|
||||
await memory.saveContext(
|
||||
{
|
||||
input: question,
|
||||
},
|
||||
{
|
||||
output: resultToPersist
|
||||
output: result.replace(/\!\[.*\)/gi, '') // Removes .MD url beforing adding to history.
|
||||
}
|
||||
);
|
||||
|
||||
GBLog.info(`GPT Result: ${result.toString()}`);
|
||||
return { answer: result.toString(), questionId: 0 };
|
||||
return { answer: result.toString(), file, questionId: 0, page };
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -37,20 +37,18 @@
|
|||
import { GBServer } from '../../../src/app.js';
|
||||
import { BotAdapter } from 'botbuilder';
|
||||
import { WaterfallDialog } from 'botbuilder-dialogs';
|
||||
import { ChatGPTAPIBrowser } from 'chatgpt';
|
||||
import { GBLog, GBMinInstance, IGBDialog, IGBPackage } from 'botlib';
|
||||
import { Messages } from '../strings.js';
|
||||
import { KBService } from './../services/KBService.js';
|
||||
import { GuaribasAnswer } from '../models/index.js';
|
||||
import { SecService } from '../../security.gbapp/services/SecService.js';
|
||||
import { CollectionUtil, AzureText } from 'pragmatismo-io-framework';
|
||||
import { CollectionUtil } from 'pragmatismo-io-framework';
|
||||
import { GBVMService } from '../../basic.gblib/services/GBVMService.js';
|
||||
import { GBImporter } from '../../core.gbapp/services/GBImporterService.js';
|
||||
import { GBDeployer } from '../../core.gbapp/services/GBDeployer.js';
|
||||
import { GBConfigService } from '../../core.gbapp/services/GBConfigService.js';
|
||||
import Fs from 'fs';
|
||||
import urlJoin from 'url-join';
|
||||
import { SystemKeywords } from '../../basic.gblib/services/SystemKeywords.js';
|
||||
import { DialogKeywords } from '../../basic.gblib/services/DialogKeywords.js';
|
||||
|
||||
/**
|
||||
* Dialog arguments.
|
||||
|
@ -235,19 +233,32 @@ export class AskDialog extends IGBDialog {
|
|||
return;
|
||||
}
|
||||
|
||||
const results = await service.ask(min, user, step, step.context.activity['pid'], text, searchScore, null /* user.subjects */);
|
||||
const results:any = await service.ask(min, user, step, step.context.activity['pid'], text, searchScore, null /* user.subjects */);
|
||||
|
||||
// If there is some result, answer immediately.
|
||||
|
||||
if (results !== undefined && results.answer !== undefined) {
|
||||
|
||||
if (results.file){
|
||||
const path = DialogKeywords.getGBAIPath(min.botId, `gbkb`);
|
||||
const url = urlJoin('kb', path, 'docs', results.file);
|
||||
|
||||
await min.conversationalService.sendEvent(
|
||||
min, step, 'play', {
|
||||
playerType: 'url',
|
||||
data: `${url}#page=${results.page}&toolbar=0&messages=0&statusbar=0&navpanes=0`
|
||||
});
|
||||
}
|
||||
|
||||
// Sends the answer to all outputs, including projector.
|
||||
|
||||
answer = results.answer;
|
||||
answer = results.answer.trim();
|
||||
|
||||
return await AskDialog.handleAnswer(service, min, step, user, answer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
GBLog.info(`SEARCH called but NO answer could be found (zero results).`);
|
||||
|
||||
// Not found.
|
||||
|
|
|
@ -653,7 +653,7 @@ export class KBService implements IGBKBService {
|
|||
} else {
|
||||
|
||||
await min.conversationalService.sendText(min, step, answer);
|
||||
await min.conversationalService.sendEvent(min, step, 'stop', undefined);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue