Python: [Breaking] removed pydantic from types and workflows (#917)

* removed pydantic from types

* fix test

* fix test

* fix tests

* fix assistants client

* Remove Pydantic usage from workflow code.

* updated pydantic removal

* updated lock and test fixes

* fix mypy

* updated build system

* updated chat client parsing

* fix broken test

---------

Co-authored-by: Evan Mattson <evan.mattson@microsoft.com>
This commit is contained in:
Eduard van Valkenburg
2025-09-29 23:19:58 +02:00
committed by GitHub
Unverified
parent 647db9635a
commit b4ebafa9b1
56 changed files with 3881 additions and 1735 deletions
@@ -564,7 +564,11 @@ def get_meter(
schema_url: Optional. Specifies the Schema URL of the emitted telemetry.
attributes: Optional. Attributes that are associated with the emitted telemetry.
"""
return metrics.get_meter(name=name, version=version, schema_url=schema_url, attributes=attributes)
try:
return metrics.get_meter(name=name, version=version, schema_url=schema_url, attributes=attributes)
except TypeError:
# Older OpenTelemetry releases do not support the attributes parameter.
return metrics.get_meter(name=name, version=version, schema_url=schema_url)
global OBSERVABILITY_SETTINGS
@@ -772,7 +776,11 @@ def _trace_get_response(
self.additional_properties["token_usage_histogram"] = _get_token_usage_histogram()
if "operation_duration_histogram" not in self.additional_properties:
self.additional_properties["operation_duration_histogram"] = _get_duration_histogram()
model_id = str(kwargs.get("ai_model_id") or getattr(self, "ai_model_id", "unknown"))
model_id = (
kwargs.get("model")
or (chat_options.model_id if (chat_options := kwargs.get("chat_options")) else None)
or getattr(self, "model_id", None)
)
service_url = str(
service_url_func()
if (service_url_func := getattr(self, "service_url", None)) and callable(service_url_func)
@@ -853,7 +861,11 @@ def _trace_get_streaming_response(
if "operation_duration_histogram" not in self.additional_properties:
self.additional_properties["operation_duration_histogram"] = _get_duration_histogram()
model_id = kwargs.get("ai_model_id") or getattr(self, "ai_model_id", None)
model_id = (
kwargs.get("model")
or (chat_options.model_id if (chat_options := kwargs.get("chat_options")) else None)
or getattr(self, "model_id", None)
)
service_url = str(
service_url_func()
if (service_url_func := getattr(self, "service_url", None)) and callable(service_url_func)
@@ -1244,7 +1256,7 @@ def _capture_messages(
for index, message in enumerate(prepped):
otel_messages.append(_to_otel_message(message))
try:
message_data = message.model_dump(exclude_none=True)
message_data = message.to_dict(exclude_none=True)
except Exception:
message_data = {"role": message.role.value, "contents": message.contents}
logger.info(
@@ -1298,7 +1310,7 @@ def _to_otel_part(content: "Contents") -> dict[str, Any] | None:
case _:
# GenericPart in otel output messages json spec.
# just required type, and arbitrary other fields.
return content.model_dump(exclude_none=True)
return content.to_dict(exclude_none=True)
return None
@@ -1317,8 +1329,8 @@ def _get_response_attributes(
)
if finish_reason:
attributes[OtelAttr.FINISH_REASONS] = json.dumps([finish_reason.value])
if ai_model_id := getattr(response, "ai_model_id", None):
attributes[SpanAttributes.LLM_RESPONSE_MODEL] = ai_model_id
if model_id := getattr(response, "model_id", None):
attributes[SpanAttributes.LLM_RESPONSE_MODEL] = model_id
if usage := response.usage_details:
if usage.input_token_count:
attributes[OtelAttr.INPUT_TOKENS] = usage.input_token_count