-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresponses-openai-open-router.py
More file actions
38 lines (32 loc) · 1.01 KB
/
responses-openai-open-router.py
File metadata and controls
38 lines (32 loc) · 1.01 KB
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
# https://openrouter.ai/docs/api/reference/responses/overview
from agents import Agent, ModelSettings, Runner, function_tool, OpenAIResponsesModel, set_tracing_disabled
from agents.extensions.models.litellm_model import LitellmModel
from openai.types.shared import Reasoning
from openai import AsyncOpenAI
import os
set_tracing_disabled(disabled=True)
client = AsyncOpenAI(
base_url="https://openrouter.ai/api/v1/",
api_key=os.getenv("OPENROUTER_API_KEY"),
)
model = OpenAIResponsesModel(
model="openai/gpt-oss-120b",
openai_client=client
)
@function_tool
def echo_tool(input: str) -> str:
print("called echo_tool !!!")
return input
agent = Agent(
name="Assistant",
instructions="You are a helpful assistant",
model=model,
tools=[echo_tool],
model_settings=ModelSettings(reasoning=Reasoning(effort="low"))
)
result = Runner.run_sync(
agent, "Can you use the echo_tool to echo the message 'Hello, world!"
)
print(result.final_output)
print("------")
print(result.to_input_list())