An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
Update ai/rsc import in researcher.tsx and writer.tsx
Yoshiki Miura9f690d5c9f86
diff --git a/lib/agents/researcher.tsx b/lib/agents/researcher.tsxindex 7ca6a921..5cd2ec7c 100644--- a/lib/agents/researcher.tsx+++ b/lib/agents/researcher.tsx@@ -1,10 +1,5 @@import { createStreamableUI, createStreamableValue } from 'ai/rsc'-import {- CoreMessage,- ToolCallPart,- ToolResultPart,- streamText as nonexperimental_streamText-} from 'ai'+import { CoreMessage, ToolCallPart, ToolResultPart, streamText } from 'ai'import { Section } from '@/components/section'import { BotMessage } from '@/components/message'import { getTools } from './tools'@@ -12,7 +7,7 @@ import { getModel } from '../utils'export async function researcher(uiStream: ReturnType<typeof createStreamableUI>,- streamText: ReturnType<typeof createStreamableValue<string>>,+ streamableText: ReturnType<typeof createStreamableValue<string>>,messages: CoreMessage[],useSpecificModel?: boolean) {@@ -20,12 +15,12 @@ export async function researcher(let hasError = falseconst answerSection = (<Section title="Answer">- <BotMessage content={streamText.value} />+ <BotMessage content={streamableText.value} /></Section>)const currentDate = new Date().toLocaleString()- const result = await nonexperimental_streamText({+ const result = await streamText({model: getModel(),maxTokens: 2500,system: `As a professional search expert, you possess the ability to search for any information on the web.@@ -44,7 +39,7 @@ export async function researcher(}).catch(err => {hasError = truefullResponse = 'Error: ' + err.message- streamText.update(fullResponse)+ streamableText.update(fullResponse)})// If the result is not available, return an error response@@ -69,7 +64,7 @@ export async function researcher(}fullResponse += delta.textDelta- streamText.update(fullResponse)+ streamableText.update(fullResponse)}breakcase 'tool-call':diff --git a/lib/agents/writer.tsx b/lib/agents/writer.tsxindex 9c99aef5..04db752f 100644--- a/lib/agents/writer.tsx+++ b/lib/agents/writer.tsx@@ -1,19 +1,19 @@import { createStreamableUI, createStreamableValue } from 'ai/rsc'-import { CoreMessage, streamText as nonexperimental_streamText } from 'ai'+import { CoreMessage, streamText } from 'ai'import { Section } from '@/components/section'import { BotMessage } from '@/components/message'import { OpenAI } from '@ai-sdk/openai'export async function writer(uiStream: ReturnType<typeof createStreamableUI>,- streamText: ReturnType<typeof createStreamableValue<string>>,+ streamableText: ReturnType<typeof createStreamableValue<string>>,messages: CoreMessage[]) {let fullResponse = ''let hasError = falseconst answerSection = (<Section title="Answer">- <BotMessage content={streamText.value} />+ <BotMessage content={streamableText.value} /></Section>)uiStream.append(answerSection)@@ -24,7 +24,7 @@ export async function writer(organization: '' // optional organization})- await nonexperimental_streamText({+ await streamText({model: openai!.chat(process.env.SPECIFIC_API_MODEL || 'llama3-70b-8192'),maxTokens: 2500,system: `As a professional writer, your job is to generate a comprehensive and informative, yet concise answer of 400 words or less for the given question based solely on the provided search results (URL and content). You must only use information from the provided search results. Use an unbiased and journalistic tone. Combine search results together into a coherent answer. Do not repeat text. If there are any images relevant to your answer, be sure to include them as well. Aim to directly address the user's question, augmenting your response with insights gleaned from the search results.@@ -39,17 +39,17 @@ export async function writer(for await (const text of result.textStream) {if (text) {fullResponse += text- streamText.update(fullResponse)+ streamableText.update(fullResponse)}}}).catch(err => {hasError = truefullResponse = 'Error: ' + err.message- streamText.update(fullResponse)+ streamableText.update(fullResponse)}).finally(() => {- streamText.done()+ streamableText.done()})return { response: fullResponse, hasError }