observability.processor.trace_conversion.adapter.elasticsearch.openai_converter#

Attributes#

Functions#

convert_role(→ str)

Convert role to standard format with fallback.

create_message_by_role(...)

Factory function for creating messages by role.

create_tool_calls(...)

Create standardized tool calls from raw data.

convert_message_to_dfw(...)

Convert a message to appropriate DFW message type with improved structure.

validate_and_convert_tools(...)

Validate and convert tools schema to RequestTool format.

convert_chat_response(...)

Convert a chat response to a DFW payload with better error context.

convert_langchain_openai(...)

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,
) nat.plugins.data_flywheel.observability.schema.sink.elasticsearch.dfw_es_record.Message#

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,
) list[nat.plugins.data_flywheel.observability.schema.sink.elasticsearch.dfw_es_record.ToolCall]#

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,
) nat.plugins.data_flywheel.observability.schema.sink.elasticsearch.dfw_es_record.Message#

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,
) list[nat.plugins.data_flywheel.observability.schema.sink.elasticsearch.dfw_es_record.RequestTool]#

Validate and convert tools schema to RequestTool format.

Args:

tools_schema (list): Raw tools schema

Returns:

list[RequestTool]: Validated request tools

convert_chat_response(
chat_response: dict,
span_name: str = '',
index: int = 0,
) 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,
) nat.plugins.data_flywheel.observability.schema.sink.elasticsearch.dfw_es_record.DFWESRecord#

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