From 5c551efb23f2d902d2e04a0139a40ec4c8988d62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mayoral=20Vilches?= Date: Sun, 16 Mar 2025 21:01:26 +0100 Subject: [PATCH] Add litellm iterations --- README.md | 15 +++++++++++++ examples/agent_patterns/litellm.py | 35 ++++++++++++++++++++++++++++++ examples/agent_patterns/ollama.py | 3 ++- 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 examples/agent_patterns/litellm.py diff --git a/README.md b/README.md index 210f6f4b..ab033a4b 100644 --- a/README.md +++ b/README.md @@ -176,3 +176,18 @@ We'd like to acknowledge the excellent work of the open-source community, especi - [uv](https://github.com/astral-sh/uv) and [ruff](https://github.com/astral-sh/ruff) We're committed to continuing to build the Agents SDK as an open source framework so others in the community can expand on our approach. + + +## LiteLLM Proxy Server integration + +Testing some basic models: +```bash +# qwen2.5:14b +curl -s http://localhost:4000/v1/chat/completions -H "Content-Type: application/json" -d '{"model": "qwen2.5:14b", "messages": [{"role": "user", "content": "Say hi"}], "max_tokens": 10}' | jq + +# claude-3-7 +curl -s http://localhost:4000/v1/chat/completions -H "Content-Type: application/json" -d '{"model": "claude-3-7", "messages": [{"role": "user", "content": "Say hi"}], "max_tokens": 10}' | jq + +# gpt-4o +curl -s http://localhost:4000/v1/chat/completions -H "Content-Type: application/json" -d '{"model": "gpt-4o", "messages": [{"role": "user", "content": "Say hi"}], "max_tokens": 10}' | jq +``` \ No newline at end of file diff --git a/examples/agent_patterns/litellm.py b/examples/agent_patterns/litellm.py new file mode 100644 index 00000000..b58997df --- /dev/null +++ b/examples/agent_patterns/litellm.py @@ -0,0 +1,35 @@ +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:4000', + api_key="cai") + +set_default_openai_client(external_client) +set_tracing_disabled(True) + +# llm_model="qwen2.5:14b" +# llm_model="claude-3-7" +llm_model="gpt-4o" + +# For Qwen models, we need to skip system instructions as they're not supported +instructions = None if "qwen" in llm_model.lower() else "You are a helpful assistant" + +agent = Agent( + name="Assistant", + instructions=instructions, + model=OpenAIChatCompletionsModel( + model=llm_model, + 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 diff --git a/examples/agent_patterns/ollama.py b/examples/agent_patterns/ollama.py index 76425e67..e4247ad6 100644 --- a/examples/agent_patterns/ollama.py +++ b/examples/agent_patterns/ollama.py @@ -18,7 +18,8 @@ agent = Agent( model="qwen2.5:14b", openai_client=external_client, ) - ) +) + result = Runner.run_sync(agent, "Write a haiku about recursion in programming.") print(result.final_output)