File tree Expand file tree Collapse file tree
examples/openai_responses Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 ())
You can’t perform that action at this time.
0 commit comments