lmnr 0.4.12b2__py3-none-any.whl → 0.4.12b4__py3-none-any.whl

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,57 +0,0 @@
1
- from contextlib import contextmanager
2
- from opentelemetry.semconv_ai import SpanAttributes
3
- from opentelemetry.trace import Span
4
- from pydantic import BaseModel
5
- from lmnr.traceloop_sdk.tracing.context_manager import get_tracer
6
-
7
-
8
- class LLMMessage(BaseModel):
9
- role: str
10
- content: str
11
-
12
-
13
- class LLMUsage(BaseModel):
14
- prompt_tokens: int
15
- completion_tokens: int
16
- total_tokens: int
17
-
18
-
19
- class LLMSpan:
20
- _span: Span = None
21
-
22
- def __init__(self, span: Span):
23
- self._span = span
24
- pass
25
-
26
- def report_request(self, model: str, messages: list[LLMMessage]):
27
- self._span.set_attribute(SpanAttributes.LLM_REQUEST_MODEL, model)
28
- for idx, message in enumerate(messages):
29
- self._span.set_attribute(
30
- f"{SpanAttributes.LLM_PROMPTS}.{idx}.role", message.role
31
- )
32
- self._span.set_attribute(
33
- f"{SpanAttributes.LLM_PROMPTS}.{idx}.content", message.content
34
- )
35
-
36
- def report_response(self, model: str, completions: list[str]):
37
- self._span.set_attribute(SpanAttributes.LLM_RESPONSE_MODEL, model)
38
- for idx, completion in enumerate(completions):
39
- self._span.set_attribute(
40
- f"{SpanAttributes.LLM_COMPLETIONS}.{idx}.role", "assistant"
41
- )
42
- self._span.set_attribute(
43
- f"{SpanAttributes.LLM_COMPLETIONS}.{idx}", completion
44
- )
45
-
46
-
47
- @contextmanager
48
- def track_llm_call(vendor: str, type: str):
49
- with get_tracer() as tracer:
50
- with tracer.start_as_current_span(name=f"{vendor}.{type}") as span:
51
- span.set_attribute(SpanAttributes.LLM_SYSTEM, vendor)
52
- span.set_attribute(SpanAttributes.LLM_REQUEST_TYPE, type)
53
- llm_span = LLMSpan(span)
54
- try:
55
- yield llm_span
56
- finally:
57
- span.end()