PHP code example of saarnilauri / ai-provider-for-mistral
1. Go to this page and download the library: Download saarnilauri/ai-provider-for-mistral 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/ */
saarnilauri / ai-provider-for-mistral example snippets
// Set your Mistral API key (or use the MISTRAL_API_KEY environment variable)
putenv('MISTRAL_API_KEY=your-api-key');
// Use the provider
$result = AiClient::prompt('Hello, world!')
->usingProvider('mistral')
->generateTextResult();
use WordPress\AiClient\AiClient;
use SaarniLauri\AiProviderForMistral\Provider\ProviderForMistral;
// Register the provider
$registry = AiClient::defaultRegistry();
$registry->registerProvider(ProviderForMistral::class);
// Set your API key
putenv('MISTRAL_API_KEY=your-api-key');
// Generate text
$result = AiClient::prompt('Explain quantum computing')
->usingProvider('mistral')
->generateTextResult();
echo $result->toText();
$result = AiClient::prompt('A red apple on a white background')
->usingProvider('mistral')
->generateImageResult();
// Get the generated image as base64-encoded PNG
$file = $result->getCandidates()[0]->getMessage()->getParts()[0]->getFile();
$binaryData = base64_decode($file->getBase64Data(), true);
file_put_contents('apple.png', $binaryData);
putenv('MISTRAL_API_KEY=your-api-key');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.