telemetry-dev-litellm 0.2.7__tar.gz → 0.2.9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: telemetry-dev-litellm
3
- Version: 0.2.7
3
+ Version: 0.2.9
4
4
  Summary: LiteLLM integration for telemetry.dev Python SDK
5
5
  Keywords: telemetry,opentelemetry,llm,genai,litellm,tracing
6
6
  Author: telemetry.dev
@@ -14,7 +14,7 @@ Classifier: Programming Language :: Python :: 3.11
14
14
  Classifier: Programming Language :: Python :: 3.12
15
15
  Classifier: Programming Language :: Python :: 3.13
16
16
  Classifier: Typing :: Typed
17
- Requires-Dist: telemetry-dev>=0.3.0
17
+ Requires-Dist: telemetry-dev>=0.3.9
18
18
  Requires-Dist: litellm>=1.90.2,<2.0
19
19
  Requires-Dist: opentelemetry-api>=1.39.0,<2
20
20
  Requires-Python: >=3.10, <3.14
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "telemetry-dev-litellm"
3
- version = "0.2.7"
3
+ version = "0.2.9"
4
4
  description = "LiteLLM integration for telemetry.dev Python SDK"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -25,7 +25,7 @@ classifiers = [
25
25
  "Typing :: Typed",
26
26
  ]
27
27
  dependencies = [
28
- "telemetry-dev>=0.3.0",
28
+ "telemetry-dev>=0.3.9",
29
29
  "litellm>=1.90.2,<2.0",
30
30
  "opentelemetry-api>=1.39.0,<2",
31
31
  ]
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "telemetry-dev-litellm"
3
- version = "0.2.7"
3
+ version = "0.2.9"
4
4
  description = "LiteLLM integration for telemetry.dev Python SDK"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -19,7 +19,7 @@ classifiers = [
19
19
  "Typing :: Typed",
20
20
  ]
21
21
  dependencies = [
22
- "telemetry-dev>=0.3.0",
22
+ "telemetry-dev>=0.3.9",
23
23
  "litellm>=1.90.2,<2.0",
24
24
  "opentelemetry-api>=1.39.0,<2",
25
25
  ]
@@ -16,8 +16,9 @@ from typing import Any, TypeVar, cast
16
16
  import litellm
17
17
  import telemetry_dev
18
18
  from opentelemetry import trace
19
+ from telemetry_dev._serialize import json_dumps
19
20
 
20
- __version__ = "0.2.7"
21
+ __version__ = "0.2.9"
21
22
 
22
23
  RequestMapper = Callable[[tuple[Any, ...], Mapping[str, Any]], tuple[str, dict[str, Any]]]
23
24
  ResponseMapper = Callable[[Any], dict[str, Any]]
@@ -505,6 +506,39 @@ def _prompt_attributes(messages: object) -> dict[str, Any]:
505
506
  return cast("dict[str, Any]", read(messages)) if callable(read) else {}
506
507
 
507
508
 
509
+ def _tool_definitions(tools: Any) -> dict[str, str] | None:
510
+ """The request tools, in the OpenAI format, as ``gen_ai.tool.definitions``: each tool's type
511
+ and name, and with input capture on a function or custom tool's description and its
512
+ parameters (custom tools: their input format). Chat Completions nests a tool under
513
+ ``function`` or ``custom``; Responses puts it at the top. A built-in tool without a name is
514
+ listed by its type. The core SDK also strips descriptions and schemas with capture off; this
515
+ check keeps them out with a core older than that rule."""
516
+ client = telemetry_dev.get_client()
517
+ content = client is not None and client.capture_input
518
+ definitions: list[dict[str, Any]] = []
519
+ for tool in _sequence_items(tools):
520
+ kind = _string(_field(tool, "type"))
521
+ if kind is None:
522
+ continue
523
+ spec = _field(tool, "custom" if kind == "custom" else "function") or tool
524
+ name = _string(_field(spec, "name"))
525
+ if kind not in ("function", "custom"):
526
+ definitions.append({"type": kind} if name is None else {"type": kind, "name": name})
527
+ continue
528
+ if name is None:
529
+ continue
530
+ definition: dict[str, Any] = {"type": kind, "name": name}
531
+ if content:
532
+ description = _string(_field(spec, "description"))
533
+ if description is not None:
534
+ definition["description"] = description
535
+ parameters = _field(spec, "format" if kind == "custom" else "parameters")
536
+ if parameters is not None:
537
+ definition["parameters"] = parameters
538
+ definitions.append(definition)
539
+ return {"gen_ai.tool.definitions": _tools_json(definitions)} if definitions else None
540
+
541
+
508
542
  def _completion_request(
509
543
  args: tuple[Any, ...], kwargs: Mapping[str, Any]
510
544
  ) -> tuple[str, dict[str, Any]]:
@@ -528,7 +562,11 @@ def _completion_request(
528
562
  "presence_penalty": _number(kwargs.get("presence_penalty")),
529
563
  "output_type": _output_type(kwargs.get("response_format")),
530
564
  "metadata": _request_metadata(kwargs),
531
- "attributes": _prompt_attributes(_arg(args, kwargs, "messages", 1)) or None,
565
+ "attributes": {
566
+ **(_tool_definitions(kwargs.get("tools")) or {}),
567
+ **_prompt_attributes(_arg(args, kwargs, "messages", 1)),
568
+ }
569
+ or None,
532
570
  },
533
571
  )
534
572
 
@@ -598,6 +636,7 @@ def _responses_request(
598
636
  input_value, input_budget = _bounded_responses_native(_arg(args, kwargs, "input", 0))
599
637
  attributes: dict[str, Any] = {
600
638
  "gen_ai.operation.name": "chat",
639
+ **(_tool_definitions(kwargs.get("tools")) or {}),
601
640
  **_prompt_attributes(_arg(args, kwargs, "input", 0)),
602
641
  }
603
642
  if input_budget is not None and input_budget.truncated:
@@ -2356,3 +2395,14 @@ __all__ = [
2356
2395
  "uninstrument_litellm",
2357
2396
  "wrap_router",
2358
2397
  ]
2398
+
2399
+
2400
+ def _tools_json(definitions: list[dict[str, Any]]) -> str:
2401
+ """The definitions as JSON, or only their types and names when a schema cannot be
2402
+ serialized, such as one holding a cycle: the wrapper maps the request outside any catch."""
2403
+ try:
2404
+ return json_dumps(definitions)
2405
+ except (TypeError, ValueError):
2406
+ return json_dumps(
2407
+ [{key: tool[key] for key in ("type", "name") if key in tool} for tool in definitions]
2408
+ )