Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix taskManager error handling #37

Merged
merged 1 commit into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function submit(formData?: FormData, skip?: boolean) {

let action: any = { object: { next: 'proceed' } }
// If the user skips the task, we proceed to the search
if (!skip) action = await taskManager(messages)
if (!skip) action = (await taskManager(messages)) ?? action

if (action.object.next === 'inquire') {
// Generate inquiry
Expand Down
19 changes: 12 additions & 7 deletions lib/agents/task-manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ export async function taskManager(messages: ExperimentalMessage[]) {
organization: '' // optional organization
})

const result = await experimental_generateObject({
model: openai.chat(process.env.OPENAI_API_MODEL || 'gpt-4-turbo'),
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.
try {
const result = await experimental_generateObject({
model: openai.chat(process.env.OPENAI_API_MODEL || 'gpt-4-turbo'),
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.
Expand All @@ -21,9 +22,13 @@ export async function taskManager(messages: ExperimentalMessage[]) {
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
})
messages,
schema: nextActionSchema
})

return result
return result
} catch (error) {
console.error(error)
return null
}
}