mirror of
https://github.com/openai/codex.git
synced 2026-04-30 11:21:34 +03:00
python-sdk: show persisted turn items in example 02 (2026-03-13)
Update the sync and async turn-run examples to read the thread after a completed turn and print the persisted item count instead of the empty immediate TurnResult.items list. This makes the example output match the current app-server behavior, where the completed turn payload can have empty items even though the persisted thread turn later contains the generated items. Validation: - python3 sdk/python/examples/02_turn_run/sync.py - python3 sdk/python/examples/02_turn_run/async.py Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
@@ -14,6 +14,11 @@ from codex_app_server import Codex, TextInput
|
||||
with Codex(config=runtime_config()) as codex:
|
||||
thread = codex.thread_start(model="gpt-5.4", config={"model_reasoning_effort": "high"})
|
||||
result = thread.turn(TextInput("Give 3 bullets about SIMD.")).run()
|
||||
persisted = thread.read(include_turns=True)
|
||||
persisted_turn = next(
|
||||
(turn for turn in persisted.thread.turns or [] if turn.id == result.turn_id),
|
||||
None,
|
||||
)
|
||||
|
||||
print("thread_id:", result.thread_id)
|
||||
print("turn_id:", result.turn_id)
|
||||
@@ -21,7 +26,10 @@ with Codex(config=runtime_config()) as codex:
|
||||
if result.error is not None:
|
||||
print("error:", result.error)
|
||||
print("text:", result.text)
|
||||
print("items.count:", len(result.items))
|
||||
print(
|
||||
"persisted.items.count:",
|
||||
0 if persisted_turn is None else len(persisted_turn.items or []),
|
||||
)
|
||||
if result.usage is None:
|
||||
raise RuntimeError("missing usage for completed turn")
|
||||
print("usage.thread_id:", result.usage.thread_id)
|
||||
|
||||
Reference in New Issue
Block a user