Skip to content

Commit 4c436b7

Browse files
authored
Add a simple gpt-oss example (#1440)
This pull request adds a simple gpt-oss example app
1 parent e3b4856 commit 4c436b7

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

examples/basic/hello_world_gpt_oss.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import asyncio
2+
import logging
3+
4+
from openai import AsyncOpenAI
5+
6+
from agents import Agent, OpenAIChatCompletionsModel, Runner, set_tracing_disabled
7+
8+
set_tracing_disabled(True)
9+
logging.basicConfig(level=logging.DEBUG)
10+
11+
# This is an example of how to use gpt-oss with Ollama.
12+
# Refer to https://cookbook.openai.com/articles/gpt-oss/run-locally-ollama for more details.
13+
# If you prefer using LM Studio, refer to https://cookbook.openai.com/articles/gpt-oss/run-locally-lmstudio
14+
gpt_oss_model = OpenAIChatCompletionsModel(
15+
model="gpt-oss:20b",
16+
openai_client=AsyncOpenAI(
17+
base_url="http://localhost:11434/v1",
18+
api_key="ollama",
19+
),
20+
)
21+
22+
23+
async def main():
24+
# Note that using a custom outputType for an agent may not work well with gpt-oss models.
25+
# Consider going with the default "text" outputType.
26+
# See also: https://github.com/openai/openai-agents-python/issues/1414
27+
agent = Agent(
28+
name="Assistant",
29+
instructions="You're a helpful assistant. You provide a concise answer to the user's question.",
30+
model=gpt_oss_model,
31+
)
32+
33+
result = await Runner.run(agent, "Tell me about recursion in programming.")
34+
print(result.final_output)
35+
36+
37+
if __name__ == "__main__":
38+
asyncio.run(main())

0 commit comments

Comments
 (0)