Skip to content

Commit 64edbc8

Browse files
committed
catch error with wrong model
1 parent 2cb277b commit 64edbc8

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

examples/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ REPLICATE_API_KEY=
1717

1818
# For using Ollama
1919
OLLAMA_HOST_URL=
20+
OLLAMA_MODEL=
2021

2122
# For using GPT on Azure
2223
AZURE_OPENAI_BASEURL=

examples/composer.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
"require": {
77
"php": ">=8.2",
88
"ext-pdo": "*",
9-
"async-aws/bedrock-runtime": "^1.1",
109
"codewithkyrian/chromadb-php": "^0.4.0",
1110
"codewithkyrian/transformers": "^0.6.1",
1211
"doctrine/dbal": "^3.3 || ^4.0",
1312
"google/auth": "^1.47",
14-
"mongodb/mongodb": "^2.1",
1513
"mrmysql/youtube-transcript": "^0.0.5",
1614
"php-http/discovery": "^1.20",
1715
"probots-io/pinecone-php": "^1.0",

examples/ollama/chat-llama.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,20 @@
1818
require_once dirname(__DIR__).'/bootstrap.php';
1919

2020
$platform = PlatformFactory::create(env('OLLAMA_HOST_URL'), http_client());
21-
$model = new Ollama();
21+
$ollamaModel = !empty($_SERVER['OLLAMA_MODEL']) ? $_SERVER['OLLAMA_MODEL'] : '';
22+
$model = new Ollama($ollamaModel);
2223

2324
$agent = new Agent($platform, $model, logger: logger());
2425
$messages = new MessageBag(
2526
Message::forSystem('You are a helpful assistant.'),
2627
Message::ofUser('Tina has one brother and one sister. How many sisters do Tina\'s siblings have?'),
2728
);
28-
$result = $agent->call($messages);
2929

30-
echo $result->getContent().\PHP_EOL;
30+
try {
31+
$result = $agent->call($messages);
32+
$response = $result->getContent().\PHP_EOL;
33+
} catch(InvalidArgumentException $e) {
34+
$response = $e->getMessage() . "\nMaybe use a different model?\n";
35+
}
36+
37+
echo $response;

0 commit comments

Comments
 (0)