-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add LiteLLM support in line with AsyncOpenAI and with reproducible examples #318
Open
vmayoral
wants to merge
9
commits into
openai:main
Choose a base branch
from
vmayoral:litellm
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+86
−1
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9bdff00
Add Ollama example
vmayoral 5c551ef
Add litellm iterations
vmayoral 012f1ca
Add litellm support
vmayoral cec4dbe
Add some additional bits to README.md
vmayoral 6d198e8
Merge branch 'main' of https://github.com/openai/openai-agents-python
vmayoral b47498d
Update openai library version to avoid version-related issue
vmayoral bf8c8d9
Restore structure and place litellm integraton under model_providers
vmayoral 0113e90
Remove independent and isolated model tests
vmayoral 3344d31
Fix error in example path
vmayoral File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import os | ||
from dotenv import load_dotenv | ||
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 | ||
|
||
# Load environment variables from .env file | ||
load_dotenv() | ||
|
||
external_client = AsyncOpenAI( | ||
base_url = os.getenv('LITELLM_BASE_URL', 'http://localhost:4000'), | ||
api_key=os.getenv('LITELLM_API_KEY', 'key')) | ||
|
||
set_default_openai_client(external_client) | ||
set_tracing_disabled(True) | ||
|
||
llm_model=os.getenv('LLM_MODEL', 'gpt-4o') | ||
# llm_model=os.getenv('LLM_MODEL', 'claude-3-7') | ||
# llm_model=os.getenv('LLM_MODEL', 'qwen2.5:14b') | ||
|
||
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
model_list: | ||
- model_name: gpt-4o | ||
litellm_params: | ||
model: gpt-4o | ||
api_key: "os.environ/OPENAI_API_KEY" | ||
api_base: https://api.openai.com/v1 | ||
- model_name: claude-3-7 | ||
litellm_params: | ||
model: claude-3-7-sonnet-20250219 | ||
api_key: "os.environ/ANTHROPIC_API_KEY" # does os.getenv("ANTHROPIC_API_KEY") | ||
base_url: 'https://api.anthropic.com' | ||
- model_name: qwen2.5:14b | ||
litellm_params: | ||
model: ollama/qwen2.5:14b | ||
api_base: http://localhost:8000 | ||
api_key: "os.environ/OLLAMA" | ||
|
||
litellm_settings: # module level litellm settings - https://github.com/BerriAI/litellm/blob/main/litellm/__init__.py | ||
drop_params: True | ||
# set_verbose: True | ||
|
||
general_settings: | ||
port: 4000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ requires-python = ">=3.9" | |
license = "MIT" | ||
authors = [{ name = "OpenAI", email = "[email protected]" }] | ||
dependencies = [ | ||
"openai>=1.66.5", | ||
"openai>=1.68.2", | ||
"pydantic>=2.10, <3", | ||
"griffe>=1.5.6, <2", | ||
"typing-extensions>=4.12.2, <5", | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should not be part of the PR, as it has nothing to do with the added example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my local testing, it was neccessary, otherwise it wouldn't work with
1.66.5
.Happy to change it though if that gets this through.