Skip to content

Commit

Permalink
Merge pull request #14 from GeraudBourdin/main
Browse files Browse the repository at this point in the history
Add response_format json.
  • Loading branch information
GeraudBourdin authored Apr 24, 2024
2 parents 5b86271 + 6183243 commit b488fec
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/MistralClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class MistralClient
const string TOOL_CHOICE_AUTO = 'auto';
const string TOOL_CHOICE_NONE = 'none';

const int RESPONSE_FORMAT_JSON = 0;

const array RETRY_STATUS_CODES = [
429,
500 => GenericRetryStrategy::IDEMPOTENT_METHODS,
Expand Down Expand Up @@ -178,8 +180,8 @@ protected function makeChatCompletionRequest(Messages $messages, array $params,
}

if (isset($params['presence_penalty']) && is_numeric(
$params['presence_penalty']
) && $params['presence_penalty'] >= -2 && $params['presence_penalty'] <= 2) {
$params['presence_penalty']
) && $params['presence_penalty'] >= -2 && $params['presence_penalty'] <= 2) {
$return['presence_penalty'] = (float)$params['presence_penalty'];
}

Expand Down Expand Up @@ -214,6 +216,12 @@ protected function makeChatCompletionRequest(Messages $messages, array $params,
$return['guided_json'] = json_encode($params['guided_json']);
}

if(isset($params['response_format']) && $params['response_format'] === self::RESPONSE_FORMAT_JSON) {
$return['response_format'] = [
'type' => 'json_object'
];
}

return $return;
}

Expand Down

0 comments on commit b488fec

Please sign in to comment.