Skip to content

Commit 91a1784

Browse files
committed
Example openai responses for synchronous and asynchronous calls
1 parent 2b28a51 commit 91a1784

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# To run this file from project root: AGENTOPS_LOG_LEVEL=debug uv run examples/openai_responses/sync_and_async.py
2+
import asyncio
3+
from dotenv import load_dotenv
4+
5+
load_dotenv()
6+
7+
from openai import OpenAI, AsyncOpenAI
8+
import agentops
9+
10+
11+
def sync_responses_request():
12+
client = OpenAI()
13+
response = client.responses.create(
14+
model="gpt-4o",
15+
input="Explain the concept of synchronous Python in one sentence.",
16+
)
17+
return response
18+
19+
20+
async def async_responses_request():
21+
client = AsyncOpenAI()
22+
response = await client.responses.create(
23+
model="gpt-4o",
24+
input="Explain the concept of async/await in Python in one sentence.",
25+
stream=False,
26+
)
27+
return response
28+
29+
30+
async def main():
31+
agentops.init()
32+
33+
# Synchronous request
34+
sync_response = sync_responses_request()
35+
print(f"Synchronous Response:\n {sync_response.output_text}")
36+
37+
# Asynchronous request
38+
async_response = await async_responses_request()
39+
print(f"Asynchronous Response:\n {async_response.output_text}")
40+
41+
42+
if __name__ == "__main__":
43+
asyncio.run(main())

0 commit comments

Comments
 (0)