Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6be1fb8

Browse filesBrowse files
authored
fix: correct completion endpoint when logprobs missing (openai-php#550)
1 parent babb3e1 commit 6be1fb8
Copy full SHA for 6be1fb8

File tree

Expand file treeCollapse file tree

2 files changed

+15
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+15
-1
lines changed

‎src/Responses/Completions/CreateResponseChoice.php

Copy file name to clipboardExpand all lines: src/Responses/Completions/CreateResponseChoice.php
+3-1Lines 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

Copy file name to clipboardExpand all lines: tests/Responses/Completions/CreateResponseChoice.php
+12Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.