Class: Tracebook::NormalizedInteraction

Inherits:
Data
  • Object
show all
Defined in:
lib/tracebook/normalized_interaction.rb

Overview

Normalized representation of an LLM interaction.

This immutable data structure provides a standard format for LLM interactions across different providers. Mappers convert provider-specific formats into this structure before persistence.

Examples:

Creating a normalized interaction

interaction = NormalizedInteraction.new(
  provider: "openai",
  model: "gpt-4o",
  request_payload: { messages: messages },
  response_payload: response,
  input_tokens: 100,
  output_tokens: 50,
  status: :success
)

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provider:, model:, project: nil, request_payload: {}, response_payload: {}, request_text: nil, response_text: nil, input_tokens: nil, output_tokens: nil, latency_ms: nil, status: "success", error_class: nil, error_message: nil, tags: [], metadata: {}, user: nil, parent_id: nil, session_id: nil) ⇒ NormalizedInteraction

Returns a new instance of NormalizedInteraction.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/tracebook/normalized_interaction.rb', line 61

def initialize(
  provider:,
  model:,
  project: nil,
  request_payload: {},
  response_payload: {},
  request_text: nil,
  response_text: nil,
  input_tokens: nil,
  output_tokens: nil,
  latency_ms: nil,
  status: "success",
  error_class: nil,
  error_message: nil,
  tags: [],
  metadata: {},
  user: nil,
  parent_id: nil,
  session_id: nil
)
  super
end

Instance Attribute Details

#error_classString? (readonly)

Exception class name on failure

Returns:

  • (String, nil)

    the current value of error_class



41
42
43
# File 'lib/tracebook/normalized_interaction.rb', line 41

def error_class
  @error_class
end

#error_messageString? (readonly)

Exception message on failure

Returns:

  • (String, nil)

    the current value of error_message



41
42
43
# File 'lib/tracebook/normalized_interaction.rb', line 41

def error_message
  @error_message
end

#input_tokensInteger? (readonly)

Prompt token count

Returns:

  • (Integer, nil)

    the current value of input_tokens



41
42
43
# File 'lib/tracebook/normalized_interaction.rb', line 41

def input_tokens
  @input_tokens
end

#latency_msInteger? (readonly)

Request duration in milliseconds

Returns:

  • (Integer, nil)

    the current value of latency_ms



41
42
43
# File 'lib/tracebook/normalized_interaction.rb', line 41

def latency_ms
  @latency_ms
end

#metadataHash (readonly)

Custom metadata

Returns:

  • (Hash)

    the current value of metadata



41
42
43
# File 'lib/tracebook/normalized_interaction.rb', line 41

def 
  
end

#modelString (readonly)

Model identifier (e.g., "gpt-4o", "claude-3-5-sonnet")

Returns:

  • (String)

    the current value of model



41
42
43
# File 'lib/tracebook/normalized_interaction.rb', line 41

def model
  @model
end

#output_tokensInteger? (readonly)

Completion token count

Returns:

  • (Integer, nil)

    the current value of output_tokens



41
42
43
# File 'lib/tracebook/normalized_interaction.rb', line 41

def output_tokens
  @output_tokens
end

#parent_idInteger? (readonly)

Parent interaction ID for hierarchical chains

Returns:

  • (Integer, nil)

    the current value of parent_id



41
42
43
# File 'lib/tracebook/normalized_interaction.rb', line 41

def parent_id
  @parent_id
end

#projectString? (readonly)

Project name for filtering

Returns:

  • (String, nil)

    the current value of project



41
42
43
# File 'lib/tracebook/normalized_interaction.rb', line 41

def project
  @project
end

#providerString (readonly)

Provider name (e.g., "openai", "anthropic")

Returns:

  • (String)

    the current value of provider



41
42
43
# File 'lib/tracebook/normalized_interaction.rb', line 41

def provider
  @provider
end

#request_payloadHash (readonly)

Full request sent to provider (will be encrypted)

Returns:

  • (Hash)

    the current value of request_payload



41
42
43
# File 'lib/tracebook/normalized_interaction.rb', line 41

def request_payload
  @request_payload
end

#request_textString? (readonly)

Human-readable request summary

Returns:

  • (String, nil)

    the current value of request_text



41
42
43
# File 'lib/tracebook/normalized_interaction.rb', line 41

def request_text
  @request_text
end

#response_payloadHash (readonly)

Full response from provider (will be encrypted)

Returns:

  • (Hash)

    the current value of response_payload



41
42
43
# File 'lib/tracebook/normalized_interaction.rb', line 41

def response_payload
  @response_payload
end

#response_textString? (readonly)

Human-readable response summary

Returns:

  • (String, nil)

    the current value of response_text



41
42
43
# File 'lib/tracebook/normalized_interaction.rb', line 41

def response_text
  @response_text
end

#session_idString? (readonly)

Session identifier for grouping related calls

Returns:

  • (String, nil)

    the current value of session_id



41
42
43
# File 'lib/tracebook/normalized_interaction.rb', line 41

def session_id
  @session_id
end

#statusSymbol, String (readonly)

:success, :error, or :canceled

Returns:

  • (Symbol, String)

    the current value of status



41
42
43
# File 'lib/tracebook/normalized_interaction.rb', line 41

def status
  @status
end

#tagsArray<String> (readonly)

Labels for filtering

Returns:

  • (Array<String>)

    the current value of tags



41
42
43
# File 'lib/tracebook/normalized_interaction.rb', line 41

def tags
  @tags
end

#userActiveRecord::Base? (readonly)

Associated user (polymorphic)

Returns:

  • (ActiveRecord::Base, nil)

    the current value of user



41
42
43
# File 'lib/tracebook/normalized_interaction.rb', line 41

def user
  @user
end