From 4ced6b667cec9898c70923c9a0701d2d718de40f Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Wed, 17 Apr 2024 10:50:33 -0300 Subject: [PATCH] new(core.gbapp): New API endpoint. --- package.json | 1 + packages/core.gbapp/services/GBMinService.ts | 4 +++- packages/gpt.gblib/services/ChatServices.ts | 11 +++++++---- src/app.ts | 19 +++++++++++++++++++ 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 6d7973f0..f3f8149c 100644 --- a/package.json +++ b/package.json @@ -136,6 +136,7 @@ "google-libphonenumber": "3.2.31", "googleapis": "126.0.1", "hnswlib-node": "^1.4.2", + "http-proxy": "^1.18.1", "ibm-watson": "7.1.2", "iso-639-1": "3.1.1", "join-images-updated": "1.1.4", diff --git a/packages/core.gbapp/services/GBMinService.ts b/packages/core.gbapp/services/GBMinService.ts index 1b72f08a..5ebde45b 100644 --- a/packages/core.gbapp/services/GBMinService.ts +++ b/packages/core.gbapp/services/GBMinService.ts @@ -1677,7 +1677,9 @@ export class GBMinService { } }; - GBServer.globals.server.apiServer = createKoaHttpServer(GBVMService.API_PORT, getRemoteId, { prefix: `api/v3` }); + GBServer.globals.server.apiServer = createKoaHttpServer( + GBVMService.API_PORT, + getRemoteId, { prefix: `api/v3` }); createRpcServer( proxies, diff --git a/packages/gpt.gblib/services/ChatServices.ts b/packages/gpt.gblib/services/ChatServices.ts index 0e4088fd..fb810237 100644 --- a/packages/gpt.gblib/services/ChatServices.ts +++ b/packages/gpt.gblib/services/ChatServices.ts @@ -144,7 +144,7 @@ export class GBLLMOutputParser extends if (source) { const gbaiName = DialogKeywords.getGBAIPath(this.min.botId, 'gbkb'); - const localName = Path.join('work', gbaiName, 'docs', source.file); + const localName = Path.join(process.env.PWD,'work', gbaiName, 'docs', source.file); if (localName) { const { url } = await ChatServices.pdfPageAsImage(this.min, localName, source.page); @@ -196,7 +196,7 @@ export class ChatServices { private static async getRelevantContext( vectorStore: HNSWLib, sanitizedQuestion: string, - numDocuments: number = 10 + numDocuments: number = 100 ): Promise { if (sanitizedQuestion === '') { @@ -221,7 +221,8 @@ export class ChatServices { const page = await ChatServices.findPageForText(metadata.source, doc.pageContent); - output = `${output}\n\n\n\nThe following context is coming from ${filename} at page: ${page}, + output = `${output}\n\n\n\nUse also the following context which is coming from Source Document: ${filename} at page: ${page} + (you will fill the JSON sources collection field later), memorize this block among document information and return when you are refering this part of content:\n\n\n\n ${doc.pageContent} \n\n\n\n.`; } return output; @@ -346,7 +347,9 @@ export class ChatServices { Example JSON format: "text": "this is the answer, anything LLM output as text answer shoud be here.", "sources": [{{"file": "filename.pdf", "page": 3}}, {{"file": "filename2.pdf", "page": 1}}], return valid JSON with brackets. Avoid explaining the context directly - to the user; instead, refer to the document source. + to the user; instead, refer to the document source, always return more than one source document + and check if the answer can be extended by using additional contexts in + other files, as specified before. Double check if the output is a valid JSON with brackets. all fields are required: text, file, page. ` diff --git a/src/app.ts b/src/app.ts index d3982c65..008177ea 100644 --- a/src/app.ts +++ b/src/app.ts @@ -59,6 +59,7 @@ import * as winston from 'winston-logs-display'; import { RootData } from './RootData.js'; import { GBSSR } from '../packages/core.gbapp/services/GBSSR.js'; import { Mutex } from 'async-mutex'; +import {httpProxy} from 'http-proxy'; /** * General Bots open-core entry point. @@ -251,6 +252,15 @@ export class GBServer { } server.get('*', async (req, res, next) => { + + const host = req.headers.host; + + // Roteamento com base no domínio. + + if (host === process.env.API_HOST) { + return httpProxy.web(req, res, { target: 'http://localhost:1111' }); // Express server + } + if (req.originalUrl.startsWith('/logs')) { if (process.env.ENABLE_WEBLOG === "true") { const admins = { @@ -299,6 +309,15 @@ export class GBServer { } if (process.env.CERTIFICATE_PFX) { + + // var options = { + // changeOrigin: true, + // target: { + // https: true + // } + // } + // httpProxy.createServer(443, 'www.google.com', options).listen(8001); + const options1 = { passphrase: process.env.CERTIFICATE_PASSPHRASE, pfx: fs.readFileSync(process.env.CERTIFICATE_PFX)