From 6c24a259ae98b0cff372dd1d28fab50cadbe086a Mon Sep 17 00:00:00 2001 From: n4ze3m Date: Tue, 14 Nov 2023 23:34:40 +0530 Subject: [PATCH 01/14] Update version numbers in package.json --- app/ui/package.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/ui/package.json b/app/ui/package.json index ce65d8e1..5962ce98 100644 --- a/app/ui/package.json +++ b/app/ui/package.json @@ -1,7 +1,7 @@ { "name": "app", "private": true, - "version": "1.4.1", + "version": "1.4.2", "type": "module", "scripts": { "dev": "vite", diff --git a/package.json b/package.json index 03f495af..a0153be0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dialoqbase", - "version": "1.4.1", + "version": "1.4.2", "description": "Create chatbots with ease", "scripts": { "ui:dev": "pnpm run --filter ui dev", From 21056f2d4ee3d9ee2fcae811aad025806b1bb160 Mon Sep 17 00:00:00 2001 From: n4ze3m Date: Tue, 14 Nov 2023 23:34:45 +0530 Subject: [PATCH 02/14] Enable streaming in store --- app/ui/src/store/index.tsx | 2 +- app/widget/src/store/index.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/ui/src/store/index.tsx b/app/ui/src/store/index.tsx index 4daa58c0..e580aecb 100644 --- a/app/ui/src/store/index.tsx +++ b/app/ui/src/store/index.tsx @@ -61,7 +61,7 @@ export const useStoreMessage = create((set) => ({ setMessages: (messages) => set({ messages }), history: [], setHistory: (history) => set({ history }), - streaming: false, + streaming: true, setStreaming: (streaming) => set({ streaming }), isFirstMessage: true, setIsFirstMessage: (isFirstMessage) => set({ isFirstMessage }), diff --git a/app/widget/src/store/index.tsx b/app/widget/src/store/index.tsx index cb221f1b..f39d6326 100644 --- a/app/widget/src/store/index.tsx +++ b/app/widget/src/store/index.tsx @@ -25,7 +25,7 @@ export const useStoreMessage = create((set) => ({ setMessages: (messages) => set({ messages }), history: [], setHistory: (history) => set({ history }), - streaming: false, + streaming: true, setStreaming: (streaming) => set({ streaming }), })); From 3d6d504c87751505fbba0bd1857ae36c903607c7 Mon Sep 17 00:00:00 2001 From: n4ze3m Date: Fri, 17 Nov 2023 21:11:40 +0530 Subject: [PATCH 03/14] Enchance streaming --- .../bot/playground/handlers/chat.handler.ts | 49 +++++++++---------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/server/src/routes/api/v1/bot/playground/handlers/chat.handler.ts b/server/src/routes/api/v1/bot/playground/handlers/chat.handler.ts index 0a5f4cf4..05d18c93 100644 --- a/server/src/routes/api/v1/bot/playground/handlers/chat.handler.ts +++ b/server/src/routes/api/v1/bot/playground/handlers/chat.handler.ts @@ -6,8 +6,10 @@ import { chatModelProvider } from "../../../../../../utils/models"; import { DialoqbaseHybridRetrival } from "../../../../../../utils/hybrid"; import { BaseRetriever } from "langchain/schema/retriever"; import { Document } from "langchain/document"; -import { createChain, groupMessagesByConversation } from "../../../../../../chain"; - +import { + createChain, + groupMessagesByConversation, +} from "../../../../../../chain"; export const chatRequestHandler = async ( request: FastifyRequest, @@ -140,10 +142,12 @@ export const chatRequestHandler = async ( const botResponse = await chain.invoke({ question: sanitizedQuestion, - chat_history: groupMessagesByConversation(history.map((message) => ({ - type: message.type, - content: message.text, - })),) + chat_history: groupMessagesByConversation( + history.map((message) => ({ + type: message.type, + content: message.text, + })) + ), }); const documents = await documentPromise; @@ -230,10 +234,6 @@ export const chatRequestStreamHandler = async ( const bot_id = request.params.id; const { message, history, history_id } = request.body; - // const history = JSON.parse(chatHistory) as { - // type: string; - // text: string; - // }[]; try { const prisma = request.server.prisma; @@ -351,27 +351,13 @@ export const chatRequestStreamHandler = async ( } } - let response: any = null; + let response: string = ""; const streamedModel = chatModelProvider( bot.provider, bot.model, temperature, { streaming: true, - callbacks: [ - { - handleLLMNewToken(token: string) { - return reply.sse({ - id: "", - event: "chunk", - data: JSON.stringify({ - message: token || "", - }), - }); - - }, - }, - ], ...botConfig, } ); @@ -397,7 +383,7 @@ export const chatRequestStreamHandler = async ( retriever, }); - response = await chain.invoke({ + let stream = await chain.stream({ question: sanitizedQuestion, chat_history: groupMessagesByConversation( history.map((message) => ({ @@ -407,6 +393,17 @@ export const chatRequestStreamHandler = async ( ), }); + for await (const token of stream) { + reply.sse({ + id: "", + event: "chunk", + data: JSON.stringify({ + message: token || "", + }), + }); + response += token; + } + let historyId = history_id; const documents = await documentPromise; From 53c3919f8ab7709e486b11c913da10648fdb1a78 Mon Sep 17 00:00:00 2001 From: n4ze3m Date: Sat, 18 Nov 2023 18:59:09 +0530 Subject: [PATCH 04/14] Bot playground form UI updated --- app/ui/src/Layout/BotPlaygroundLayout.tsx | 1 + app/ui/src/components/Bot/Playground/Form.tsx | 79 ++++++++----------- .../src/components/Bot/Playground/index.tsx | 4 +- 3 files changed, 38 insertions(+), 46 deletions(-) diff --git a/app/ui/src/Layout/BotPlaygroundLayout.tsx b/app/ui/src/Layout/BotPlaygroundLayout.tsx index 6fe1207b..54140f98 100644 --- a/app/ui/src/Layout/BotPlaygroundLayout.tsx +++ b/app/ui/src/Layout/BotPlaygroundLayout.tsx @@ -297,6 +297,7 @@ export default function BotPlaygroundLayout({ {children} + diff --git a/app/ui/src/components/Bot/Playground/Form.tsx b/app/ui/src/components/Bot/Playground/Form.tsx index c3d994b0..fbe30af1 100644 --- a/app/ui/src/components/Bot/Playground/Form.tsx +++ b/app/ui/src/components/Bot/Playground/Form.tsx @@ -73,15 +73,8 @@ export const PlaygroundgForm = () => { const textareaRef = React.useRef(null); React.useEffect(() => { - const textarea = textareaRef.current; - if (textarea) { - const increaseHeight = () => { - textarea.style.height = "auto"; - textarea.style.height = `${Math.min(textarea.scrollHeight, 300)}px`; - }; - increaseHeight(); - textarea.addEventListener("input", increaseHeight); - return () => textarea.removeEventListener("input", increaseHeight); + if (textareaRef.current) { + textareaRef.current.focus(); } }, []); @@ -106,8 +99,8 @@ export const PlaygroundgForm = () => { }; return ( -
-
+
+
{ @@ -117,34 +110,34 @@ export const PlaygroundgForm = () => { })} className="shrink-0 flex-grow flex items-center " > -
+