An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
Update query-suggestor, researcher, and inquire agentsgst
Yoshiki Miuraf7f5fb694226
diff --git a/lib/agents/inquire.tsx b/lib/agents/inquire.tsxindex f7e84532..82254168 100644--- a/lib/agents/inquire.tsx+++ b/lib/agents/inquire.tsx@@ -14,10 +14,24 @@ export async function inquire(let finalInquiry: PartialInquiry = {}await experimental_streamObject({model: openai.chat('gpt-4-turbo-preview'),- system: `You are a professional web researcher tasked with deepening your understanding of the user's input through further inquiries.- Only ask additional questions if absolutely necessary after receiving an initial response from the user.- Structure your inquiry as follows:- e.g., {+ system: `As a professional web researcher, your role is to deepen your understanding of the user's input by conducting further inquiries when necessary.+ After receiving an initial response from the user, carefully assess whether additional questions are absolutely essential to provide a comprehensive and accurate answer. Only proceed with further inquiries if the available information is insufficient or ambiguous.++ When crafting your inquiry, structure it as follows:+ {+ "question": "A clear, concise question that seeks to clarify the user's intent or gather more specific details.",+ "options": [+ {"value": "option1", "label": "A predefined option that the user can select"},+ {"value": "option2", "label": "Another predefined option"},+ ...+ ],+ "allowsInput": true/false, // Indicates whether the user can provide a free-form input+ "inputLabel": "A label for the free-form input field, if allowed",+ "inputPlaceholder": "A placeholder text to guide the user's free-form input"+ }++ For example:+ {"question": "What specific information are you seeking about Rivian?","options": [{"value": "history", "label": "History"},@@ -29,7 +43,11 @@ export async function inquire("allowsInput": true,"inputLabel": "If other, please specify","inputPlaceholder": "e.g., Specifications"- }`,+ }++ By providing predefined options, you guide the user towards the most relevant aspects of their query, while the free-form input allows them to provide additional context or specific details not covered by the options.+ Remember, your goal is to gather the necessary information to deliver a thorough and accurate response.+ `,messages,schema: inquirySchema})diff --git a/lib/agents/query-suggestor.tsx b/lib/agents/query-suggestor.tsxindex 8f9a4bee..59dc4f39 100644--- a/lib/agents/query-suggestor.tsx+++ b/lib/agents/query-suggestor.tsx@@ -18,16 +18,20 @@ export async function querySuggestor(await experimental_streamObject({model: openai.chat('gpt-4-turbo-preview'),- system: `You are tasked as a professional web researcher to generate queries that delve deeper into the subject based on the initial query and its search results. Your goal is to formulate three related questions.- For example, given the query: "Starship's third test flight key milestones",- Your output should look like:+ system: `As a professional web researcher, your task is to generate a set of three queries that explore the subject matter more deeply, building upon the initial query and the information uncovered in its search results.++ For instance, if the original query was "Starship's third test flight key milestones", your output should follow this format:+"{"related": [- "Key milestones achieved during Starship's third test flight",- "Reason for Starship's failure during the third test flight",- "Future plans for Starship following the third test flight"+ "What were the primary objectives achieved during Starship's third test flight?",+ "What factors contributed to the ultimate outcome of Starship's third test flight?",+ "How will the results of the third test flight influence SpaceX's future development plans for Starship?"]- }"`,+ }"++ Aim to create queries that progressively delve into more specific aspects, implications, or adjacent topics related to the initial query. The goal is to anticipate the user's potential information needs and guide them towards a more comprehensive understanding of the subject matter.+ `,messages,schema: relatedSchema})diff --git a/lib/agents/researcher.tsx b/lib/agents/researcher.tsxindex da206dc3..f1a3c554 100644--- a/lib/agents/researcher.tsx+++ b/lib/agents/researcher.tsx@@ -23,13 +23,21 @@ export async function researcher(const searchAPI: 'tavily' | 'exa' = 'tavily'let fullResponse = ''+ const answerSection = (+ <Section title="Answer">+ <BotMessage content={streamText.value} />+ </Section>+ )+const result = await experimental_streamText({model: openai.chat('gpt-4-turbo-preview'),maxTokens: 2500,- system: `As a professional web researcher, you possess the ability to search the web for any information.- Utilize the search results to offer additional assistance or information as needed.- Include a key image in your response if one is relevant. Respond to the user's query accordingly.- `,+ system: `As a professional search expert, you possess the ability to search for any information on the web.+ For each user query, utilize the search results to their fullest potential to provide additional information and assistance in your response.+ If there are any key 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.+ Whenever quoting or referencing information from a specific URL, always cite the source URL explicitly.+ `,messages,tools: {search: {@@ -75,11 +83,7 @@ export async function researcher(</Section>)- uiStream.append(- <Section title="Answer">- <BotMessage content={streamText.value} />- </Section>- )+ uiStream.append(answerSection)return searchResult}@@ -93,6 +97,12 @@ export async function researcher(switch (delta.type) {case 'text-delta':if (delta.textDelta) {+ // If the first text delata is available, add a ui section+ if (fullResponse.length === 0 && delta.textDelta.length > 0) {+ // Update the UI+ uiStream.update(answerSection)+ }+fullResponse += delta.textDeltastreamText.update(fullResponse)}diff --git a/lib/agents/task-manager.tsx b/lib/agents/task-manager.tsxindex 4a506890..2bbf5b4e 100644--- a/lib/agents/task-manager.tsx+++ b/lib/agents/task-manager.tsx@@ -6,11 +6,15 @@ import { nextActionSchema } from '../schema/next-action'export async function taskManager(messages: ExperimentalMessage[]) {const result = await experimental_generateObject({model: openai.chat('gpt-3.5-turbo'),- system: `You are a professional web researcher tasked with fully understanding the user's query, conducting web searches for the necessary information, and responding accordingly.- Your goal is to comprehend the user's input and determine the next step. You have the option to present a form and request further information from the user.- Select one of the three options based on the context: "proceed", "inquire". Use "proceed" if the provided information is sufficient for action.- Opt for "inquire" if more information can be gathered through questions, allowing for default selections and free-form input.- Make your choice wisely to fulfill your mission effectively.`,+ system: `As a professional web researcher, your primary objective is to fully comprehend the user's query, conduct thorough web searches to gather the necessary information, and provide an appropriate response.+ To achieve this, you must first analyze the user's input and determine the optimal course of action. You have two options at your disposal:+ 1. "proceed": If the provided information is sufficient to address the query effectively, choose this option to proceed with the research and formulate a response.+ 2. "inquire": If you believe that additional information from the user would enhance your ability to provide a comprehensive response, select this option. You may present a form to the user, offering default selections or free-form input fields, to gather the required details.+ Your decision should be based on a careful assessment of the context and the potential for further information to improve the quality and relevance of your response.+ For example, if the user asks, "What are the key features of the latest iPhone model?", you may choose to "proceed" as the query is clear and can be answered effectively with web research alone.+ However, if the user asks, "What's the best smartphone for my needs?", you may opt to "inquire" and present a form asking about their specific requirements, budget, and preferred features to provide a more tailored recommendation.+ Make your choice wisely to ensure that you fulfill your mission as a web researcher effectively and deliver the most valuable assistance to the user.+ `,messages,schema: nextActionSchema})