Skip to content

Commit

Permalink
Add test case for function without output
Browse files Browse the repository at this point in the history
When a function tool call requires an action, its `output` is not yet submitted, therefore the key doesn't exists
  • Loading branch information
Michel MA authored and gehrisandro committed Jan 26, 2024
1 parent b67520c commit 45ee20e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static function from(array $attributes): self
return new self(
$attributes['name'],
$attributes['arguments'],
$attributes['output'],
$attributes['output'] ?? null,
);
}

Expand Down
36 changes: 36 additions & 0 deletions tests/Fixtures/ThreadRunSteps.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,42 @@ function threadRunStepWithCodeInterpreterOutputResource(): array
];
}

/**
* @return array<string, mixed>
*/
function threadRunStepWithFunctionCallPendingOutputResource(): array
{
return [
'id' => 'step_1spQXgbAabXFm1YXrwiGIMUz',
'object' => 'thread.run.step',
'created_at' => 1699564106,
'run_id' => 'run_fYijubpOJsKDnvtACWBS8C8r',
'assistant_id' => 'asst_EopvUEMh90bxkNRYEYM81Orc',
'thread_id' => 'thread_3WdOgtVuhD8aUIEx774Whkvo',
'type' => 'tool_calls',
'status' => 'in_progress',
'cancelled_at' => null,
'completed_at' => 1699564119,
'expires_at' => null,
'failed_at' => null,
'last_error' => null,
'step_details' => [
'type' => 'tool_calls',
'tool_calls' => [
[
'id' => 'call_Fbg14X7kZF2WDzlPhpQ167De',
'type' => 'function',
'function' => [
'name' => 'add',
'arguments' => '{ "a": 5, "b": 7 }',
],
],
],
],
'metadata' => ['name' => 'the step name'],
];
}

/**
* @return array<string, mixed>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
->output->toBe('12');
});

test('from function call with output not submitted', function () {
$result = ThreadRunStepResponseFunction::from(threadRunStepWithFunctionCallPendingOutputResource()['step_details']['tool_calls'][0]['function']);
expect($result)
->name->toBe('add')
->arguments->toBe('{ "a": 5, "b": 7 }')
->output->toBeEmpty();
});

test('as array accessible', function () {
$result = ThreadRunStepResponseFunction::from(threadRunStepWithCodeInterpreterOutputResource()['step_details']['tool_calls'][1]['function']);

Expand Down

0 comments on commit 45ee20e

Please sign in to comment.