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.
-
#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
- #event(name:, start_time: nil, input: nil, output: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) ⇒ Object
- #generation(name: nil, start_time: nil, end_time: nil, completion_start_time: nil, model: nil, model_parameters: nil, input: nil, output: nil, usage: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) ⇒ Object
- #get_url ⇒ Object
-
#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, **kwargs) ⇒ Trace
constructor
A new instance of Trace.
- #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, **kwargs) ⇒ Object
- #to_dict ⇒ Object
- #update(name: nil, user_id: nil, session_id: nil, version: nil, release: nil, input: nil, output: nil, metadata: nil, tags: 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, **kwargs) ⇒ Trace
Returns a new instance of Trace.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/langfuse/trace.rb', line 6 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, **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 = @kwargs = kwargs # Create the trace create_trace end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
3 4 5 |
# File 'lib/langfuse/trace.rb', line 3 def client @client end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/langfuse/trace.rb', line 3 def id @id end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
3 4 5 |
# File 'lib/langfuse/trace.rb', line 3 def input @input end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
3 4 5 |
# File 'lib/langfuse/trace.rb', line 3 def @metadata end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/langfuse/trace.rb', line 3 def name @name end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
3 4 5 |
# File 'lib/langfuse/trace.rb', line 3 def output @output end |
#release ⇒ Object (readonly)
Returns the value of attribute release.
3 4 5 |
# File 'lib/langfuse/trace.rb', line 3 def release @release end |
#session_id ⇒ Object (readonly)
Returns the value of attribute session_id.
3 4 5 |
# File 'lib/langfuse/trace.rb', line 3 def session_id @session_id end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
3 4 5 |
# File 'lib/langfuse/trace.rb', line 3 def @tags end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
3 4 5 |
# File 'lib/langfuse/trace.rb', line 3 def @timestamp end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
3 4 5 |
# File 'lib/langfuse/trace.rb', line 3 def user_id @user_id end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
3 4 5 |
# File 'lib/langfuse/trace.rb', line 3 def version @version end |
Instance Method Details
#event(name:, start_time: nil, input: nil, output: nil, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/langfuse/trace.rb', line 70 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, metadata: nil, level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/langfuse/trace.rb', line 46 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, 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, metadata: , level: level, status_message: , parent_observation_id: parent_observation_id, version: version, **kwargs ) end |
#get_url ⇒ Object
115 116 117 |
# File 'lib/langfuse/trace.rb', line 115 def get_url "#{@client.host}/trace/#{@id}" end |
#score(name:, value:, data_type: nil, comment: nil, **kwargs) ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/langfuse/trace.rb', line 87 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, **kwargs) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/langfuse/trace.rb', line 27 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, **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, **kwargs ) end |
#to_dict ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/langfuse/trace.rb', line 119 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 }.merge(@kwargs).compact end |
#update(name: nil, user_id: nil, session_id: nil, version: nil, release: nil, input: nil, output: nil, metadata: nil, tags: nil, **kwargs) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/langfuse/trace.rb', line 98 def update(name: nil, user_id: nil, session_id: nil, version: nil, release: nil, input: nil, output: nil, metadata: nil, tags: 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 @kwargs.merge!(kwargs) if kwargs.any? # 触发 trace-update 事件 update_trace end |