Class: Langfuse::Types::GenerationAttributes
- Inherits:
-
SpanAttributes
- Object
- SpanAttributes
- Langfuse::Types::GenerationAttributes
- Defined in:
- lib/langfuse/types.rb
Overview
Attributes for Langfuse generation observations
Generations are specialized observations for tracking LLM interactions, including model parameters, usage metrics, costs, and prompt information.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#completion_start_time ⇒ Time?
Timestamp when the model started generating completion.
-
#cost_details ⇒ Hash?
Cost breakdown for the generation (prefer :input, :output, :total).
-
#model ⇒ String?
Name of the language model used (e.g., 'gpt-4', 'claude-3-opus').
-
#model_parameters ⇒ Hash?
Parameters passed to the model (temperature, max_tokens, etc.).
-
#prompt ⇒ Hash?
Information about the prompt used from Langfuse prompt management Hash should contain :name (String), :version (Integer), :is_fallback (Boolean).
-
#usage_details ⇒ Hash?
Token usage and other model-specific usage metrics.
Attributes inherited from SpanAttributes
#environment, #input, #level, #metadata, #output, #status_message, #version
Instance Method Summary collapse
-
#initialize(completion_start_time: nil, model: nil, model_parameters: nil, usage_details: nil, cost_details: nil, prompt: nil) ⇒ GenerationAttributes
constructor
Initialize a new GenerationAttributes instance.
-
#to_h ⇒ Hash
Convert attributes to a hash representation.
Constructor Details
#initialize(completion_start_time: nil, model: nil, model_parameters: nil, usage_details: nil, cost_details: nil, prompt: nil) ⇒ GenerationAttributes
Initialize a new GenerationAttributes instance
rubocop:disable Metrics/ParameterLists
207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/langfuse/types.rb', line 207 def initialize(completion_start_time: nil, model: nil, model_parameters: nil, usage_details: nil, cost_details: nil, prompt: nil, **) # rubocop:enable Metrics/ParameterLists super(**) @completion_start_time = completion_start_time @model = model @model_parameters = model_parameters @usage_details = usage_details @cost_details = cost_details @prompt = prompt end |
Instance Attribute Details
#completion_start_time ⇒ Time?
Returns Timestamp when the model started generating completion.
179 180 181 |
# File 'lib/langfuse/types.rb', line 179 def completion_start_time @completion_start_time end |
#cost_details ⇒ Hash?
Returns Cost breakdown for the generation (prefer :input, :output, :total).
191 192 193 |
# File 'lib/langfuse/types.rb', line 191 def cost_details @cost_details end |
#model ⇒ String?
Returns Name of the language model used (e.g., 'gpt-4', 'claude-3-opus').
182 183 184 |
# File 'lib/langfuse/types.rb', line 182 def model @model end |
#model_parameters ⇒ Hash?
Returns Parameters passed to the model (temperature, max_tokens, etc.).
185 186 187 |
# File 'lib/langfuse/types.rb', line 185 def model_parameters @model_parameters end |
#prompt ⇒ Hash?
Returns Information about the prompt used from Langfuse prompt management Hash should contain :name (String), :version (Integer), :is_fallback (Boolean).
195 196 197 |
# File 'lib/langfuse/types.rb', line 195 def prompt @prompt end |
#usage_details ⇒ Hash?
Returns Token usage and other model-specific usage metrics.
188 189 190 |
# File 'lib/langfuse/types.rb', line 188 def usage_details @usage_details end |
Instance Method Details
#to_h ⇒ Hash
Convert attributes to a hash representation
Returns a hash with all non-nil attributes, including both span and generation-specific fields.
224 225 226 227 228 229 230 231 232 233 |
# File 'lib/langfuse/types.rb', line 224 def to_h super.merge( completion_start_time: @completion_start_time, model: @model, model_parameters: @model_parameters, usage_details: @usage_details, cost_details: @cost_details, prompt: @prompt ).compact end |