From 536d7826d550ed1e295ebeca45386c6f6fd00420 Mon Sep 17 00:00:00 2001 From: Dmitry Pimenov <dmitry@openai.com> Date: Wed, 12 Mar 2025 17:24:35 -0700 Subject: [PATCH 1/3] added a Jupyter example to clarify how to use the SDK with an existing event loop --- README.md | 4 +++- examples/basic/hello_world_jupyter.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 examples/basic/hello_world_jupyter.py diff --git a/README.md b/README.md index d3f25fa7..32984bc7 100644 --- a/README.md +++ b/README.md @@ -47,9 +47,11 @@ print(result.final_output) (_If running this, ensure you set the `OPENAI_API_KEY` environment variable_) +(_For Jupyter notebook users, see [hello_world_jupyter.py](examples/basic/hello_world_jupyter.py)_) + ## Handoffs example -```py +```python from agents import Agent, Runner import asyncio diff --git a/examples/basic/hello_world_jupyter.py b/examples/basic/hello_world_jupyter.py new file mode 100644 index 00000000..6b0f2759 --- /dev/null +++ b/examples/basic/hello_world_jupyter.py @@ -0,0 +1,11 @@ +from agents import Agent, Runner + +agent = Agent(name="Assistant", instructions="You are a helpful assistant") + +# Intended for Jupyter notebooks where there's an existing event loop +result = await Runner.run(agent, "Write a haiku about recursion in programming.") +print(result.final_output) + +# Code within code loops, +# Infinite mirrors reflect— +# Logic folds on self. From 65546703cbd768b411972cc06e42116aea059a5a Mon Sep 17 00:00:00 2001 From: Dmitry Pimenov <dmitry@openai.com> Date: Wed, 12 Mar 2025 17:28:44 -0700 Subject: [PATCH 2/3] fixing lint issues --- examples/basic/hello_world_jupyter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/basic/hello_world_jupyter.py b/examples/basic/hello_world_jupyter.py index 6b0f2759..5c1e3029 100644 --- a/examples/basic/hello_world_jupyter.py +++ b/examples/basic/hello_world_jupyter.py @@ -3,9 +3,9 @@ agent = Agent(name="Assistant", instructions="You are a helpful assistant") # Intended for Jupyter notebooks where there's an existing event loop -result = await Runner.run(agent, "Write a haiku about recursion in programming.") +result = await Runner.run(agent, "Write a haiku about recursion in programming.") # noqa: F704 print(result.final_output) -# Code within code loops, -# Infinite mirrors reflect— +# Code within code loops, +# Infinite mirrors reflect— # Logic folds on self. From 26f9cb42de9791ba43ee961722909b342f331d9d Mon Sep 17 00:00:00 2001 From: Dmitry Pimenov <dmitry@openai.com> Date: Wed, 12 Mar 2025 17:30:59 -0700 Subject: [PATCH 3/3] fixing mypy error --- examples/basic/hello_world_jupyter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/basic/hello_world_jupyter.py b/examples/basic/hello_world_jupyter.py index 5c1e3029..bb8f14c0 100644 --- a/examples/basic/hello_world_jupyter.py +++ b/examples/basic/hello_world_jupyter.py @@ -3,7 +3,7 @@ agent = Agent(name="Assistant", instructions="You are a helpful assistant") # Intended for Jupyter notebooks where there's an existing event loop -result = await Runner.run(agent, "Write a haiku about recursion in programming.") # noqa: F704 +result = await Runner.run(agent, "Write a haiku about recursion in programming.") # type: ignore[top-level-await] # noqa: F704 print(result.final_output) # Code within code loops,