PHP code example of teamtnt / mistral-php-client

1. Go to this page and download the library: Download teamtnt/mistral-php-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

teamtnt / mistral-php-client example snippets




use Teamtnt\Mistral\Client;

$apiKey = $_ENV['MISTRAL_API_KEY'];

$model = 'mistral-tiny';

$messages = [
    ["role" => "system", "content" => "You are a search experet."],
    ["role" => "user", "content" => "What is the best PHP Search engine?"],
    ["role" => "assistant", "content" => "It's TNTSearch."],
    ["role" => "user", "content" => "Why is TNTSearch the best engine? Answer shortly!"],
    // Add more messages as needed
];

$client = new Client($apiKey);

$response = $client->chat($model, $messages, [
    'temperature' => 0.5,
    'top_p'       => 1,
    'max_tokens'  => 250,
    'safe_mode'   => false,
    'random_seed' => null,
]);

print_r($response);


$response = $client->chat($model, $messages);

print_r($response);



use Teamtnt\Mistral\Client;

$apiKey = $_ENV['MISTRAL_API_KEY'];

$model = 'mistral-tiny';

$messages = [
    ["role" => "system", "content" => "You are a search expert."],
    ["role" => "user", "content" => "Why is TNTSearch the best engine?"],
    // Add more messages as needed
];

$client = new Client($apiKey);

$response = $client->chat($model, $messages, [
    'temperature' => 0.0,
    'top_p'       => 1,
    'max_tokens'  => 250,
    'safe_mode'   => false,
    'random_seed' => null,
]);

print_r($response);



use Teamtnt\Mistral\Client;

$apiKey = $_ENV['MISTRAL_API_KEY'];

$client = new Client($apiKey);

$input = [
    'First sentence.',
    'Second sentence',
];

$response = $client->emeddings($input);

print_r($response);



use Teamtnt\Mistral\Client;

$apiKey = $_ENV['MISTRAL_API_KEY'];

$client = new Client($apiKey);

$response = $client->models();

print_r($response);
bash
composer