-
Notifications
You must be signed in to change notification settings - Fork 14
feat: Implement Mistral OpenTelemetry #703
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
base: LILYPAD-223
Are you sure you want to change the base?
Conversation
️✅ There are no secrets present in this pull request anymore.If these secrets were true positive and are still valid, we highly recommend you to revoke them. 🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request. |
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
🚀 Preview DeploymentYour changes have been deployed to a preview environment: Preview URL: https://lilypad-pr-703.mirascope.workers.dev Database Branch: Last updated: 2025-10-03T04:12:42Z (Commit: 6da8958) |
98cefac
to
da91e24
Compare
a5a8b79
to
e919212
Compare
385a27c
to
c90f218
Compare
e919212
to
36031fe
Compare
|
||
_MISTRAL_SYSTEM = gen_ai_attributes.GenAiSystemValues.MISTRAL_AI.value | ||
|
||
MistralMessage: TypeAlias = ( |
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.
nit: i think these type aliases might make things more confusing
class _MistralKwargs(BaseKwargs, total=False): | ||
"""TypedDict for Mistral chat completion parameters.""" | ||
|
||
model: Required[str] |
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.
nit: should have same required vs. not required comments as other providers
server_url: str | None | ||
|
||
|
||
def _coerce_optional(value: T | None) -> T | None: |
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.
the type hint on this function doesn't match it's description since it doesn't include UNSET
or UNSET_SENTINEL
|
||
def _normalize_stop_sequences(stop: Stop | None) -> list[str] | None: | ||
"""Returns normalized stop sequences from Mistral parameters.""" | ||
normalized = _coerce_optional(stop) |
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.
same here, if the type is Stop | None
why do we need to coerce?
kwargs.get("server_url") or client.sdk_configuration.get_server_details()[0] | ||
) | ||
parsed = urlparse(server_url or "") | ||
request_attributes = GenAIRequestAttributes( |
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.
nit: just return this directly
message: Message = {"role": "assistant"} | ||
tool_calls = None | ||
if choice.message: | ||
message_dict = _to_dict(choice.message) |
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.
note that this is an example proving my earlier comment that _to_dict
removes the value of type hints in the following code
if content: | ||
message["content"] = content | ||
tool_calls_value = message_dict.get("tool_calls") | ||
tool_calls_payload = ( |
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.
another reason to push this inside of _convert_tool_calls
return response_attributes, choice_deltas | ||
|
||
|
||
def instrument_mistral(client: Mistral) -> None: |
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.
nit: the formatting on this function doesn't match other providers
_utils.mark_client_as_instrumented(client) | ||
|
||
|
||
if not hasattr(EventStreamAsync, "close"): |
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'd like to sync on why we need this
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.
no tests for tools reinsertion?
c90f218
to
b02d206
Compare
04a34fc
to
b9c8a35
Compare
b02d206
to
a2952b2
Compare
1f8cbab
to
bdd704e
Compare
479e664
to
436b11a
Compare
cac29d2
to
3c5de5f
Compare
618e158
to
7d0b215
Compare
TL;DR
Added support for Mistral AI in the Python SDK's telemetry and tracing system.
What changed?
_MistralInstrumentor
class to handle Mistral client instrumentationinstrument_mistral()
function to instrument Mistral clientspyproject.toml
for the new Mistral integrationHow to test?
Install the Mistral dependency:
Use the instrumentation in your code:
Run the tests:
Why make this change?
This change extends the SDK's telemetry capabilities to include Mistral AI, allowing users to collect standardized telemetry data when using Mistral models. This is part of the ongoing effort to provide comprehensive observability across all supported LLM providers, making it easier for users to monitor, debug, and analyze their AI applications regardless of which provider they're using.