fix(llm.gblib): Talk to data local db use fix.
This commit is contained in:
parent
420543768b
commit
afc72c5d55
1 changed files with 22 additions and 13 deletions
|
@ -47,13 +47,12 @@ import { CSVLoader } from '@langchain/community/document_loaders/fs/csv';
|
||||||
import { DocxLoader } from '@langchain/community/document_loaders/fs/docx';
|
import { DocxLoader } from '@langchain/community/document_loaders/fs/docx';
|
||||||
import { EPubLoader } from '@langchain/community/document_loaders/fs/epub';
|
import { EPubLoader } from '@langchain/community/document_loaders/fs/epub';
|
||||||
import { PDFLoader } from '@langchain/community/document_loaders/fs/pdf';
|
import { PDFLoader } from '@langchain/community/document_loaders/fs/pdf';
|
||||||
import { rimraf } from 'rimraf';
|
import svg2img from 'svg2img';
|
||||||
|
|
||||||
import getColors from 'get-image-colors';
|
import getColors from 'get-image-colors';
|
||||||
import { Document } from 'langchain/document';
|
import { Document } from 'langchain/document';
|
||||||
import { RecursiveCharacterTextSplitter } from 'langchain/text_splitter';
|
import { RecursiveCharacterTextSplitter } from 'langchain/text_splitter';
|
||||||
import puppeteer, { Page } from 'puppeteer';
|
import puppeteer, { Page } from 'puppeteer';
|
||||||
import {Jimp} from 'jimp';
|
import { Jimp } from 'jimp';
|
||||||
import {
|
import {
|
||||||
GBDialogStep,
|
GBDialogStep,
|
||||||
GBLog,
|
GBLog,
|
||||||
|
@ -663,7 +662,7 @@ export class KBService implements IGBKBService {
|
||||||
if (removeMarkdownImages(answer)) {
|
if (removeMarkdownImages(answer)) {
|
||||||
await min.conversationalService.sendText(min, step, answer);
|
await min.conversationalService.sendText(min, step, answer);
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
const urlMatch = answer.match(/!?\[.*?\]\((.*?)\)/);
|
const urlMatch = answer.match(/!?\[.*?\]\((.*?)\)/);
|
||||||
const url = urlMatch ? urlMatch[1] : null;
|
const url = urlMatch ? urlMatch[1] : null;
|
||||||
await this.showImage(min, min.conversationalService, step, url, channel)
|
await this.showImage(min, min.conversationalService, step, url, channel)
|
||||||
|
@ -1067,14 +1066,24 @@ export class KBService implements IGBKBService {
|
||||||
|
|
||||||
const logoBinary = await page.goto(logo);
|
const logoBinary = await page.goto(logo);
|
||||||
let buffer = await logoBinary.buffer();
|
let buffer = await logoBinary.buffer();
|
||||||
const logoFilename = path.basename(logo);
|
let logoFilename = path.basename(logo);
|
||||||
|
|
||||||
// Replace sharp with jimp
|
// Replace sharp with jimp
|
||||||
if (buffer.toString().includes('<svg')) {
|
if (buffer.toString().includes('<svg')) {
|
||||||
|
|
||||||
|
logoFilename = logoFilename.replace('.svg', '.png');
|
||||||
|
|
||||||
// For SVG files, convert using svg2img
|
// For SVG files, convert using svg2img
|
||||||
const svg2img = require('svg2img');
|
|
||||||
buffer = await new Promise((resolve, reject) => {
|
buffer = await new Promise((resolve, reject) => {
|
||||||
svg2img(buffer, {width: 48, height: 48}, (error: any, buffer: Buffer) => {
|
svg2img(buffer, {
|
||||||
|
resvg: {
|
||||||
|
fitTo: {
|
||||||
|
mode: 'width', // or height
|
||||||
|
value: 48,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}, (error: any, buffer: Buffer) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1086,7 +1095,7 @@ export class KBService implements IGBKBService {
|
||||||
|
|
||||||
// Replace sharp with jimp
|
// Replace sharp with jimp
|
||||||
const image = await Jimp.read(buffer);
|
const image = await Jimp.read(buffer);
|
||||||
await image.scaleToFit({w:48, h:48});
|
await image.scaleToFit({ w: 48, h: 48 });
|
||||||
packagePath = path.join(process.env.PWD, 'work', packagePath);
|
packagePath = path.join(process.env.PWD, 'work', packagePath);
|
||||||
|
|
||||||
const logoPath = path.join(packagePath, 'cache', logoFilename);
|
const logoPath = path.join(packagePath, 'cache', logoFilename);
|
||||||
|
|
Loading…
Add table
Reference in a new issue