Add litellm iterations

This commit is contained in:
Víctor Mayoral Vilches 2025-03-16 21:01:26 +01:00
parent 9bdff00971
commit 5c551efb23
3 changed files with 52 additions and 1 deletions

View File

@ -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
```

View File

@ -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.

View File

@ -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)