telemetry-dev-litellm 0.2.7__tar.gz → 0.2.8__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.
- {telemetry_dev_litellm-0.2.7 → telemetry_dev_litellm-0.2.8}/PKG-INFO +1 -1
- {telemetry_dev_litellm-0.2.7 → telemetry_dev_litellm-0.2.8}/pyproject.toml +1 -1
- {telemetry_dev_litellm-0.2.7 → telemetry_dev_litellm-0.2.8}/pyproject.toml.orig +1 -1
- {telemetry_dev_litellm-0.2.7 → telemetry_dev_litellm-0.2.8}/src/telemetry_dev_litellm/__init__.py +52 -2
- {telemetry_dev_litellm-0.2.7 → telemetry_dev_litellm-0.2.8}/LICENSE +0 -0
- {telemetry_dev_litellm-0.2.7 → telemetry_dev_litellm-0.2.8}/README.md +0 -0
- {telemetry_dev_litellm-0.2.7 → telemetry_dev_litellm-0.2.8}/src/telemetry_dev_litellm/py.typed +0 -0
{telemetry_dev_litellm-0.2.7 → telemetry_dev_litellm-0.2.8}/src/telemetry_dev_litellm/__init__.py
RENAMED
|
@@ -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.
|
|
21
|
+
__version__ = "0.2.8"
|
|
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":
|
|
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
|
+
)
|
|
File without changes
|
|
File without changes
|
{telemetry_dev_litellm-0.2.7 → telemetry_dev_litellm-0.2.8}/src/telemetry_dev_litellm/py.typed
RENAMED
|
File without changes
|