new(core.gbapp): New API endpoint.
This commit is contained in:
parent
4342c6d3e5
commit
4ced6b667c
4 changed files with 30 additions and 5 deletions
|
@ -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",
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<string> {
|
||||
|
||||
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.
|
||||
`
|
||||
|
|
19
src/app.ts
19
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)
|
||||
|
|
Loading…
Add table
Reference in a new issue