From 1b14662caf38b60f05098453fb157ab12e353eb3 Mon Sep 17 00:00:00 2001 From: Leifer Mendez Date: Tue, 2 Apr 2024 13:16:43 +0200 Subject: [PATCH 1/2] add: favicon --- public/favicon.ico | Bin 15086 -> 1150 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/public/favicon.ico b/public/favicon.ico index 2deafb7ba9477100832fca12b760676acd1cbb75..643e24a7014dd048314d8e21c950b12fe8e5541b 100644 GIT binary patch literal 1150 zcmb7E>q}Ds6u&`#fFwi^k3m=b6`^1H5J3<@K|~~e$-p9lB+Cy5^)2z4ZaVjN zbGvSH&Z%>n8rF2FCBB{Wk!G4DmD={}+;Oa9oX8xs@5K}Ikx==uGA z{%(D31I}&*bjAWGbk}%et;Ntcmq4l&p<0%U?H_x5Y#<=y2m}OfU!Mh4^=F`LiGZ;y z1}&~QGBKLkqsT-sb;m%heH7$!y;8S9uEWuYYGnj$1Ie)VW}u}zoh*$vvnw5zo(z~> zDX3MP#>j`kecZ9pAymmlu)mdnb!Jd3#rKBzsg#2=3E`QPKLJ&;3s_s-6mn4O3QZnN z&KSy{3AQ^PYHKvTLnLAGgmFDcVD3qV))ob|MGQF`4x7E4=X>Y8s8wac`bGjnM?4Ic ztC*VZfp2LT2J3ag5@`mfplLaWVUHfGYg1@pIvh%T9D4`%`!^_kk$|$ASTx9Q@^Kz_KVFvHhi`rv zD#I02N+sCZ{Em&UU-10NJ&cczK;Kk`g@qZcuB@Z6`7F9Tsc5n%!qrnlI~UxC0V#BZ zu`ZgUt&q>b6_}WGqWbkM(w;8|oxTXVwn$!gZJQWcHU}D04$VbO^G_w?W-ErulntZp zGAbI5Q5}syrt_k21r^dPwDu)Zjx3sY66uvhdUM*5_D)X!blCdSVRRmcOmPFhehT!^ z{*8DBQC=sZ=h3kBr3Lpbjo05wyJYJpecDcb;;qKo991m PuHR5yj(hO`;D7zUB8MPk literal 15086 zcmeI3PiPcZ9LL|1nuPi%L9C(@XXziPpqQ48$*CKmLa%x#s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Apr 2024 13:27:46 +0200 Subject: [PATCH 2/2] docs: improve --- src/pages/_app.jsx | 2 +- src/pages/en/tutorials/langchain.mdx | 55 ++++++++++++---------------- 2 files changed, 24 insertions(+), 33 deletions(-) diff --git a/src/pages/_app.jsx b/src/pages/_app.jsx index 9d0bae6..55b494f 100644 --- a/src/pages/_app.jsx +++ b/src/pages/_app.jsx @@ -27,7 +27,7 @@ export default function App({ Component, pageProps }) { ) : ( {`${pageProps?.title || 'Documentation'} - BuilderBot.app Chatbot for Whatsapp, Telegram and more`} )} - + diff --git a/src/pages/en/tutorials/langchain.mdx b/src/pages/en/tutorials/langchain.mdx index 83097f2..83705ae 100644 --- a/src/pages/en/tutorials/langchain.mdx +++ b/src/pages/en/tutorials/langchain.mdx @@ -3,7 +3,7 @@ import { Resources } from '@/components/Resources' import { Warning } from "@/components/mdx" import { Guides } from '@/components/Guides' -# Welcome to Builderbot x Langchain +# Langchain When we want something more personality and intelligence in our assistants, the first thing we think about is Openai, what if I tell you that there is a simple way to get the most out of your LLM? @@ -11,81 +11,73 @@ When we want something more personality and intelligence in our assistants, the --- -## Firts steps +## Install let's look at a simple but very valuable trick. to be able to know the user's intention, we have tried it before with DialogFlow but what a headache, let's go for something easier - -first of all you need to install these libs - ```bash pnpm i @langchain/openai @langchain/core zod ``` - -```ts {{title:'./ai/catch-intention.ts'}} +```ts {{title:'ai/catch-intention.ts'}} import { z } from "zod"; -import { ChatOpenAI } from "@langchain/openai"; +import { ChatOpenAI, ChatPromptTemplate } from "@langchain/openai"; -export const openAiGP4Model = new ChatOpenAI({ +export const openAI = new ChatOpenAI({ modelName: 'gpt-4', openAIApiKey: 'YOUR_API_KEY_HERE', -}) +}); const SYSTEM_STRUCT = `just only history based: {history} -Answer the users question as best as possible.` - +Answer the users question as best as possible.`; export const PROMPT_STRUCT = ChatPromptTemplate.fromMessages([ ["system", SYSTEM_STRUCT], ["human", "{question}"] ]); +const catchIntention = z.object( + { + intention: z.enum(['UNKNOWN', 'SALES', 'GREETING', 'CLOSURE']) + .describe('Categorize the following conversation and decide what the intention is') + } +).describe('Given the following products, you should structure it in the best way, do not alter or edit anything'); - -const catchIntention = z.object({ - intention: z.enum(['UNKNOWN', 'SALES', 'GREETING', 'CLOSURE']) - .describe('Categorize the following conversation and decide what the intention is') -}) -.describe('Given the following products, you should structure it in the best way, do not alter or edit anything') - -const llmWithToolsCatchIntention = openAiGP4Model.withStructuredOutput(catchIntention, { +const llmWithToolsCatchIntention = openAI.withStructuredOutput(catchIntention, { name: "CatchIntention", }); -export const getIntention = (text: string): Promise => { +export const getIntention = async (text: string): Promise => { try { const { intention } = await PROMPT_STRUCT.pipe(llmWithToolsCatchIntention).invoke({ question: text, history: await history.getHistory(state) - }) - - return String(intention).toLocaleLowerCase() + }); + + return Promise.resolve(String(intention).toLocaleLowerCase()); } catch (errorIntention) { - return 'unknown' + return Promise.resolve('unknown'); } -} - - +}; ``` ```ts {{title:'app.ts'}} -import { createBot, MemoryDB, createProvider } from '@builderbot/bot' +import { createBot, MemoryDB, createProvider, createFlow } from '@builderbot/bot' import { MetaProvider } from '@builderbot/provider-meta' import { getIntention } from './ai/catch-intention' const PORT = process.env.PORT ?? 3001 const welcome = addKeyword(EVENTS.WELCOME) - .addAction(async (ctx, { gotoflow }) => { + .addAction(async (ctx, { gotoFlow }) => { const intention = getIntention(ctx.body) if (intention === 'greeting') { return gotoFlow(anyFlowThatYouDecide) - }else if (intention === 'sales') { + } else if (intention === 'sales') { /* sales flow */ /* any flow */ } @@ -110,7 +102,6 @@ const main = async () => { } main() - ```