fix: prefer _full_model_name over _settings.model in tracing

The API-provided full model name is more specific than the
user-provided model name (e.g. includes version/snapshot details).
Reorder the lookup in _get_model_name and add a comment where the
Responses service sets the field.
This commit is contained in:
Paul Kompfner
2026-03-19 13:55:26 -04:00
committed by Mark Backman
parent 3ddb7b4aaf
commit f680f3c1fa
2 changed files with 6 additions and 2 deletions

View File

@@ -292,6 +292,8 @@ class OpenAIResponsesLLMService(LLMService):
model = getattr(response, "model", None)
if model:
# This field is used by @traced_llm for more detailed
# model name in tracing spans
self._full_model_name = model
# Process any function calls

View File

@@ -51,8 +51,10 @@ def _get_model_name(service) -> str:
check all the places we used to store it.
"""
return (
getattr(getattr(service, "_settings", None), "model", None)
or getattr(service, "_full_model_name", None)
# Some services store an API-response-provided detailed "full" name,
# which is distinct from the user-provided model name
getattr(service, "_full_model_name", None)
or getattr(getattr(service, "_settings", None), "model", None)
or getattr(service, "model_name", None)
or getattr(service, "_model_name", None)
or "unknown"