Skip to content

Commit

Permalink
Merge pull request #37 from miurla/fix-task-manager
Browse files Browse the repository at this point in the history
Fix taskManager error handling
  • Loading branch information
miurla authored Apr 14, 2024
2 parents a9a47f1 + 672155c commit a37a675
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
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
}
}

0 comments on commit a37a675

Please sign in to comment.