Skip to content

Modify the properties in CreateResponseUsageCompletionTokensDetails to allow null #521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Responses/Chat/CreateResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private function __construct(
/**
* Acts as static factory, and returns a new Response instance.
*
* @param array{id: string, object: string, created: int, model: string, system_fingerprint?: string, choices: array<int, array{index: int, message: array{role: string, content: ?string, function_call: ?array{name: string, arguments: string}, tool_calls: ?array<int, array{id: string, type: string, function: array{name: string, arguments: string}}>}, finish_reason: string|null}>, usage: array{prompt_tokens: int, completion_tokens: int|null, total_tokens: int, prompt_tokens_details?:array{cached_tokens:int}, completion_tokens_details?:array{audio_tokens?:int, reasoning_tokens:int, accepted_prediction_tokens:int, rejected_prediction_tokens:int}}} $attributes
* @param array{id: string, object: string, created: int, model: string, system_fingerprint?: string, choices: array<int, array{index: int, message: array{role: string, content: ?string, function_call: ?array{name: string, arguments: string}, tool_calls: ?array<int, array{id: string, type: string, function: array{name: string, arguments: string}}>}, finish_reason: string|null}>, usage: array{prompt_tokens: int, completion_tokens: int|null, total_tokens: int, prompt_tokens_details?:array{cached_tokens:int}, completion_tokens_details?:array{audio_tokens?:int, reasoning_tokens?:int, accepted_prediction_tokens?:int, rejected_prediction_tokens?:int}}} $attributes
*/
public static function from(array $attributes, MetaInformation $meta): self
{
Expand Down
2 changes: 1 addition & 1 deletion src/Responses/Chat/CreateResponseUsage.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private function __construct(
) {}

/**
* @param array{prompt_tokens: int, completion_tokens: int|null, total_tokens: int, prompt_tokens_details?:array{cached_tokens:int}, completion_tokens_details?:array{audio_tokens?:int, reasoning_tokens:int, accepted_prediction_tokens:int, rejected_prediction_tokens:int}} $attributes
* @param array{prompt_tokens: int, completion_tokens: int|null, total_tokens: int, prompt_tokens_details?:array{cached_tokens:int}, completion_tokens_details?:array{audio_tokens?:int, reasoning_tokens?:int, accepted_prediction_tokens?:int, rejected_prediction_tokens?:int}} $attributes
*/
public static function from(array $attributes): self
{
Expand Down
36 changes: 22 additions & 14 deletions src/Responses/Chat/CreateResponseUsageCompletionTokensDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,47 @@ final class CreateResponseUsageCompletionTokensDetails
{
private function __construct(
public readonly ?int $audioTokens,
public readonly int $reasoningTokens,
public readonly int $acceptedPredictionTokens,
public readonly int $rejectedPredictionTokens
public readonly ?int $reasoningTokens,
public readonly ?int $acceptedPredictionTokens,
public readonly ?int $rejectedPredictionTokens
) {}

/**
* @param array{audio_tokens?:int, reasoning_tokens:int, accepted_prediction_tokens:int, rejected_prediction_tokens:int} $attributes
* @param array{audio_tokens?:int, reasoning_tokens?:int, accepted_prediction_tokens?:int, rejected_prediction_tokens?:int} $attributes
*/
public static function from(array $attributes): self
{
return new self(
$attributes['audio_tokens'] ?? null,
$attributes['reasoning_tokens'],
$attributes['accepted_prediction_tokens'],
$attributes['rejected_prediction_tokens'],
$attributes['reasoning_tokens'] ?? null,
$attributes['accepted_prediction_tokens'] ?? null,
$attributes['rejected_prediction_tokens'] ?? null,
);
}

/**
* @return array{audio_tokens?:int, reasoning_tokens:int, accepted_prediction_tokens:int, rejected_prediction_tokens:int}
* @return array{audio_tokens?:int, reasoning_tokens?:int, accepted_prediction_tokens?:int, rejected_prediction_tokens?:int}
*/
public function toArray(): array
{
$result = [
'reasoning_tokens' => $this->reasoningTokens,
'accepted_prediction_tokens' => $this->acceptedPredictionTokens,
'rejected_prediction_tokens' => $this->rejectedPredictionTokens,
];
$result = [];

if (! is_null($this->audioTokens)) {
if ($this->audioTokens !== null) {
$result['audio_tokens'] = $this->audioTokens;
}

if ($this->reasoningTokens !== null) {
$result['reasoning_tokens'] = $this->reasoningTokens;
}

if ($this->acceptedPredictionTokens !== null) {
$result['accepted_prediction_tokens'] = $this->acceptedPredictionTokens;
}

if ($this->rejectedPredictionTokens !== null) {
$result['rejected_prediction_tokens'] = $this->rejectedPredictionTokens;
}

return $result;
}
}