fix: guard ACTIVE_MODEL_INSTANCES lookup and add json default=str

This commit is contained in:
emco 2026-06-09 12:19:11 +01:00
parent 1c79507140
commit b92fc723f0
2 changed files with 8 additions and 5 deletions

View File

@ -132,7 +132,7 @@ def main() -> int:
try:
with open(args.result_file, "w", encoding="utf-8") as f:
json.dump(payload, f, ensure_ascii=False)
json.dump(payload, f, ensure_ascii=False, default=str)
except Exception as write_error: # pylint: disable=broad-except
print(f"[CAI worker] failed to write result file: {write_error}", file=sys.stderr)
return 2

View File

@ -125,10 +125,13 @@ def _get_agent_token_info():
from cai.sdk.agents.models.openai_chatcompletions import ACTIVE_MODEL_INSTANCES
if ACTIVE_MODEL_INSTANCES:
# Get the most recent instance (highest instance ID)
latest_key = max(ACTIVE_MODEL_INSTANCES.keys(), key=lambda x: x[1])
model_ref = ACTIVE_MODEL_INSTANCES[latest_key]
model = model_ref() if model_ref else None
try:
# Get the most recent instance (highest instance ID)
latest_key = max(ACTIVE_MODEL_INSTANCES.keys(), key=lambda x: x[1])
model_ref = ACTIVE_MODEL_INSTANCES.get(latest_key)
model = model_ref() if model_ref else None
except Exception:
model = None
if model:
# Get display name with ID