Skip to content

Commit 6be1fb8

Browse files
authored
fix: correct completion endpoint when logprobs missing (#550)
1 parent babb3e1 commit 6be1fb8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Responses/Completions/CreateResponseChoice.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ public static function from(array $attributes): self
2121
return new self(
2222
$attributes['text'],
2323
$attributes['index'],
24-
$attributes['logprobs'] ? CreateResponseChoiceLogprobs::from($attributes['logprobs']) : null,
24+
isset($attributes['logprobs'])
25+
? CreateResponseChoiceLogprobs::from($attributes['logprobs'])
26+
: null,
2527
$attributes['finish_reason'],
2628
);
2729
}

tests/Responses/Completions/CreateResponseChoice.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
->finishReason->toBeIn(['length', null]);
1414
});
1515

16+
test('from with missing logprobs', function () {
17+
$payload = completion()['choices'][0];
18+
unset($payload['logprobs']);
19+
$result = CreateResponseChoice::from($payload);
20+
21+
expect($result)
22+
->text->toBe("el, she elaborates more on the Corruptor's role, suggesting K")
23+
->index->toBe(0)
24+
->logprobs->toBeNull()
25+
->finishReason->toBeIn(['length', null]);
26+
});
27+
1628
test('to array', function () {
1729
$result = CreateResponseChoice::from(completion()['choices'][0]);
1830

0 commit comments

Comments
 (0)