mirror of
https://github.com/openai/codex.git
synced 2026-04-28 00:25:56 +00:00
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>
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
import sys
|
|
from pathlib import Path
|
|
|
|
_EXAMPLES_ROOT = Path(__file__).resolve().parents[1]
|
|
if str(_EXAMPLES_ROOT) not in sys.path:
|
|
sys.path.insert(0, str(_EXAMPLES_ROOT))
|
|
|
|
from _bootstrap import ensure_local_sdk_src, runtime_config
|
|
|
|
ensure_local_sdk_src()
|
|
|
|
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)
|
|
print("status:", result.status)
|
|
if result.error is not None:
|
|
print("error:", result.error)
|
|
print("text:", result.text)
|
|
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)
|
|
print("usage.turn_id:", result.usage.turn_id)
|