-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Better follow otel semconv #3741
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 |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| """Type definitions of OpenTelemetry GenAI spec message parts. | ||
|
|
||
| Based on https://github.com/lmolkova/semantic-conventions/blob/eccd1f806e426a32c98271c3ce77585492d26de2/docs/gen-ai/non-normative/models.ipynb | ||
| Based on the OpenTelemetry semantic conventions for GenAI: | ||
| https://github.com/open-telemetry/semantic-conventions/blob/main/docs/gen-ai/gen-ai-input-messages.json | ||
| https://github.com/open-telemetry/semantic-conventions/blob/main/docs/gen-ai/gen-ai-output-messages.json | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
@@ -12,11 +14,15 @@ | |
|
|
||
|
|
||
| class TextPart(TypedDict): | ||
| """A text part in a GenAI message.""" | ||
|
|
||
| type: Literal['text'] | ||
| content: NotRequired[str] | ||
|
|
||
|
|
||
| class ToolCallPart(TypedDict): | ||
| """A tool call part in a GenAI message.""" | ||
|
|
||
| type: Literal['tool_call'] | ||
| id: str | ||
| name: str | ||
|
|
@@ -25,36 +31,57 @@ class ToolCallPart(TypedDict): | |
|
|
||
|
|
||
| class ToolCallResponsePart(TypedDict): | ||
| """A tool call response part in a GenAI message.""" | ||
|
|
||
| type: Literal['tool_call_response'] | ||
| id: str | ||
| name: str | ||
| # TODO: This should be `response` not `result` | ||
| result: NotRequired[JsonValue] | ||
| builtin: NotRequired[bool] # Not (currently?) part of the spec, used by Logfire | ||
|
|
||
|
|
||
| class MediaUrlPart(TypedDict): | ||
| type: Literal['image-url', 'audio-url', 'video-url', 'document-url'] | ||
| url: NotRequired[str] | ||
| class UriPart(TypedDict): | ||
| """A URI part in a GenAI message (for images, audio, video, documents). | ||
|
|
||
| Per the semantic conventions, uses 'uri' type with modality field. | ||
| """ | ||
|
|
||
| class BinaryDataPart(TypedDict): | ||
| type: Literal['binary'] | ||
| media_type: str | ||
| content: NotRequired[str] | ||
| type: Literal['uri'] | ||
| uri: NotRequired[str] | ||
| modality: NotRequired[str] | ||
|
|
||
|
|
||
| class BlobPart(TypedDict): | ||
| """A blob (binary data) part in a GenAI message. | ||
|
|
||
| Per the semantic conventions, uses 'blob' type with modality field. | ||
| """ | ||
|
|
||
| class ThinkingPart(TypedDict): | ||
| type: Literal['thinking'] | ||
| type: Literal['blob'] | ||
| blob: NotRequired[str] | ||
| modality: NotRequired[str] | ||
|
|
||
|
|
||
| class ReasoningPart(TypedDict): | ||
| """A reasoning/thinking part in a GenAI message. | ||
|
|
||
| Per the semantic conventions, uses 'reasoning' type. | ||
|
Contributor
Author
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. You can find |
||
| """ | ||
|
|
||
| type: Literal['reasoning'] | ||
| content: NotRequired[str] | ||
|
|
||
|
|
||
| MessagePart: TypeAlias = 'TextPart | ToolCallPart | ToolCallResponsePart | MediaUrlPart | BinaryDataPart | ThinkingPart' | ||
| MessagePart: TypeAlias = 'TextPart | ToolCallPart | ToolCallResponsePart | UriPart | BlobPart | ReasoningPart' | ||
|
|
||
|
|
||
| Role = Literal['system', 'user', 'assistant'] | ||
|
|
||
|
|
||
| class ChatMessage(TypedDict): | ||
| """A chat message in the GenAI format.""" | ||
|
|
||
| role: Role | ||
| parts: list[MessagePart] | ||
|
|
||
|
|
@@ -63,6 +90,8 @@ class ChatMessage(TypedDict): | |
|
|
||
|
|
||
| class OutputMessage(ChatMessage): | ||
| """An output message with optional finish reason.""" | ||
|
|
||
| finish_reason: NotRequired[str] | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also noted in https://github.com/open-telemetry/semantic-conventions/blob/main/docs/gen-ai/gen-ai-input-messages.json, I can update the PR to make this change you want, or I can revert the changes to the other types below.