diff --git a/util/opentelemetry-util-genai/src/opentelemetry/util/genai/types.py b/util/opentelemetry-util-genai/src/opentelemetry/util/genai/types.py new file mode 100644 index 0000000000..44ce90ce5e --- /dev/null +++ b/util/opentelemetry-util-genai/src/opentelemetry/util/genai/types.py @@ -0,0 +1,59 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +from dataclasses import dataclass +from typing import Any, Literal, Optional, Union + + +@dataclass() +class ToolCall: + type: Literal["tool_call"] = "tool_call" + arguments: Any + name: str + id: Optional[str] + + +@dataclass() +class ToolCallResponse: + type: Literal["tool_call_response"] = "tool_call_response" + response: Any + id: Optional[str] + + +FinishReason = Literal[ + "content_filter", "error", "length", "stop", "tool_calls" +] + + +@dataclass() +class Text: + type: Literal["text"] = "text" + content: str + + +MessagePart = Union[Text, ToolCall, ToolCallResponse, Any] + + +@dataclass() +class InputMessage: + role: str + parts: list[MessagePart] + + +@dataclass() +class OutputMessage: + role: str + parts: list[MessagePart] + finish_reason: Union[str, FinishReason]