Skip to content

Commit

Permalink
Merge pull request #13 from GeraudBourdin/main
Browse files Browse the repository at this point in the history
Enable KnpLabs\JsonSchema\ObjectSchema in guided_json
  • Loading branch information
GeraudBourdin authored Apr 15, 2024
2 parents 226ec91 + 154dc26 commit 5b86271
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
4 changes: 4 additions & 0 deletions src/MistralClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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']);
}

Expand Down

0 comments on commit 5b86271

Please sign in to comment.