Skip to content

Commit 598ab94

Browse files
committed
Extract yield_and_clear_tasks method
1 parent fc324b7 commit 598ab94

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

samples-v2/openai_agents/activity_call_tracker.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,9 @@ def call_activity(self, activity_name, input: str):
2525
result_json = completed_tasks[self.activities_called - 1].Result
2626
result = json.loads(result_json)
2727
return result
28+
29+
def yield_and_clear_tasks(self):
30+
"""Yield all accumulated tasks and clear the tasks list."""
31+
for task in self.tasks_to_yield:
32+
yield task
33+
self.tasks_to_yield.clear()

samples-v2/openai_agents/function_app.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,10 @@ def basic_hello_world_orchestrator(context):
3131
result = main()
3232
return result
3333
except YieldException as e:
34-
for task in activity_call_tracker.tasks_to_yield:
35-
yield task
36-
activity_call_tracker.tasks_to_yield.clear()
34+
yield from activity_call_tracker.yield_and_clear_tasks()
3735
yield e.task
3836
finally:
39-
for task in activity_call_tracker.tasks_to_yield:
40-
yield task
41-
activity_call_tracker.tasks_to_yield.clear()
37+
yield from activity_call_tracker.yield_and_clear_tasks()
4238

4339

4440
@app.activity_trigger(input_name="input")

0 commit comments

Comments
 (0)