Class: NitroIntelligence::Client::Observers::LangfuseObserver
- Inherits:
-
Object
- Object
- NitroIntelligence::Client::Observers::LangfuseObserver
- Defined in:
- lib/nitro_intelligence/client/observers/langfuse_observer.rb
Constant Summary collapse
- LITELLM_CALL_ID_HEADER =
The inference gateway returns its own request identifier on every response, including error responses. Recording it on the observation is the only way to line a failed generation up with the gateway's logs. See https://docs.litellm.ai/docs/proxy/response_headers
"x-litellm-call-id".freeze
- MAX_STATUS_MESSAGE_LENGTH =
2000
Instance Attribute Summary collapse
-
#project_client ⇒ Object
readonly
Returns the value of attribute project_client.
Instance Method Summary collapse
-
#initialize(project_client:) ⇒ LangfuseObserver
constructor
A new instance of LangfuseObserver.
-
#observe(operation_name, type:, parameters:, trace_name:, prompt: nil, input: nil) ⇒ Object
rubocop:disable Metrics/AbcSize.
Constructor Details
#initialize(project_client:) ⇒ LangfuseObserver
Returns a new instance of LangfuseObserver.
15 16 17 |
# File 'lib/nitro_intelligence/client/observers/langfuse_observer.rb', line 15 def initialize(project_client:) @project_client = project_client end |
Instance Attribute Details
#project_client ⇒ Object (readonly)
Returns the value of attribute project_client.
13 14 15 |
# File 'lib/nitro_intelligence/client/observers/langfuse_observer.rb', line 13 def project_client @project_client end |
Instance Method Details
#observe(operation_name, type:, parameters:, trace_name:, prompt: nil, input: nil) ⇒ Object
rubocop:disable Metrics/AbcSize
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/nitro_intelligence/client/observers/langfuse_observer.rb', line 19 def observe(operation_name, type:, parameters:, trace_name:, prompt: nil, input: nil) # rubocop:disable Metrics/AbcSize = parameters[:metadata] seed = parameters[:trace_seed] trace_id = NitroIntelligence::Trace.create_id(seed:) if seed.present? if prompt [:prompt_name] = prompt.name [:prompt_version] = prompt.version end = .transform_values(&:to_s) Langfuse.propagate_attributes(**propagated_attributes(parameters, )) do @project_client.observability_client.observe( operation_name, as_type: type, trace_id:, environment: NitroIntelligence.environment.to_s, model: parameters[:model], metadata: ) do |generation| generation.update_trace(name: trace_name, release: NitroIntelligence.configuration.current_revision) generation.update({ prompt: { name: prompt.name, version: prompt.version } }) if prompt record_input(generation, input) result, trace_attributes = observe_failures(generation) { yield(generation) } if trace_attributes handle_truncation(trace_attributes[:input], trace_attributes[:output], trace_attributes[:model]) generation.model = trace_attributes[:model] if trace_attributes[:model] generation.usage_details = trace_attributes[:usage_details] if trace_attributes[:usage_details] generation.input = trace_attributes[:input] if trace_attributes[:input] generation.output = trace_attributes[:output] if trace_attributes[:output] generation.update_trace(input: trace_attributes[:input], output: trace_attributes[:output]) end result end end end |