Class: Langfuse::Trace
- Inherits:
-
Object
- Object
- Langfuse::Trace
- Defined in:
- lib/langfuse/trace.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#public ⇒ Object
readonly
Returns the value of attribute public.
-
#release ⇒ Object
readonly
Returns the value of attribute release.
-
#session_id ⇒ Object
readonly
Returns the value of attribute session_id.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#agent(name: nil, start_time: nil, end_time: nil, input: nil, output: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) ⇒ Object
Create a child agent observation.
-
#chain(name: nil, start_time: nil, end_time: nil, input: nil, output: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) ⇒ Object
Create a child chain observation.
-
#embedding(name: nil, start_time: nil, end_time: nil, input: nil, output: nil, model: nil, usage: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) ⇒ Object
Create a child embedding observation.
-
#evaluator(name: nil, start_time: nil, end_time: nil, input: nil, output: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) ⇒ Object
Create a child evaluator observation.
-
#event(name:, start_time: nil, input: nil, output: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) ⇒ Object
Create a child event.
-
#generation(name: nil, start_time: nil, end_time: nil, completion_start_time: nil, model: nil, model_parameters: nil, input: nil, output: nil, usage: nil, usage_details: nil, cost_details: nil, prompt: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) ⇒ Object
Create a child generation.
- #get_url ⇒ Object
-
#guardrail(name: nil, start_time: nil, end_time: nil, input: nil, output: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) ⇒ Object
Create a child guardrail observation.
-
#initialize(client:, id:, name: nil, user_id: nil, session_id: nil, version: nil, release: nil, input: nil, output: nil, metadata: nil, tags: nil, timestamp: nil, public: nil, **kwargs) ⇒ Trace
constructor
A new instance of Trace.
-
#retriever(name: nil, start_time: nil, end_time: nil, input: nil, output: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) ⇒ Object
Create a child retriever observation.
- #score(name:, value:, data_type: nil, comment: nil, **kwargs) ⇒ Object
-
#span(name: nil, start_time: nil, end_time: nil, input: nil, output: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, as_type: nil, **kwargs) ⇒ Object
Create a child span with optional type.
- #to_dict ⇒ Object
-
#tool(name: nil, start_time: nil, end_time: nil, input: nil, output: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) ⇒ Object
Create a child tool observation.
- #update(name: nil, user_id: nil, session_id: nil, version: nil, release: nil, input: nil, output: nil, metadata: nil, tags: nil, public: nil, **kwargs) ⇒ Object
Constructor Details
#initialize(client:, id:, name: nil, user_id: nil, session_id: nil, version: nil, release: nil, input: nil, output: nil, metadata: nil, tags: nil, timestamp: nil, public: nil, **kwargs) ⇒ Trace
Returns a new instance of Trace.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/langfuse/trace.rb', line 8 def initialize(client:, id:, name: nil, user_id: nil, session_id: nil, version: nil, release: nil, input: nil, output: nil, metadata: nil, tags: nil, timestamp: nil, public: nil, **kwargs) @client = client @id = id @name = name @user_id = user_id @session_id = session_id @version = version @release = release @input = input @output = output @metadata = || {} @tags = || [] @timestamp = @public = public @kwargs = kwargs # Create the trace create_trace end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
5 6 7 |
# File 'lib/langfuse/trace.rb', line 5 def client @client end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/langfuse/trace.rb', line 5 def id @id end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
5 6 7 |
# File 'lib/langfuse/trace.rb', line 5 def input @input end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
5 6 7 |
# File 'lib/langfuse/trace.rb', line 5 def @metadata end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/langfuse/trace.rb', line 5 def name @name end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
5 6 7 |
# File 'lib/langfuse/trace.rb', line 5 def output @output end |
#public ⇒ Object (readonly)
Returns the value of attribute public.
5 6 7 |
# File 'lib/langfuse/trace.rb', line 5 def public @public end |
#release ⇒ Object (readonly)
Returns the value of attribute release.
5 6 7 |
# File 'lib/langfuse/trace.rb', line 5 def release @release end |
#session_id ⇒ Object (readonly)
Returns the value of attribute session_id.
5 6 7 |
# File 'lib/langfuse/trace.rb', line 5 def session_id @session_id end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
5 6 7 |
# File 'lib/langfuse/trace.rb', line 5 def @tags end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
5 6 7 |
# File 'lib/langfuse/trace.rb', line 5 def @timestamp end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
5 6 7 |
# File 'lib/langfuse/trace.rb', line 5 def user_id @user_id end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
5 6 7 |
# File 'lib/langfuse/trace.rb', line 5 def version @version end |
Instance Method Details
#agent(name: nil, start_time: nil, end_time: nil, input: nil, output: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) ⇒ Object
Create a child agent observation
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/langfuse/trace.rb', line 101 def agent(name: nil, start_time: nil, end_time: nil, input: nil, output: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) span( name: name, start_time: start_time, end_time: end_time, input: input, output: output, metadata: , level: level, status_message: , parent_observation_id: parent_observation_id, version: version, as_type: ObservationType::AGENT, **kwargs ) end |
#chain(name: nil, start_time: nil, end_time: nil, input: nil, output: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) ⇒ Object
Create a child chain observation
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/langfuse/trace.rb', line 141 def chain(name: nil, start_time: nil, end_time: nil, input: nil, output: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) span( name: name, start_time: start_time, end_time: end_time, input: input, output: output, metadata: , level: level, status_message: , parent_observation_id: parent_observation_id, version: version, as_type: ObservationType::CHAIN, **kwargs ) end |
#embedding(name: nil, start_time: nil, end_time: nil, input: nil, output: nil, model: nil, usage: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) ⇒ Object
Create a child embedding observation
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/langfuse/trace.rb', line 181 def (name: nil, start_time: nil, end_time: nil, input: nil, output: nil, model: nil, usage: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) = ( || {}).merge( { model: model, usage: usage }.compact ) span( name: name, start_time: start_time, end_time: end_time, input: input, output: output, metadata: .empty? ? nil : , level: level, status_message: , parent_observation_id: parent_observation_id, version: version, as_type: ObservationType::EMBEDDING, **kwargs ) end |
#evaluator(name: nil, start_time: nil, end_time: nil, input: nil, output: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) ⇒ Object
Create a child evaluator observation
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/langfuse/trace.rb', line 204 def evaluator(name: nil, start_time: nil, end_time: nil, input: nil, output: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) span( name: name, start_time: start_time, end_time: end_time, input: input, output: output, metadata: , level: level, status_message: , parent_observation_id: parent_observation_id, version: version, as_type: ObservationType::EVALUATOR, **kwargs ) end |
#event(name:, start_time: nil, input: nil, output: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) ⇒ Object
Create a child event
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/langfuse/trace.rb', line 81 def event(name:, start_time: nil, input: nil, output: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) @client.event( trace_id: @id, name: name, start_time: start_time, input: input, output: output, metadata: , level: level, status_message: , parent_observation_id: parent_observation_id, version: version, **kwargs ) end |
#generation(name: nil, start_time: nil, end_time: nil, completion_start_time: nil, model: nil, model_parameters: nil, input: nil, output: nil, usage: nil, usage_details: nil, cost_details: nil, prompt: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) ⇒ Object
Create a child generation
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/langfuse/trace.rb', line 52 def generation(name: nil, start_time: nil, end_time: nil, completion_start_time: nil, model: nil, model_parameters: nil, input: nil, output: nil, usage: nil, usage_details: nil, cost_details: nil, prompt: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) @client.generation( trace_id: @id, name: name, start_time: start_time, end_time: end_time, completion_start_time: completion_start_time, model: model, model_parameters: model_parameters, input: input, output: output, usage: usage, usage_details: usage_details, cost_details: cost_details, prompt: prompt, metadata: , level: level, status_message: , parent_observation_id: parent_observation_id, version: version, **kwargs ) end |
#get_url ⇒ Object
273 274 275 |
# File 'lib/langfuse/trace.rb', line 273 def get_url "#{@client.host}/trace/#{@id}" end |
#guardrail(name: nil, start_time: nil, end_time: nil, input: nil, output: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) ⇒ Object
Create a child guardrail observation
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/langfuse/trace.rb', line 224 def guardrail(name: nil, start_time: nil, end_time: nil, input: nil, output: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) span( name: name, start_time: start_time, end_time: end_time, input: input, output: output, metadata: , level: level, status_message: , parent_observation_id: parent_observation_id, version: version, as_type: ObservationType::GUARDRAIL, **kwargs ) end |
#retriever(name: nil, start_time: nil, end_time: nil, input: nil, output: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) ⇒ Object
Create a child retriever observation
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/langfuse/trace.rb', line 161 def retriever(name: nil, start_time: nil, end_time: nil, input: nil, output: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) span( name: name, start_time: start_time, end_time: end_time, input: input, output: output, metadata: , level: level, status_message: , parent_observation_id: parent_observation_id, version: version, as_type: ObservationType::RETRIEVER, **kwargs ) end |
#score(name:, value:, data_type: nil, comment: nil, **kwargs) ⇒ Object
243 244 245 246 247 248 249 250 251 252 |
# File 'lib/langfuse/trace.rb', line 243 def score(name:, value:, data_type: nil, comment: nil, **kwargs) @client.score( trace_id: @id, name: name, value: value, data_type: data_type, comment: comment, **kwargs ) end |
#span(name: nil, start_time: nil, end_time: nil, input: nil, output: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, as_type: nil, **kwargs) ⇒ Object
Create a child span with optional type
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/langfuse/trace.rb', line 31 def span(name: nil, start_time: nil, end_time: nil, input: nil, output: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, as_type: nil, **kwargs) @client.span( trace_id: @id, name: name, start_time: start_time, end_time: end_time, input: input, output: output, metadata: , level: level, status_message: , parent_observation_id: parent_observation_id, version: version, as_type: as_type, **kwargs ) end |
#to_dict ⇒ Object
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/langfuse/trace.rb', line 277 def to_dict { id: @id, name: @name, user_id: @user_id, session_id: @session_id, version: @version, release: @release, input: @input, output: @output, metadata: @metadata, tags: @tags, timestamp: @timestamp, public: @public }.merge(@kwargs).compact end |
#tool(name: nil, start_time: nil, end_time: nil, input: nil, output: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) ⇒ Object
Create a child tool observation
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/langfuse/trace.rb', line 121 def tool(name: nil, start_time: nil, end_time: nil, input: nil, output: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) span( name: name, start_time: start_time, end_time: end_time, input: input, output: output, metadata: , level: level, status_message: , parent_observation_id: parent_observation_id, version: version, as_type: ObservationType::TOOL, **kwargs ) end |
#update(name: nil, user_id: nil, session_id: nil, version: nil, release: nil, input: nil, output: nil, metadata: nil, tags: nil, public: nil, **kwargs) ⇒ Object
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/langfuse/trace.rb', line 254 def update(name: nil, user_id: nil, session_id: nil, version: nil, release: nil, input: nil, output: nil, metadata: nil, tags: nil, public: nil, **kwargs) # 更新实例变量 @name = name if name @user_id = user_id if user_id @session_id = session_id if session_id @version = version if version @release = release if release @input = input if input @output = output if output @metadata = if @tags = if @public = public unless public.nil? @kwargs.merge!(kwargs) if kwargs.any? # 触发 trace-update 事件 update_trace end |