An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
refactor: modify researcher to return streamText result directly
Yoshiki Miurae9a4a8db4fb3
diff --git a/lib/agents/researcher.ts b/lib/agents/researcher.tsindex 4b70f75d..d0533aad 100644--- a/lib/agents/researcher.ts+++ b/lib/agents/researcher.ts@@ -33,8 +33,6 @@ Citation Format:[number](url)`-type ResearcherReturn = Parameters<typeof streamText>[0]-export function researcher({messages,model,@@ -43,7 +41,7 @@ export function researcher({messages: ModelMessage[]model: stringsearchMode: boolean-}): ResearcherReturn {+}) {try {const currentDate = new Date().toLocaleString()@@ -52,7 +50,7 @@ export function researcher({const videoSearchTool = createVideoSearchTool(model)const askQuestionTool = createQuestionTool(model)- return {+ const config = {model: openai('gpt-4o-mini'), // TODO: Make this configurablesystem: `${SYSTEM_PROMPT}\nCurrent date and time: ${currentDate}`,messages,@@ -68,6 +66,8 @@ export function researcher({maxSteps: searchMode ? 5 : 1,experimental_transform: smoothStream()}++ return streamText(config)} catch (error) {console.error('Error in chatResearcher:', error)throw errordiff --git a/lib/streaming/create-tool-calling-stream.ts b/lib/streaming/create-tool-calling-stream.tsindex 86657214..262e75fe 100644--- a/lib/streaming/create-tool-calling-stream.ts+++ b/lib/streaming/create-tool-calling-stream.ts@@ -5,7 +5,6 @@ import {convertToModelMessages,createUIMessageStream,createUIMessageStreamResponse,- streamText,UIMessageStreamWriter} from 'ai'import { saveChatMessage, saveSingleMessage } from '../actions/chat-db'@@ -51,16 +50,12 @@ export function createToolCallingStreamResponse(config: BaseStreamConfig) {message})- let researcherConfig = await researcher({+ const result = await researcher({messages: convertToModelMessages(messages),model: modelId,searchMode})- const result = streamText({- ...researcherConfig- })-writer.merge(result.toUIMessageStream({newMessageId: generateUUID(),