-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from GeraudBourdin/timeout
Timeout
- Loading branch information
Showing
2 changed files
with
83 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
||
use Partitech\PhpMistral\MistralClient; | ||
use Partitech\PhpMistral\MistralClientException; | ||
use Partitech\PhpMistral\Messages; | ||
use Symfony\Component\HttpClient\Exception\TransportException; | ||
|
||
// export MISTRAL_API_KEY= | ||
$apiKey = getenv('MISTRAL_API_KEY'); | ||
$client = new MistralClient(apiKey: $apiKey, timeout:0.1); | ||
$messages = new Messages(); | ||
$messages->addUserMessage('What is the best French cheese?'); | ||
|
||
$params = [ | ||
'model' => 'mistral-large-latest', | ||
'temperature' => 0.7, | ||
'top_p' => 1, | ||
'max_tokens' => null, | ||
'safe_prompt' => false, | ||
'random_seed' => null | ||
]; | ||
|
||
try { | ||
foreach ($client->chatStream($messages, $params) as $chunk) { | ||
echo $chunk->getChunk(); | ||
} | ||
} catch (MistralClientException $e) { | ||
echo $e->getMessage(); | ||
exit(1); | ||
} catch (TransportException $e) { | ||
echo 'Idle timeout reached' . PHP_EOL; | ||
|
||
} | ||
|
||
$client->setTimeout(null); | ||
try { | ||
foreach ($client->chatStream($messages, $params) as $chunk) { | ||
echo $chunk->getChunk(); | ||
} | ||
} catch (MistralClientException $e) { | ||
echo $e->getMessage(); | ||
exit(1); | ||
} catch (TransportException $e) { | ||
echo 'Idle timeout reached' . PHP_EOL;; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters