Skip to content
Open
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
13 changes: 9 additions & 4 deletions src/Responses/Chat/CreateResponseToolCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,34 @@ private function __construct(
public readonly string $id,
public readonly string $type,
public readonly CreateResponseToolCallFunction $function,
public readonly ?CreateResponseToolCallExtraContent $extra_content,
) {}

/**
* @param array{id: string, type?: string, function: array{name: string, arguments: string}} $attributes
* @param array{id: string, type?: string, function: array{name: string, arguments: string}, extra_content?: array{google?: array{thought_signature: string}}} $attributes
*/
public static function from(array $attributes): self
{
return new self(
$attributes['id'],
$attributes['type'] ?? 'function',
CreateResponseToolCallFunction::from($attributes['function']),
isset($attributes['extra_content']) ? CreateResponseToolCallExtraContent::from($attributes['extra_content']) : null,
);
}

/**
* @return array{id: string, type: string, function: array{name: string, arguments: string}}
* @return array{id: string, type: string, function: array{name: string, arguments: string}, extra_content?: array{google?: array{thought_signature: string}|null}}
*/
public function toArray(): array
{
return [
$extraContentArray = $this->extra_content?->toArray();

return array_filter([
'id' => $this->id,
'type' => $this->type,
'function' => $this->function->toArray(),
];
'extra_content' => empty($extraContentArray) ? null : $extraContentArray,
], fn ($value) => $value !== null);
}
}
32 changes: 32 additions & 0 deletions src/Responses/Chat/CreateResponseToolCallExtraContent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace OpenAI\Responses\Chat;

final class CreateResponseToolCallExtraContent
{
private function __construct(
public readonly ?CreateResponseToolCallExtraContentGoogle $google,
) {}

/**
* @param array{google?: array{thought_signature: string}} $attributes
*/
public static function from(array $attributes): self
{
return new self(
isset($attributes['google']) ? CreateResponseToolCallExtraContentGoogle::from($attributes['google']) : null
);
}

/**
* @return array{google?: array{thought_signature: string}|null}
*/
public function toArray(): array
{
return array_filter([
'google' => $this->google?->toArray(),
], fn ($value) => $value !== null);
}
}
32 changes: 32 additions & 0 deletions src/Responses/Chat/CreateResponseToolCallExtraContentGoogle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace OpenAI\Responses\Chat;

final class CreateResponseToolCallExtraContentGoogle
{
private function __construct(
public readonly string $thought_signature,
) {}

/**
* @param array{thought_signature?: string} $attributes
*/
public static function from(array $attributes): self
{
return new self(
$attributes['thought_signature'] ?? '',
);
}

/**
* @return array{thought_signature: string}
*/
public function toArray(): array
{
return [
'thought_signature' => $this->thought_signature,
];
}
}
Loading