From 2cc95d9a00b01eff3e620fa72f37a51e1610f469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mayoral=20Vilches?= Date: Fri, 14 Mar 2025 15:26:58 +0100 Subject: [PATCH] Add Ollama example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: VĂ­ctor Mayoral Vilches --- examples/agent_patterns/ollama.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 examples/agent_patterns/ollama.py diff --git a/examples/agent_patterns/ollama.py b/examples/agent_patterns/ollama.py new file mode 100644 index 00000000..76425e67 --- /dev/null +++ b/examples/agent_patterns/ollama.py @@ -0,0 +1,28 @@ +from openai import AsyncOpenAI +from agents import OpenAIChatCompletionsModel,Agent,Runner +from agents.model_settings import ModelSettings +from agents import set_default_openai_client, set_tracing_disabled + +external_client = AsyncOpenAI( + base_url = 'http://localhost:8000/v1', + api_key='ollama', # required, but unused +) + +set_default_openai_client(external_client) +set_tracing_disabled(True) + +agent = Agent( + name="Assistant", + instructions="You are a helpful assistant", + model=OpenAIChatCompletionsModel( + model="qwen2.5:14b", + openai_client=external_client, + ) + ) + +result = Runner.run_sync(agent, "Write a haiku about recursion in programming.") +print(result.final_output) + +# Code within the code, +# Functions calling themselves, +# Infinite loop's dance. \ No newline at end of file