From 5292d15ba64828ef3e5f19e8e2f1957b346a9c78 Mon Sep 17 00:00:00 2001 From: Christopher Hertel Date: Wed, 17 Sep 2025 00:14:28 +0200 Subject: [PATCH] Consistency about Ollama model config via env, and wrap up docs. --- examples/.env | 5 +++-- examples/ollama/{Ollama.md => README.md} | 18 ++++++++++++------ examples/ollama/chat-llama.php | 2 +- examples/ollama/embeddings.php | 2 +- examples/ollama/indexer.php | 2 +- examples/ollama/rag.php | 4 ++-- examples/ollama/stream.php | 2 +- examples/ollama/structured-output-math.php | 2 +- examples/ollama/toolcall.php | 2 +- 9 files changed, 23 insertions(+), 16 deletions(-) rename examples/ollama/{Ollama.md => README.md} (54%) diff --git a/examples/.env b/examples/.env index 7daf6362d..50b84ea7d 100644 --- a/examples/.env +++ b/examples/.env @@ -16,8 +16,9 @@ VOYAGE_API_KEY= REPLICATE_API_KEY= # For using Ollama -OLLAMA_HOST_URL= -OLLAMA_MODEL= +OLLAMA_HOST_URL=http://localhost:11434 +OLLAMA_LLM=llama3.2 +OLLAMA_EMBEDDINGS=nomic-embed-text # For using GPT on Azure AZURE_OPENAI_BASEURL= diff --git a/examples/ollama/Ollama.md b/examples/ollama/README.md similarity index 54% rename from examples/ollama/Ollama.md rename to examples/ollama/README.md index bc498ebd0..e813693df 100644 --- a/examples/ollama/Ollama.md +++ b/examples/ollama/README.md @@ -11,20 +11,26 @@ To get started with Ollama please check their [Quickstart guide](https://github. To run the examples you will need to download [Llama 3.2](https://ollama.com/library/llama3.2) and [nomic-embed-text](https://ollama.com/library/nomic-embed-text) models. -Once models are downloaded you can run them with +You can do this by running the following commands: ```bash -ollama run +ollama pull llama3.2 +ollama pull nomic-embed-text ``` -for example +Then you can start the Ollama server by running: ```bash -ollama run llama3.2 +ollama serve ``` -#### Configuration -To run Ollama examples you will need to provide a OLLAMA_HOST_URL key in your env.local file. +### Configuration +By default, the examples expect Ollama to be run on `localhost:11434`, but you can customize this in your `.env.local` +file - as well as the models to be used: For example ```bash OLLAMA_HOST_URL=http://localhost:11434 +OLLAMA_LLM=llama3.2 +OLLAMA_EMBEDDINGS=nomic-embed-text ``` + +You can find more models in the [Ollama model library](https://ollama.com/library). diff --git a/examples/ollama/chat-llama.php b/examples/ollama/chat-llama.php index 852e931e4..5a96cb2d9 100644 --- a/examples/ollama/chat-llama.php +++ b/examples/ollama/chat-llama.php @@ -17,7 +17,7 @@ require_once dirname(__DIR__).'/bootstrap.php'; $platform = PlatformFactory::create(env('OLLAMA_HOST_URL'), http_client()); -$model = new Ollama($_SERVER['OLLAMA_MODEL'] ?? ''); +$model = new Ollama(env('OLLAMA_LLM')); $messages = new MessageBag( Message::forSystem('You are a helpful assistant.'), diff --git a/examples/ollama/embeddings.php b/examples/ollama/embeddings.php index 822704d8c..ac8d4ca95 100644 --- a/examples/ollama/embeddings.php +++ b/examples/ollama/embeddings.php @@ -16,7 +16,7 @@ $platform = PlatformFactory::create(env('OLLAMA_HOST_URL'), http_client()); -$response = $platform->invoke(new Ollama(Ollama::NOMIC_EMBED_TEXT), <<invoke(new Ollama(env('OLLAMA_EMBEDDINGS')), <<index($documents); -$model = new Ollama(); +$model = new Ollama(env('OLLAMA_LLM')); $similaritySearch = new SimilaritySearch($vectorizer, $store); $toolbox = new Toolbox([$similaritySearch], logger: logger()); diff --git a/examples/ollama/stream.php b/examples/ollama/stream.php index e1b977cbf..605a0043a 100644 --- a/examples/ollama/stream.php +++ b/examples/ollama/stream.php @@ -17,7 +17,7 @@ require_once dirname(__DIR__).'/bootstrap.php'; $platform = PlatformFactory::create(env('OLLAMA_HOST_URL'), http_client()); -$model = new Ollama(Ollama::LLAMA_3_2); +$model = new Ollama(env('OLLAMA_LLM')); $messages = new MessageBag( Message::forSystem('You are a helpful assistant.'), diff --git a/examples/ollama/structured-output-math.php b/examples/ollama/structured-output-math.php index 8953ff5b0..a3d4fdb8b 100644 --- a/examples/ollama/structured-output-math.php +++ b/examples/ollama/structured-output-math.php @@ -20,7 +20,7 @@ require_once dirname(__DIR__).'/bootstrap.php'; $platform = PlatformFactory::create(env('OLLAMA_HOST_URL'), http_client()); -$model = new Ollama(Ollama::LLAMA_3_2); +$model = new Ollama(env('OLLAMA_LLM')); $processor = new AgentProcessor(); $agent = new Agent($platform, $model, [$processor], [$processor], logger: logger()); diff --git a/examples/ollama/toolcall.php b/examples/ollama/toolcall.php index 9abccb8dc..2a012cad2 100644 --- a/examples/ollama/toolcall.php +++ b/examples/ollama/toolcall.php @@ -21,7 +21,7 @@ require_once dirname(__DIR__).'/bootstrap.php'; $platform = PlatformFactory::create(env('OLLAMA_HOST_URL'), http_client()); -$model = new Ollama(Ollama::LLAMA_3_2); +$model = new Ollama(env('OLLAMA_LLM')); $toolbox = new Toolbox([new Clock()], logger: logger()); $processor = new AgentProcessor($toolbox);