diff --git a/src/Responses/Chat/CreateResponseToolCall.php b/src/Responses/Chat/CreateResponseToolCall.php index b14a0776..64ba656f 100644 --- a/src/Responses/Chat/CreateResponseToolCall.php +++ b/src/Responses/Chat/CreateResponseToolCall.php @@ -10,10 +10,11 @@ private function __construct( public readonly string $id, public readonly string $type, public readonly CreateResponseToolCallFunction $function, + public readonly array $extraContent ) {} /** - * @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|null} $attributes */ public static function from(array $attributes): self { @@ -21,11 +22,12 @@ public static function from(array $attributes): self $attributes['id'], $attributes['type'], CreateResponseToolCallFunction::from($attributes['function']), + $attributes['extra_content'] ?? [] ); } /** - * @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} */ public function toArray(): array { @@ -33,6 +35,7 @@ public function toArray(): array 'id' => $this->id, 'type' => $this->type, 'function' => $this->function->toArray(), + 'extra_content' => $this->extraContent, ]; } } diff --git a/src/Transporters/HttpTransporter.php b/src/Transporters/HttpTransporter.php index 0b1d8af6..701f458f 100644 --- a/src/Transporters/HttpTransporter.php +++ b/src/Transporters/HttpTransporter.php @@ -175,8 +175,8 @@ private function throwIfJsonError(ResponseInterface $response, string|ResponseIn /** @var array{error?: string|array{message: string|array, type: string, code: string}} $data */ $data = json_decode($contents, true, flags: JSON_THROW_ON_ERROR); - if (isset($data['error'])) { - throw new ErrorException($data['error'], $response); + if (isset($data['error']) || isset($data[0]['error'])) { + throw new ErrorException($data['error'] ?? $data[0]['error'], $response); } } catch (JsonException $jsonException) { throw new UnserializableResponse($jsonException, $response);