An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
chore: Update chat researcher and retrieve tool
Yoshiki Miurab77951098c9b
diff --git a/lib/agents/chat-researcher.ts b/lib/agents/chat-researcher.tsindex 9d4b1022..f8c100ee 100644--- a/lib/agents/chat-researcher.ts+++ b/lib/agents/chat-researcher.ts@@ -1,14 +1,16 @@import { CoreMessage, streamText } from 'ai'import { getModel } from '../utils/registry'import { searchTool } from './tools/search'+import { retrieveTool } from './tools/retrieve'-const SYSTEM_PROMPT = `You are a helpful AI assistant with access to real-time web search capabilities.+const SYSTEM_PROMPT = `You are a helpful AI assistant with access to real-time web search capabilities and content retrieval.When asked a question, you should:1. Search for relevant information using the search tool when needed-2. Analyze the search results and provide accurate, up-to-date information-3. Always cite your sources when using information from search results-4. If search results are not relevant or helpful, rely on your general knowledge-5. Be concise and direct in your responses+2. Use the retrieve tool to get detailed content from specific URLs+3. Analyze the search and retrieved results to provide accurate, up-to-date information+4. Always cite your sources when using information from search or retrieved content+5. If results are not relevant or helpful, rely on your general knowledge+6. Be concise and direct in your responsesRemember to:- Use search for current events, facts, or when you need to verify information@@ -31,7 +33,7 @@ export async function chatResearcher({model: getModel(model),system: `${SYSTEM_PROMPT}\nCurrent date and time: ${currentDate}`,messages,- tools: { search: searchTool },+ tools: { search: searchTool, retrieve: retrieveTool },maxSteps: 5}} catch (error) {diff --git a/lib/agents/tools/retrieve.tsx b/lib/agents/tools/retrieve.tssimilarity index 65%rename from lib/agents/tools/retrieve.tsxrename to lib/agents/tools/retrieve.tsindex 3cb55911..1d1a9e9d 100644--- a/lib/agents/tools/retrieve.tsx+++ b/lib/agents/tools/retrieve.ts@@ -1,9 +1,6 @@import { tool } from 'ai'import { retrieveSchema } from '@/lib/schema/retrieve'-import { ToolProps } from '.'-import { DefaultSkeleton } from '@/components/default-skeleton'import { SearchResults as SearchResultsType } from '@/lib/types'-import RetrieveSection from '@/components/retrieve-section'const CONTENT_CHARACTER_LIMIT = 10000@@ -79,32 +76,24 @@ async function fetchTavilyExtractData(}}-export const retrieveTool = ({ uiStream, fullResponse }: ToolProps) =>- tool({- description: 'Retrieve content from the web',- parameters: retrieveSchema,- execute: async ({ url }) => {- // Append the search section- uiStream.update(<DefaultSkeleton />)+export const retrieveTool = tool({+ description: 'Retrieve content from the web',+ parameters: retrieveSchema,+ execute: async ({ url }) => {+ let results: SearchResultsType | null- let results: SearchResultsType | null-- // Use Jina if the API key is set, otherwise use Tavily- const useJina = process.env.JINA_API_KEY- if (useJina) {- results = await fetchJinaReaderData(url)- } else {- results = await fetchTavilyExtractData(url)- }-- if (!results) {- fullResponse = `An error occurred while retrieving "${url}".`- uiStream.update(null)- return results- }-- uiStream.update(<RetrieveSection data={results} />)+ // Use Jina if the API key is set, otherwise use Tavily+ const useJina = process.env.JINA_API_KEY+ if (useJina) {+ results = await fetchJinaReaderData(url)+ } else {+ results = await fetchTavilyExtractData(url)+ }- return results+ if (!results) {+ return null}- })++ return results+ }+})