Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

->chat not working #1

Open
oresteafrica opened this issue May 4, 2024 · 1 comment
Open

->chat not working #1

oresteafrica opened this issue May 4, 2024 · 1 comment

Comments

@oresteafrica
Copy link

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
Copy link
Contributor

nticaric commented May 5, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants