Skip to content

Commit a37a675

Browse files
authored
Merge pull request miurla#37 from miurla/fix-task-manager
Fix taskManager error handling
2 parents a9a47f1 + 672155c commit a37a675

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

app/action.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async function submit(formData?: FormData, skip?: boolean) {
4040

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

4545
if (action.object.next === 'inquire') {
4646
// Generate inquiry

lib/agents/task-manager.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ export async function taskManager(messages: ExperimentalMessage[]) {
1010
organization: '' // optional organization
1111
})
1212

13-
const result = await experimental_generateObject({
14-
model: openai.chat(process.env.OPENAI_API_MODEL || 'gpt-4-turbo'),
15-
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.
13+
try {
14+
const result = await experimental_generateObject({
15+
model: openai.chat(process.env.OPENAI_API_MODEL || 'gpt-4-turbo'),
16+
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.
1617
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:
1718
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.
1819
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.
@@ -21,9 +22,13 @@ export async function taskManager(messages: ExperimentalMessage[]) {
2122
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.
2223
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.
2324
`,
24-
messages,
25-
schema: nextActionSchema
26-
})
25+
messages,
26+
schema: nextActionSchema
27+
})
2728

28-
return result
29+
return result
30+
} catch (error) {
31+
console.error(error)
32+
return null
33+
}
2934
}

0 commit comments

Comments
 (0)