@@ -9,12 +9,7 @@ export const completeTask = async (
9
9
page : Page ,
10
10
task : TaskMessage
11
11
) : Promise < TaskResult > => {
12
- const openai = new OpenAI ( {
13
- apiKey : task . options ?. openaiApiKey ,
14
- baseURL : task . options ?. openaiBaseUrl ,
15
- defaultQuery : task . options ?. openaiDefaultQuery ,
16
- defaultHeaders : task . options ?. openaiDefaultHeaders ,
17
- } ) ;
12
+ const openai = new OpenAI ( { apiKey : task . options ?. openaiApiKey } ) ;
18
13
19
14
let lastFunctionResult : null | { errorMessage : string } | { query : string } =
20
15
null ;
@@ -25,7 +20,7 @@ export const completeTask = async (
25
20
26
21
const runner = openai . beta . chat . completions
27
22
. runTools ( {
28
- model : task . options ?. model ?? "gpt-4-1106-preview " ,
23
+ model : task . options ?. model ?? "gpt-4o " ,
29
24
messages : [ { role : "user" , content : prompt ( task ) } ] ,
30
25
tools : Object . values ( actions ) . map ( ( action ) => ( {
31
26
type : "function" ,
@@ -39,9 +34,13 @@ export const completeTask = async (
39
34
40
35
if (
41
36
message . role === "assistant" &&
42
- message . function_call ?. name . startsWith ( "result" )
37
+ message . tool_calls &&
38
+ message . tool_calls . length > 0 &&
39
+ message . tool_calls [ 0 ] . function . name . startsWith ( "result" )
43
40
) {
44
- lastFunctionResult = JSON . parse ( message . function_call . arguments ) ;
41
+ lastFunctionResult = JSON . parse (
42
+ message . tool_calls [ 0 ] . function . arguments
43
+ ) ;
45
44
}
46
45
} ) ;
47
46
0 commit comments