observability.processor.trace_conversion.adapter.elasticsearch.openai_converter#
Attributes#
Functions#
|
Convert role to standard format with fallback. |
Factory function for creating messages by role. |
|
|
Create standardized tool calls from raw data. |
Convert a message to appropriate DFW message type with improved structure. |
|
Validate and convert tools schema to RequestTool format. |
|
Convert a chat response to a DFW payload with better error context. |
|
Convert a LangChain/LangGraph OpenAI trace source to a DFWESRecord. |
Module Contents#
- logger#
- DEFAULT_ROLE = 'user'#
- ROLE_MAP#
- FINISH_REASON_MAP#
- convert_role(role: str) str#
Convert role to standard format with fallback.
- Args:
role (str): The role to convert
- Returns:
str: The converted role
- create_message_by_role(
- role: str,
- content: str | None,
- \*\*kwargs,
Factory function for creating messages by role.
- Args:
role (str): The message role content (str): The message content kwargs: Additional role-specific parameters
- Returns:
Message: The appropriate message type for the role
- Raises:
ValueError: If the role is unsupported
- create_tool_calls(
- tool_calls_data: list,
Create standardized tool calls from raw data.
- Args:
tool_calls_data (list): Raw tool call data
- Returns:
list[ToolCall]: List of validated tool calls
- convert_message_to_dfw(
- message: nat.plugins.data_flywheel.observability.schema.provider.openai_message.OpenAIMessage,
Convert a message to appropriate DFW message type with improved structure.
- Args:
message (OpenAIMessage): The message to convert
- Returns:
Message: The converted message
- Raises:
ValueError: If the message cannot be converted
- validate_and_convert_tools(
- tools_schema: list,
Validate and convert tools schema to RequestTool format.
- Args:
tools_schema (list): Raw tools schema
- Returns:
list[RequestTool]: Validated request tools
- convert_chat_response( ) nat.plugins.data_flywheel.observability.schema.sink.elasticsearch.dfw_es_record.ResponseChoice#
Convert a chat response to a DFW payload with better error context.
- Args:
chat_response (dict): The chat response to convert span_name (str): Span name for error context index (int): The index of this choice
- Returns:
ResponseChoice: The converted chat response
- Raises:
ValueError: If the chat response is invalid
- convert_langchain_openai(
- trace_source: nat.plugins.data_flywheel.observability.schema.trace_container.TraceContainer,
Convert a LangChain/LangGraph OpenAI trace source to a DFWESRecord.
- Args:
trace_source (TraceContainer): The trace source to convert
- Returns:
DFWESRecord: The converted DFW record
- Raises:
ValueError: If the trace source cannot be converted to DFWESRecord