diff --git a/composer.json b/composer.json index 798934f..7eecaa0 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,7 @@ }, "require": { "symfony/http-client": "^6.4 || ^7.0", - "amphp/http-client": "^4.2.1" + "amphp/http-client": "^4.2.1", + "knplabs/php-json-schema": "^0.1.0" } } diff --git a/src/MistralClient.php b/src/MistralClient.php index dc6322c..975c1c1 100644 --- a/src/MistralClient.php +++ b/src/MistralClient.php @@ -5,6 +5,7 @@ ini_set('default_socket_timeout', '-1'); use Generator; +use KnpLabs\JsonSchema\ObjectSchema; use Symfony\Component\HttpClient\HttpClient; use Symfony\Component\HttpClient\Retry\GenericRetryStrategy; use Symfony\Component\HttpClient\RetryableHttpClient; @@ -207,6 +208,9 @@ protected function makeChatCompletionRequest(Messages $messages, array $params, } if (isset($params['guided_json']) && is_object($params['guided_json'])) { + if ($params['guided_json'] instanceof ObjectSchema) { + $params['guided_json'] = $params['guided_json']->jsonSerialize(); + } $return['guided_json'] = json_encode($params['guided_json']); }