Skip to content

Commit

Permalink
sanitize tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gehrisandro committed Aug 28, 2023
1 parent 6b09676 commit d9f8b8a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 36 deletions.
27 changes: 5 additions & 22 deletions tests/Fixtures/Chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,13 @@ function chatCompletionWithFunction(): array
/**
* @return array<string, mixed>
*/
function chatCompletionWithFunctionAndNoContent(): array
function chatCompletionMessageWithFunctionAndNoContent(): array
{
return [
'id' => 'chatcmpl-123',
'object' => 'chat.completion',
'created' => 1686689333,
'model' => 'gpt-3.5-turbo-0613',
'choices' => [
[
'index' => 0,
'message' => [
'role' => 'assistant',
'function_call' => [
'name' => 'get_current_weather',
'arguments' => "{\n \"location\": \"Boston, MA\"\n}",
],
],
'finish_reason' => 'function_call',
],
],
'usage' => [
'prompt_tokens' => 82,
'completion_tokens' => 18,
'total_tokens' => 100,
'role' => 'assistant',
'function_call' => [
'name' => 'get_current_weather',
'arguments' => "{\n \"location\": \"Boston, MA\"\n}",
],
];
}
Expand Down
14 changes: 0 additions & 14 deletions tests/Responses/Chat/CreateResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,6 @@
->meta()->toBeInstanceOf(MetaInformation::class);
});

test('from function response without content', function () {
$completion = CreateResponse::from(chatCompletionWithFunctionAndNoContent());

expect($completion)
->toBeInstanceOf(CreateResponse::class)
->id->toBe('chatcmpl-123')
->object->toBe('chat.completion')
->created->toBe(1686689333)
->model->toBe('gpt-3.5-turbo-0613')
->choices->toBeArray()->toHaveCount(1)
->choices->each->toBeInstanceOf(CreateResponseChoice::class)
->usage->toBeInstanceOf(CreateResponseUsage::class);
});

test('as array accessible', function () {
$completion = CreateResponse::from(chatCompletion(), meta());

Expand Down
9 changes: 9 additions & 0 deletions tests/Responses/Chat/CreateResponseMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
->functionCall->toBeInstanceOf(CreateResponseFunctionCall::class);
});

test('from function response without content', function () {
$result = CreateResponseMessage::from(chatCompletionMessageWithFunctionAndNoContent());

expect($result)
->role->toBe('assistant')
->content->toBeNull()
->functionCall->toBeInstanceOf(CreateResponseFunctionCall::class);
});

test('to array', function () {
$result = CreateResponseMessage::from(chatCompletion()['choices'][0]['message']);

Expand Down

0 comments on commit d9f8b8a

Please sign in to comment.