Skip to content

Commit b8cb4a3

Browse files
committed
bug #563 [Ollama] Fix example (dollmetzer)
This PR was squashed before being merged into the main branch. Discussion ---------- [Ollama] Fix example As discussed in the hackathon a fix for using different models in ollama (e.g. mistral) Extended .env variables Commits ------- 2caf3de Apply suggestions from code review 30aed96 Update examples/ollama/chat-llama.php 80a7e03 catch error with wrong model 64edbc8 catch error with wrong model
2 parents f1d488b + 2caf3de commit b8cb4a3

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
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/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 = $_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+
echo $result->getContent().\PHP_EOL;
33+
} catch(InvalidArgumentException $e) {
34+
echo $e->getMessage() . "\nMaybe use a different model?\n";
35+
}
36+
37+
echo $response;

0 commit comments

Comments
 (0)