teamtnt / mistral-php-client

A PHP client for interacting with the Mistral API
MIT License
3 stars 0 forks source link

->chat not working #1

Open oresteafrica opened 5 months ago

oresteafrica commented 5 months ago

While the following is working correctly: require_once 'mistral-php-client-main/vendor/autoload.php'; use Teamtnt\Mistral\Client; $iniArray = parse_ini_file('php_client.ini'); $mistralApiKey = $iniArray['mistralApiKey']; $clientMistral = new Client($mistralApiKey); $question = 'Models'; $response = $clientMistral->models(); $answer = '

' . print_r($response,true) . '
' ;

results in:

Question: Models

Answer:

Array ( [0] => open-mistral-7b [1] => mistral-tiny-2312 [2] => mistral-tiny [3] => open-mixtral-8x7b [4] => open-mixtral-8x22b [5] => open-mixtral-8x22b-2404 [6] => mistral-small-2312 [7] => mistral-small [8] => mistral-small-2402 [9] => mistral-small-latest [10] => mistral-medium-latest [11] => mistral-medium-2312 [12] => mistral-medium [13] => mistral-large-latest [14] => mistral-large-2402 [15] => mistral-embed )

which seems to be correct.

The following:

$model = 'mistral-tiny'; $question = 'Qu\'est-ce que l\'herméneutique ?'; $messages = [ ['role' => 'system', 'content' => 'Répondre en français'], ['role' => 'user', 'content' => $question] ]; $response = $clientMistral->chat($model,$messages);

results in:

Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: POST https://api.mistral.ai/v1/chat/completions resulted in a 422 Unprocessable Entity response: {"object":"error","message":{"detail":[{"type":"extra_forbidden","loc":["body","safe_mode"],"msg":"Extra inputs are not (truncated...) in /var/www/html/mistral/php-client/mistral-php-client-main/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113 Stack trace: #0 /var/www/html/mistral/php-client/mistral-php-client-main/vendor/guzzlehttp/guzzle/src/Middleware.php(72): GuzzleHttp\Exception\RequestException::create() #1 /var/www/html/mistral/php-client/mistral-php-client-main/vendor/guzzlehttp/promises/src/Promise.php(209): GuzzleHttp\Middleware::GuzzleHttp{closure}() #2 /var/www/html/mistral/php-client/mistral-php-client-main/vendor/guzzlehttp/promises/src/Promise.php(158): GuzzleHttp\Promise\Promise::callHandler() #3 /var/www/html/mistral/php-client/mistral-php-client-main/vendor/guzzlehttp/promises/src/TaskQueue.php(52): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise{closure}() #4 /var/www/html/mistral/php-client/mistral-php-client-main/vendor/guzzlehttp/promises/src/Promise.php(251): GuzzleHttp\Promise\TaskQueue->run() #5 /var/www/html/mistral/php-client/mistral-php-client-main/vendor/guzzlehttp/promises/src/Promise.php(227): GuzzleHttp\Promise\Promise->invokeWaitFn() #6 /var/www/html/mistral/php-client/mistral-php-client-main/vendor/guzzlehttp/promises/src/Promise.php(272): GuzzleHttp\Promise\Promise->waitIfPending() #7 /var/www/html/mistral/php-client/mistral-php-client-main/vendor/guzzlehttp/promises/src/Promise.php(229): GuzzleHttp\Promise\Promise->invokeWaitList() #8 /var/www/html/mistral/php-client/mistral-php-client-main/vendor/guzzlehttp/promises/src/Promise.php(69): GuzzleHttp\Promise\Promise->waitIfPending() #9 /var/www/html/mistral/php-client/mistral-php-client-main/vendor/guzzlehttp/guzzle/src/Client.php(189): GuzzleHttp\Promise\Promise->wait() #10 /var/www/html/mistral/php-client/mistral-php-client-main/vendor/guzzlehttp/guzzle/src/ClientTrait.php(95): GuzzleHttp\Client->request() #11 /var/www/html/mistral/php-client/mistral-php-client-main/src/Client.php(64): GuzzleHttp\Client->post() #12 /var/www/html/mistral/php-client/php_client.php(50): Teamtnt\Mistral\Client->chat() #13 {main} thrown in /var/www/html/mistral/php-client/mistral-php-client-main/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 113

I tried with other models with the same results. Why the above error despite the first interaction worked?

nticaric commented 5 months ago

Have you tried using double quotes, like $question = "Qu'est-ce que l'herméneutique ?";