Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions util/opentelemetry-util-genai/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ The GenAI Utils package will include boilerplate and helpers to standardize inst
This package will provide APIs and decorators to minimize the work needed to instrument genai libraries,
while providing standardization for generating both types of otel, "spans and metrics" and "spans, metrics and events"

This package provides these span attributes.
-> gen_ai.operation.name: Str(chat)
-> gen_ai.system: Str(ChatOpenAI)
-> gen_ai.request.model: Str(gpt-3.5-turbo)
-> gen_ai.request.top_p: Double(0.9)
-> gen_ai.request.frequency_penalty: Double(0.5)
-> gen_ai.request.presence_penalty: Double(0.5)
-> gen_ai.request.stop_sequences: Slice(["\n","Human:","AI:"])
-> gen_ai.request.seed: Int(100)
-> gen_ai.request.max_tokens: Int(100)
-> gen_ai.provider.name: Str(openai)
-> gen_ai.request.temperature: Double(0.1)
-> gen_ai.response.finish_reasons: Slice(["stop"])
-> gen_ai.response.model: Str(gpt-3.5-turbo-0125)
-> gen_ai.response.id: Str(chatcmpl-Bz8yrvPnydD9pObv625n2CGBPHS13)
-> gen_ai.usage.input_tokens: Int(24)
-> gen_ai.usage.output_tokens: Int(7)

Installation
------------

Expand Down
6 changes: 3 additions & 3 deletions util/opentelemetry-util-genai/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ classifiers = [
"Programming Language :: Python :: 3.13",
]
dependencies = [
"opentelemetry-instrumentation ~= 0.51b0",
"opentelemetry-semantic-conventions ~= 0.51b0",
"opentelemetry-api>=1.31.0",
"opentelemetry-instrumentation ~= 0.57b0",
"opentelemetry-semantic-conventions ~= 0.57b0",
"opentelemetry-api>=1.36.0",
]

[project.optional-dependencies]
Expand Down
38 changes: 38 additions & 0 deletions util/opentelemetry-util-genai/src/opentelemetry/util/genai/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from dataclasses import dataclass


@dataclass
class Message:
content: str
type: str
name: str

def _to_part_dict(self):
"""Convert the message to a dictionary suitable for OpenTelemetry semconvs.

Ref: https://github.com/open-telemetry/semantic-conventions/blob/main/docs/registry/attributes/gen-ai.md#gen-ai-input-messages
"""

# Support tool_call and tool_call response
return {
"role": self.type,
"parts": [
{
"content": self.content,
"type": "text",
}
],
}


@dataclass
class ChatGeneration:
content: str
type: str
finish_reason: str = None


@dataclass
class Error:
message: str
type: type[BaseException]
Loading