-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathlitellm_auto.py
41 lines (28 loc) · 1.05 KB
/
litellm_auto.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from __future__ import annotations
import asyncio
from agents import Agent, Runner, function_tool, set_tracing_disabled
"""This example uses the built-in support for LiteLLM. To use this, ensure you have the
ANTHROPIC_API_KEY environment variable set.
"""
set_tracing_disabled(disabled=True)
@function_tool
def get_weather(city: str):
print(f"[debug] getting weather for {city}")
return f"The weather in {city} is sunny."
async def main():
agent = Agent(
name="Assistant",
instructions="You only respond in haikus.",
# We prefix with litellm/ to tell the Runner to use the LitellmModel
model="litellm/anthropic/claude-3-5-sonnet-20240620",
tools=[get_weather],
)
result = await Runner.run(agent, "What's the weather in Tokyo?")
print(result.final_output)
if __name__ == "__main__":
import os
if os.getenv("ANTHROPIC_API_KEY") is None:
raise ValueError(
"ANTHROPIC_API_KEY is not set. Please set it the environment variable and try again."
)
asyncio.run(main())