From 878f10245f321578759ac567da3491c5366915c3 Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Tue, 26 Nov 2024 09:35:15 -0300 Subject: [PATCH] fix(kb.gbapp): Auto Logo generation fixed. --- package.json | 2 +- packages/kb.gbapp/services/KBService.ts | 30 ++++++++----------- .../talk-to-data.gbdialog/start.bas | 15 ++++++++++ 3 files changed, 29 insertions(+), 18 deletions(-) create mode 100644 templates/talk-to-data.gbai/talk-to-data.gbdialog/start.bas diff --git a/package.json b/package.json index 5dd32375..5046f5ac 100644 --- a/package.json +++ b/package.json @@ -154,7 +154,7 @@ "instagram-private-api": "1.46.1", "iso-639-1": "3.1.3", "isomorphic-fetch": "3.0.0", - "jimp": "^1.6.0", + "jimp": "1.6.0", "js-md5": "0.8.3", "json-schema-to-zod": "2.4.0", "jsqr": "^1.4.0", diff --git a/packages/kb.gbapp/services/KBService.ts b/packages/kb.gbapp/services/KBService.ts index 8ed7b741..90fb91d8 100644 --- a/packages/kb.gbapp/services/KBService.ts +++ b/packages/kb.gbapp/services/KBService.ts @@ -53,7 +53,7 @@ import getColors from 'get-image-colors'; import { Document } from 'langchain/document'; import { RecursiveCharacterTextSplitter } from 'langchain/text_splitter'; import puppeteer, { Page } from 'puppeteer'; - +import {Jimp} from 'jimp'; import { GBDialogStep, GBLog, @@ -1065,22 +1065,18 @@ export class KBService implements IGBKBService { const baseUrl = page.url().split('/').slice(0, 3).join('/'); logo = logo.startsWith('https') ? logo : urlJoin(baseUrl, logo); - try { - const logoBinary = await page.goto(logo); - const buffer = await logoBinary.buffer(); - const logoFilename = path.basename(logo); - // TODO: sharp(buffer) - // .resize({ - // width: 48, - // height: 48, - // fit: 'inside', // Resize the image to fit within the specified dimensions - // withoutEnlargement: true // Don't enlarge the image if its dimensions are already smaller - // }) - // .toFile(path.join(logoPath, logoFilename)); - await min.core['setConfig'](min, 'Logo', logoFilename); - } catch (error) { - GBLogEx.debug(min, error); - } + const logoBinary = await page.goto(logo); + const buffer = await logoBinary.buffer(); + const logoFilename = path.basename(logo); + + // Replace sharp with jimp + const image = await Jimp.read(buffer); + await image.scaleToFit({w:48, h:48}); + packagePath = path.join(process.env.PWD, 'work', packagePath); + + const logoPath = path.join(packagePath, 'cache', logoFilename); + await (image as any).write(logoPath); + await min.core['setConfig'](min, 'Logo', logoFilename); } // Extract dominant colors from the screenshot diff --git a/templates/talk-to-data.gbai/talk-to-data.gbdialog/start.bas b/templates/talk-to-data.gbai/talk-to-data.gbdialog/start.bas new file mode 100644 index 00000000..73d43554 --- /dev/null +++ b/templates/talk-to-data.gbai/talk-to-data.gbdialog/start.bas @@ -0,0 +1,15 @@ +BEGIN TALK + + General Bots Talk To Data + + Examples: + - Show me top products in a rainbow collored pie chart. + - Sales across years. + + + Let’s get started! +END TALK + +BEGIN SYSTEM PROMPT + +END SYSTEM PROMPT \ No newline at end of file