8000 Add test case for function without output · openai-php/client@45ee20e · GitHub
[go: up one dir, main page]

Skip to content

Commit 45ee20e

Browse files
Michel MAgehrisandro
authored andcommitted
Add test case for function without output
When a function tool call requires an action, its `output` is not yet submitted, therefore the key doesn't exists
1 parent b67520c commit 45ee20e

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

src/Responses/Threads/Runs/Steps/ThreadRunStepResponseFunction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static function from(array $attributes): self
3737
return new self(
3838
$attributes['name'],
3939
$attributes['arguments'],
40-
$attributes['output'],
40+
$attributes['output'] ?? null,
4141
);
4242
}
4343

tests/Fixtures/ThreadRunSteps.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,42 @@ function threadRunStepWithCodeInterpreterOutputResource(): array
8989
];
9090
}
9191

92+
/**
93+
* @return array<string, mixed>
94+
*/
95+
function threadRunStepWithFunctionCallPendingOutputResource(): array
96+
{
97+
return [
98+
'id' => 'step_1spQXgbAabXFm1YXrwiGIMUz',
99+
'object' => 'thread.run.step',
100+
'created_at' => 1699564106,
101+
'run_id' => 'run_fYijubpOJsKDnvtACWBS8C8r',
102+
'assistant_id' => 'asst_EopvUEMh90bxkNRYEYM81Orc',
103+
'thread_id' => 'thread_3WdOgtVuhD8aUIEx774Whkvo',
104+
'type' => 'tool_calls',
105+
'status' => 'in_progress',
106+
'cancelled_at' => null,
107+
'completed_at' => 1699564119,
108+
'expires_at' => null,
109+
'failed_at' => null,
110+
'last_error' => null,
111+
'step_details' => [
112+
'type' => 'tool_calls',
113+
'tool_calls' => [
114+
[
115+
'id' => 'call_Fbg14X7kZF2WDzlPhpQ167De',
116+
'type' => 'function',
117+
'function' => [
118+
'name' => 'add',
119+
'arguments' => '{ "a": 5, "b": 7 }',
120+
],
121+
],
122+
],
123+
],
124+
'metadata' => ['name' => 'the step name'],
125+
];
126+
}
127+
92128
/**
93129
* @return array<string, mixed>
94130
*/

tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseFunction.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
->output->toBe('12');
1111
});
1212

13+
test('from function call with output not submitted', function () {
14+
$result = ThreadRunStepResponseFunction::from(threadRunStepWithFunctionCallPendingOutputResource()['step_details']['tool_calls'][0]['function']);
15+
expect($result)
16+
->name->toBe('add')
17+
->arguments->toBe('{ "a": 5, "b": 7 }')
18+
->output->toBeEmpty();
19+
});
20+
1321
test('as array accessible', function () {
1422
$result = ThreadRunStepResponseFunction::from(threadRunStepWithCodeInterpreterOutputResource()['step_details']['tool_calls'][1]['function']);
1523

0 commit comments

Comments
 (0)
0