From 64edbc8177cc98966fa74943027a3a267e969517 Mon Sep 17 00:00:00 2001 From: dirk Date: Fri, 12 Sep 2025 15:35:27 +0200 Subject: [PATCH 1/4] catch error with wrong model --- examples/.env | 1 + examples/composer.json | 2 -- examples/ollama/chat-llama.php | 13 ++++++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/examples/.env b/examples/.env index 5c1fdc0b4..234a83fde 100644 --- a/examples/.env +++ b/examples/.env @@ -17,6 +17,7 @@ REPLICATE_API_KEY= # For using Ollama OLLAMA_HOST_URL= +OLLAMA_MODEL= # For using GPT on Azure AZURE_OPENAI_BASEURL= diff --git a/examples/composer.json b/examples/composer.json index c5c6a9e35..df2928a68 100644 --- a/examples/composer.json +++ b/examples/composer.json @@ -6,12 +6,10 @@ "require": { "php": ">=8.2", "ext-pdo": "*", - "async-aws/bedrock-runtime": "^1.1", "codewithkyrian/chromadb-php": "^0.4.0", "codewithkyrian/transformers": "^0.6.1", "doctrine/dbal": "^3.3 || ^4.0", "google/auth": "^1.47", - "mongodb/mongodb": "^2.1", "mrmysql/youtube-transcript": "^0.0.5", "php-http/discovery": "^1.20", "probots-io/pinecone-php": "^1.0", diff --git a/examples/ollama/chat-llama.php b/examples/ollama/chat-llama.php index 394d815c5..419acffd6 100644 --- a/examples/ollama/chat-llama.php +++ b/examples/ollama/chat-llama.php @@ -18,13 +18,20 @@ require_once dirname(__DIR__).'/bootstrap.php'; $platform = PlatformFactory::create(env('OLLAMA_HOST_URL'), http_client()); -$model = new Ollama(); +$ollamaModel = !empty($_SERVER['OLLAMA_MODEL']) ? $_SERVER['OLLAMA_MODEL'] : ''; +$model = new Ollama($ollamaModel); $agent = new Agent($platform, $model, logger: logger()); $messages = new MessageBag( Message::forSystem('You are a helpful assistant.'), Message::ofUser('Tina has one brother and one sister. How many sisters do Tina\'s siblings have?'), ); -$result = $agent->call($messages); -echo $result->getContent().\PHP_EOL; +try { + $result = $agent->call($messages); + $response = $result->getContent().\PHP_EOL; +} catch(InvalidArgumentException $e) { + $response = $e->getMessage() . "\nMaybe use a different model?\n"; +} + +echo $response; From 80a7e0369928f8fa7464c0e5bc5963e97d1cf21b Mon Sep 17 00:00:00 2001 From: dirk Date: Fri, 12 Sep 2025 15:38:17 +0200 Subject: [PATCH 2/4] catch error with wrong model --- examples/composer.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/composer.json b/examples/composer.json index df2928a68..c5c6a9e35 100644 --- a/examples/composer.json +++ b/examples/composer.json @@ -6,10 +6,12 @@ "require": { "php": ">=8.2", "ext-pdo": "*", + "async-aws/bedrock-runtime": "^1.1", "codewithkyrian/chromadb-php": "^0.4.0", "codewithkyrian/transformers": "^0.6.1", "doctrine/dbal": "^3.3 || ^4.0", "google/auth": "^1.47", + "mongodb/mongodb": "^2.1", "mrmysql/youtube-transcript": "^0.0.5", "php-http/discovery": "^1.20", "probots-io/pinecone-php": "^1.0", From 30aed96be4978bef976f4164cc54437a04d43c2c Mon Sep 17 00:00:00 2001 From: Dirk Ollmetzer Date: Fri, 12 Sep 2025 16:01:05 +0200 Subject: [PATCH 3/4] Update examples/ollama/chat-llama.php Co-authored-by: Oskar Stark --- examples/ollama/chat-llama.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ollama/chat-llama.php b/examples/ollama/chat-llama.php index 419acffd6..aa6a9cd9c 100644 --- a/examples/ollama/chat-llama.php +++ b/examples/ollama/chat-llama.php @@ -18,7 +18,7 @@ require_once dirname(__DIR__).'/bootstrap.php'; $platform = PlatformFactory::create(env('OLLAMA_HOST_URL'), http_client()); -$ollamaModel = !empty($_SERVER['OLLAMA_MODEL']) ? $_SERVER['OLLAMA_MODEL'] : ''; +$ollamaModel = $_SERVER['OLLAMA_MODEL'] ?? ''; $model = new Ollama($ollamaModel); $agent = new Agent($platform, $model, logger: logger()); From 2caf3de20cc46f33a564b915ad4844e55307d461 Mon Sep 17 00:00:00 2001 From: Dirk Ollmetzer Date: Fri, 12 Sep 2025 16:02:04 +0200 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: Oskar Stark --- examples/ollama/chat-llama.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/ollama/chat-llama.php b/examples/ollama/chat-llama.php index aa6a9cd9c..265313928 100644 --- a/examples/ollama/chat-llama.php +++ b/examples/ollama/chat-llama.php @@ -29,9 +29,9 @@ try { $result = $agent->call($messages); - $response = $result->getContent().\PHP_EOL; + echo $result->getContent().\PHP_EOL; } catch(InvalidArgumentException $e) { - $response = $e->getMessage() . "\nMaybe use a different model?\n"; + echo $e->getMessage() . "\nMaybe use a different model?\n"; } echo $response;