Use TurnStatus in retry examples

This commit is contained in:
Ahmed Ibrahim
2026-05-17 06:15:37 -07:00
parent ac86b0a0e1
commit b2becbfa87
2 changed files with 10 additions and 1 deletions

View File

@@ -21,6 +21,7 @@ from openai_codex import (
TextInput, TextInput,
is_retryable_error, is_retryable_error,
) )
from openai_codex.types import TurnStatus
ResultT = TypeVar("ResultT") ResultT = TypeVar("ResultT")
@@ -72,6 +73,10 @@ async def main() -> None:
print(f"JSON-RPC error {exc.code}: {exc.message}") print(f"JSON-RPC error {exc.code}: {exc.message}")
return return
if result.status == TurnStatus.failed:
print("Turn failed:", result.error)
return
print("Text:", result.final_response) print("Text:", result.final_response)

View File

@@ -16,6 +16,7 @@ from openai_codex import (
TextInput, TextInput,
retry_on_overload, retry_on_overload,
) )
from openai_codex.types import TurnStatus
with Codex(config=runtime_config()) as codex: with Codex(config=runtime_config()) as codex:
thread = codex.thread_start(model="gpt-5.4", config={"model_reasoning_effort": "high"}) thread = codex.thread_start(model="gpt-5.4", config={"model_reasoning_effort": "high"})
@@ -32,4 +33,7 @@ with Codex(config=runtime_config()) as codex:
except JsonRpcError as exc: except JsonRpcError as exc:
print(f"JSON-RPC error {exc.code}: {exc.message}") print(f"JSON-RPC error {exc.code}: {exc.message}")
else: else:
print("Text:", result.final_response) if result.status == TurnStatus.failed:
print("Turn failed:", result.error)
else:
print("Text:", result.final_response)