-
Notifications
You must be signed in to change notification settings - Fork 811
InstrumentedModel and FallbackModel fixes #1121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Docs Preview
|
"""The system / model provider, n/a for fallback models.""" | ||
return None | ||
def system(self) -> str: | ||
return 'fallback' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this include the systems of models that are fallen back to? E.g. 'fallback:openai:anthropic:function'
or similar?
Related, if this never ends up in the otel system (e.g. because we use the value from the actual model that made the request), I think we don't necessarily need to include the fallback systems here but I would appreciate a comment explaining that.
(If it does end up in the otel, then it seems problematic. I'm assuming it doesn't though.)
span = get_current_span() | ||
if span.is_recording(): | ||
attributes = getattr(span, 'attributes', {}) | ||
if attributes.get('gen_ai.request.model') == self.model_name: | ||
span.set_attributes(InstrumentedModel.model_attributes(model)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this should be outside this try-except. Like, errors with otel shouldn't trigger fallback, it means something more fundamental is wrong
TypeError: cannot pickle '_thread.RLock' object
error reported in https://pydanticlogfire.slack.com/archives/C083V7PMHHA/p1741909209116159 by no longer settingmodel_used
onModelResponse
.Model.system
non-optional, becausegen_ai.system
is an important attribute and OTel doesn't support null attribute values.Model.system
directly returns value used forgen_ai.system
to help with Fix instrumentation of FallbackModel #1076 (comment). @Kludex we still need to do something about bedrock, azure, and maybe others, but I've stuffed too much in here already.