An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
fix: Update generatedMessages
Yoshiki Miurab3bcf7fa1e01
diff --git a/components/answer-section.tsx b/components/answer-section.tsxindex 3aa22193..69998f7c 100644--- a/components/answer-section.tsx+++ b/components/answer-section.tsx@@ -40,7 +40,7 @@ export function AnswerSection({return (<CollapsibleMessagerole="assistant"- isCollapsible={true}+ isCollapsible={false}header={header}isOpen={isOpen}onOpenChange={onOpenChange}diff --git a/components/render-message.tsx b/components/render-message.tsxindex 187852be..719aa196 100644--- a/components/render-message.tsx+++ b/components/render-message.tsx@@ -25,7 +25,7 @@ export function RenderMessage({}: RenderMessageProps) {const relatedQuestions = useMemo(() =>- message.annotations?.find(+ message.annotations?.filter(annotation => (annotation as any)?.type === 'related-questions'),[message.annotations]@@ -113,14 +113,16 @@ export function RenderMessage({chatId={chatId}/>)}- {!message.toolInvocations && relatedQuestions && (- <RelatedQuestions- annotations={relatedQuestions as JSONValue[]}- onQuerySelect={onQuerySelect}- isOpen={getIsOpen(`${messageId}-related`)}- onOpenChange={open => onOpenChange(`${messageId}-related`, open)}- />- )}+ {!message.toolInvocations &&+ relatedQuestions &&+ relatedQuestions.length > 0 && (+ <RelatedQuestions+ annotations={relatedQuestions as JSONValue[]}+ onQuerySelect={onQuerySelect}+ isOpen={getIsOpen(`${messageId}-related`)}+ onOpenChange={open => onOpenChange(`${messageId}-related`, open)}+ />+ )}</>)}diff --git a/lib/agents/manual-researcher.ts b/lib/agents/manual-researcher.tsindex 0e8fa163..6dc2b0df 100644--- a/lib/agents/manual-researcher.ts+++ b/lib/agents/manual-researcher.ts@@ -12,15 +12,11 @@ You are a helpful AI assistant analyzing search results to provide accurate info4. Only use information that has a URL available for citation5. Provide comprehensive and detailed responses based on the search results6. Use markdown to structure your responses with appropriate headings-7. Include relevant images only when they significantly aid understanding-8. If the search results don't contain relevant information, acknowledge this and provide a general response+7. If the search results don't contain relevant information, acknowledge this and provide a general responseCitation Format:[number](url)-Image Format:--Remember: Focus on the search results provided to you and maintain high accuracy in your responses.`@@ -42,6 +38,9 @@ export function manualResearcher({model: getModel(model),system: `${MANUAL_SYSTEM_PROMPT}\nCurrent date and time: ${currentDate}`,messages,+ temperature: 0.6,+ topP: 1,+ topK: 40,experimental_transform: smoothStream({ chunking: 'word' })}} catch (error) {diff --git a/lib/streaming/create-manual-tool-stream.ts b/lib/streaming/create-manual-tool-stream.tsindex decebf05..6792651e 100644--- a/lib/streaming/create-manual-tool-stream.ts+++ b/lib/streaming/create-manual-tool-stream.ts@@ -14,15 +14,16 @@ import { BaseStreamConfig } from './types'export function createManualToolStreamResponse(config: BaseStreamConfig) {return createDataStreamResponse({execute: async (dataStream: DataStreamWriter) => {+ const { messages, model, chatId } = configtry {- const coreMessages = convertToCoreMessages(config.messages)+ const coreMessages = convertToCoreMessages(messages)const { toolCallDataAnnotation, toolCallMessages } =await executeToolCall(coreMessages, dataStream)const researcherConfig = manualResearcher({messages: [...coreMessages, ...toolCallMessages],- model: config.model+ model})const result = streamText({@@ -41,9 +42,9 @@ export function createManualToolStreamResponse(config: BaseStreamConfig) {await handleStreamFinish({responseMessages: result.response.messages,- originalMessages: config.messages,- model: config.model,- chatId: config.chatId,+ originalMessages: messages,+ model,+ chatId,dataStream,skipRelatedQuestions: true,annotationsdiff --git a/lib/streaming/create-tool-calling-stream.ts b/lib/streaming/create-tool-calling-stream.tsindex c6ec9f3d..fa4bec7b 100644--- a/lib/streaming/create-tool-calling-stream.ts+++ b/lib/streaming/create-tool-calling-stream.ts@@ -11,12 +11,14 @@ import { BaseStreamConfig } from './types'export function createToolCallingStreamResponse(config: BaseStreamConfig) {return createDataStreamResponse({execute: async (dataStream: DataStreamWriter) => {+ const { messages, model, chatId } = config+try {- const coreMessages = convertToCoreMessages(config.messages)+ const coreMessages = convertToCoreMessages(messages)let researcherConfig = await researcher({messages: coreMessages,- model: config.model+ model})const result = streamText({@@ -24,9 +26,9 @@ export function createToolCallingStreamResponse(config: BaseStreamConfig) {onFinish: async result => {await handleStreamFinish({responseMessages: result.response.messages,- originalMessages: config.messages,- model: config.model,- chatId: config.chatId,+ originalMessages: messages,+ model,+ chatId,dataStream})}diff --git a/lib/streaming/handle-stream-finish.ts b/lib/streaming/handle-stream-finish.tsindex b106e686..d756816c 100644--- a/lib/streaming/handle-stream-finish.ts+++ b/lib/streaming/handle-stream-finish.ts@@ -59,8 +59,9 @@ export async function handleStreamFinish({// Create the message to saveconst generatedMessages = [...extendedCoreMessages,- ...allAnnotations,- responseMessages[responseMessages.length - 1]+ ...responseMessages.slice(0, -1),+ ...allAnnotations, // Add annotations before the last message+ ...responseMessages.slice(-1)] as ExtendedCoreMessage[]// Get the chat from the database if it exists, otherwise create a new one