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 (total_cost, etc.).
-
#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
193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/langfuse/types.rb', line 193 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.
165 166 167 |
# File 'lib/langfuse/types.rb', line 165 def completion_start_time @completion_start_time end |
#cost_details ⇒ Hash?
Returns Cost breakdown for the generation (total_cost, etc.).
177 178 179 |
# File 'lib/langfuse/types.rb', line 177 def cost_details @cost_details end |
#model ⇒ String?
Returns Name of the language model used (e.g., ‘gpt-4’, ‘claude-3-opus’).
168 169 170 |
# File 'lib/langfuse/types.rb', line 168 def model @model end |
#model_parameters ⇒ Hash?
Returns Parameters passed to the model (temperature, max_tokens, etc.).
171 172 173 |
# File 'lib/langfuse/types.rb', line 171 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).
181 182 183 |
# File 'lib/langfuse/types.rb', line 181 def prompt @prompt end |
#usage_details ⇒ Hash?
Returns Token usage and other model-specific usage metrics.
174 175 176 |
# File 'lib/langfuse/types.rb', line 174 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.
210 211 212 213 214 215 216 217 218 219 |
# File 'lib/langfuse/types.rb', line 210 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 |