-
Notifications
You must be signed in to change notification settings - Fork 38
Align GenAI message dataclasses with semconv message schemas #284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Align message dataclasses with the GenAI semconv schemas: add `name` to `InputMessage`/`OutputMessage`, add `Compaction`, `SystemInstructionPart`, `MemoryRecord`, and `RetrievalDocument`, extend `Modality` with `document`, and update `FinishReason` to the schema enum (`tool_calls` becomes `tool_call`, adds `compaction`). Message and tool-definition serialization now omits `None`-valued fields to match the semconv JSON schemas. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,12 +30,16 @@ class ContentCapturingMode(Enum): | |
| @dataclass() | ||
| class GenericPart: | ||
| """Used for provider-specific message part types that don't match | ||
| the standard MessagePart types defined in semantic conventions. Wrap custom | ||
| types with GenericPart(value=...) to explicitly opt-in to non-standard types. | ||
| This will be removed in a future version when all instrumentations use core types.""" | ||
| the standard MessagePart types defined in semantic conventions. Set ``type`` | ||
| to the provider-specific type discriminator and carry the payload in | ||
| ``value`` to explicitly opt-in to non-standard types. | ||
| This will be removed in a future version when all instrumentations use core types. | ||
|
|
||
| Per the semconv message schema, ``type`` is a free-form string (the | ||
| provider's own type name), not a fixed literal.""" | ||
|
|
||
| type: str | ||
| value: Any | ||
| type: Literal["generic"] = "generic" | ||
|
|
||
|
|
||
| @dataclass() | ||
|
|
@@ -127,7 +131,20 @@ class Reasoning: | |
| type: Literal["reasoning"] = "reasoning" | ||
|
|
||
|
|
||
| Modality = Literal["image", "video", "audio"] | ||
| @dataclass() | ||
| class Compaction: | ||
| """Represents a compaction/summary of prior conversation history. | ||
|
|
||
| This model is specified as part of semconv in `GenAI messages Python models - CompactionPart | ||
| <https://github.com/open-telemetry/semantic-conventions/blob/main/docs/gen-ai/non-normative/models.ipynb>`__. | ||
| """ | ||
|
|
||
| id: str | None = None | ||
| content: str | None = None | ||
| type: Literal["compaction"] = "compaction" | ||
|
|
||
|
|
||
| Modality = Literal["image", "video", "audio", "document"] | ||
|
|
||
|
|
||
| @dataclass() | ||
|
|
@@ -202,26 +219,60 @@ class GenericToolDefinition: | |
| File, | ||
| Uri, | ||
| Reasoning, | ||
| Compaction, | ||
| GenericPart, # For provider-specific types; prefer standard types above | ||
| ] | ||
|
|
||
|
|
||
| # System instructions are a narrower set of parts than message content. | ||
| # Mirrors the `gen_ai.system_instructions` semconv schema (TextPart | GenericPart). | ||
| SystemInstructionPart = Union[Text, GenericPart] | ||
|
|
||
|
|
||
| FinishReason = Literal[ | ||
| "content_filter", "error", "length", "stop", "tool_calls" | ||
| "content_filter", "error", "length", "stop", "tool_call", "compaction" | ||
| ] | ||
|
|
||
|
|
||
| @dataclass() | ||
| class InputMessage: | ||
| role: str | ||
| parts: list[MessagePart] | ||
| name: str | None = None | ||
|
|
||
|
|
||
| @dataclass() | ||
| class OutputMessage: | ||
| role: str | ||
| parts: list[MessagePart] | ||
| finish_reason: str | FinishReason | ||
| name: str | None = None | ||
|
|
||
|
|
||
| @dataclass() | ||
| class MemoryRecord: | ||
| """Represents a single memory record exposed to or produced by the model. | ||
|
|
||
| This model is specified as part of semconv in `GenAI messages Python models - MemoryRecord | ||
| <https://github.com/open-telemetry/semantic-conventions/blob/main/docs/gen-ai/non-normative/models.ipynb>`__. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This link (and below) doesn't resolve, they point to the old repo |
||
| """ | ||
|
|
||
| content: Any | ||
| id: str | None = None | ||
| metadata: dict[str, Any] | None = None | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel we should start just using AttributeValue instead of Any in these types, since they ultimately go into a span/log attribute right ? For |
||
| score: float | None = None | ||
|
|
||
|
|
||
| @dataclass() | ||
| class RetrievalDocument: | ||
| """Represents a document returned by a retrieval operation. | ||
|
|
||
| This model is specified as part of semconv in `GenAI messages Python models - RetrievalDocument | ||
| <https://github.com/open-telemetry/semantic-conventions/blob/main/docs/gen-ai/non-normative/models.ipynb>`__. | ||
| """ | ||
|
|
||
| id: str | ||
| score: float | ||
|
|
||
|
|
||
| @dataclass | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.