langfuse-ruby 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +8 -8
- data/CHANGELOG.md +21 -0
- data/Gemfile.lock +5 -1
- data/README.md +6 -1
- data/docs/URL_ENCODING_FIX.md +164 -0
- data/examples/basic_tracing.rb +1 -1
- data/examples/url_encoding_demo.rb +57 -0
- data/langfuse-ruby.gemspec +5 -2
- data/lib/langfuse/client.rb +157 -2
- data/lib/langfuse/event.rb +21 -5
- data/lib/langfuse/generation.rb +155 -5
- data/lib/langfuse/observation_types.rb +61 -0
- data/lib/langfuse/span.rb +162 -7
- data/lib/langfuse/trace.rb +150 -1
- data/lib/langfuse/utils.rb +5 -0
- data/lib/langfuse/version.rb +1 -1
- data/lib/langfuse.rb +1 -0
- data/test_offline.rb +1 -1
- metadata +20 -3
data/lib/langfuse/trace.rb
CHANGED
|
@@ -24,9 +24,10 @@ module Langfuse
|
|
|
24
24
|
create_trace
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
+
# Create a child span with optional type
|
|
27
28
|
def span(name: nil, start_time: nil, end_time: nil, input: nil, output: nil,
|
|
28
29
|
metadata: nil, level: nil, status_message: nil, parent_observation_id: nil,
|
|
29
|
-
version: nil, **kwargs)
|
|
30
|
+
version: nil, as_type: nil, **kwargs)
|
|
30
31
|
@client.span(
|
|
31
32
|
trace_id: @id,
|
|
32
33
|
name: name,
|
|
@@ -39,10 +40,12 @@ module Langfuse
|
|
|
39
40
|
status_message: status_message,
|
|
40
41
|
parent_observation_id: parent_observation_id,
|
|
41
42
|
version: version,
|
|
43
|
+
as_type: as_type,
|
|
42
44
|
**kwargs
|
|
43
45
|
)
|
|
44
46
|
end
|
|
45
47
|
|
|
48
|
+
# Create a child generation
|
|
46
49
|
def generation(name: nil, start_time: nil, end_time: nil, completion_start_time: nil,
|
|
47
50
|
model: nil, model_parameters: nil, input: nil, output: nil, usage: nil,
|
|
48
51
|
metadata: nil, level: nil, status_message: nil, parent_observation_id: nil,
|
|
@@ -67,6 +70,7 @@ module Langfuse
|
|
|
67
70
|
)
|
|
68
71
|
end
|
|
69
72
|
|
|
73
|
+
# Create a child event
|
|
70
74
|
def event(name:, start_time: nil, input: nil, output: nil, metadata: nil,
|
|
71
75
|
level: nil, status_message: nil, parent_observation_id: nil, version: nil, **kwargs)
|
|
72
76
|
@client.event(
|
|
@@ -84,6 +88,151 @@ module Langfuse
|
|
|
84
88
|
)
|
|
85
89
|
end
|
|
86
90
|
|
|
91
|
+
# Convenience methods for enhanced observation types
|
|
92
|
+
|
|
93
|
+
# Create a child agent observation
|
|
94
|
+
def agent(name: nil, start_time: nil, end_time: nil, input: nil, output: nil,
|
|
95
|
+
metadata: nil, level: nil, status_message: nil, parent_observation_id: nil,
|
|
96
|
+
version: nil, **kwargs)
|
|
97
|
+
span(
|
|
98
|
+
name: name,
|
|
99
|
+
start_time: start_time,
|
|
100
|
+
end_time: end_time,
|
|
101
|
+
input: input,
|
|
102
|
+
output: output,
|
|
103
|
+
metadata: metadata,
|
|
104
|
+
level: level,
|
|
105
|
+
status_message: status_message,
|
|
106
|
+
parent_observation_id: parent_observation_id,
|
|
107
|
+
version: version,
|
|
108
|
+
as_type: ObservationType::AGENT,
|
|
109
|
+
**kwargs
|
|
110
|
+
)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# Create a child tool observation
|
|
114
|
+
def tool(name: nil, start_time: nil, end_time: nil, input: nil, output: nil,
|
|
115
|
+
metadata: nil, level: nil, status_message: nil, parent_observation_id: nil,
|
|
116
|
+
version: nil, **kwargs)
|
|
117
|
+
span(
|
|
118
|
+
name: name,
|
|
119
|
+
start_time: start_time,
|
|
120
|
+
end_time: end_time,
|
|
121
|
+
input: input,
|
|
122
|
+
output: output,
|
|
123
|
+
metadata: metadata,
|
|
124
|
+
level: level,
|
|
125
|
+
status_message: status_message,
|
|
126
|
+
parent_observation_id: parent_observation_id,
|
|
127
|
+
version: version,
|
|
128
|
+
as_type: ObservationType::TOOL,
|
|
129
|
+
**kwargs
|
|
130
|
+
)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# Create a child chain observation
|
|
134
|
+
def chain(name: nil, start_time: nil, end_time: nil, input: nil, output: nil,
|
|
135
|
+
metadata: nil, level: nil, status_message: nil, parent_observation_id: nil,
|
|
136
|
+
version: nil, **kwargs)
|
|
137
|
+
span(
|
|
138
|
+
name: name,
|
|
139
|
+
start_time: start_time,
|
|
140
|
+
end_time: end_time,
|
|
141
|
+
input: input,
|
|
142
|
+
output: output,
|
|
143
|
+
metadata: metadata,
|
|
144
|
+
level: level,
|
|
145
|
+
status_message: status_message,
|
|
146
|
+
parent_observation_id: parent_observation_id,
|
|
147
|
+
version: version,
|
|
148
|
+
as_type: ObservationType::CHAIN,
|
|
149
|
+
**kwargs
|
|
150
|
+
)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# Create a child retriever observation
|
|
154
|
+
def retriever(name: nil, start_time: nil, end_time: nil, input: nil, output: nil,
|
|
155
|
+
metadata: nil, level: nil, status_message: nil, parent_observation_id: nil,
|
|
156
|
+
version: nil, **kwargs)
|
|
157
|
+
span(
|
|
158
|
+
name: name,
|
|
159
|
+
start_time: start_time,
|
|
160
|
+
end_time: end_time,
|
|
161
|
+
input: input,
|
|
162
|
+
output: output,
|
|
163
|
+
metadata: metadata,
|
|
164
|
+
level: level,
|
|
165
|
+
status_message: status_message,
|
|
166
|
+
parent_observation_id: parent_observation_id,
|
|
167
|
+
version: version,
|
|
168
|
+
as_type: ObservationType::RETRIEVER,
|
|
169
|
+
**kwargs
|
|
170
|
+
)
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
# Create a child embedding observation
|
|
174
|
+
def embedding(name: nil, start_time: nil, end_time: nil, input: nil, output: nil,
|
|
175
|
+
model: nil, usage: nil, metadata: nil, level: nil, status_message: nil,
|
|
176
|
+
parent_observation_id: nil, version: nil, **kwargs)
|
|
177
|
+
merged_metadata = (metadata || {}).merge(
|
|
178
|
+
{ model: model, usage: usage }.compact
|
|
179
|
+
)
|
|
180
|
+
span(
|
|
181
|
+
name: name,
|
|
182
|
+
start_time: start_time,
|
|
183
|
+
end_time: end_time,
|
|
184
|
+
input: input,
|
|
185
|
+
output: output,
|
|
186
|
+
metadata: merged_metadata.empty? ? nil : merged_metadata,
|
|
187
|
+
level: level,
|
|
188
|
+
status_message: status_message,
|
|
189
|
+
parent_observation_id: parent_observation_id,
|
|
190
|
+
version: version,
|
|
191
|
+
as_type: ObservationType::EMBEDDING,
|
|
192
|
+
**kwargs
|
|
193
|
+
)
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
# Create a child evaluator observation
|
|
197
|
+
def evaluator(name: nil, start_time: nil, end_time: nil, input: nil, output: nil,
|
|
198
|
+
metadata: nil, level: nil, status_message: nil, parent_observation_id: nil,
|
|
199
|
+
version: nil, **kwargs)
|
|
200
|
+
span(
|
|
201
|
+
name: name,
|
|
202
|
+
start_time: start_time,
|
|
203
|
+
end_time: end_time,
|
|
204
|
+
input: input,
|
|
205
|
+
output: output,
|
|
206
|
+
metadata: metadata,
|
|
207
|
+
level: level,
|
|
208
|
+
status_message: status_message,
|
|
209
|
+
parent_observation_id: parent_observation_id,
|
|
210
|
+
version: version,
|
|
211
|
+
as_type: ObservationType::EVALUATOR,
|
|
212
|
+
**kwargs
|
|
213
|
+
)
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
# Create a child guardrail observation
|
|
217
|
+
def guardrail(name: nil, start_time: nil, end_time: nil, input: nil, output: nil,
|
|
218
|
+
metadata: nil, level: nil, status_message: nil, parent_observation_id: nil,
|
|
219
|
+
version: nil, **kwargs)
|
|
220
|
+
span(
|
|
221
|
+
name: name,
|
|
222
|
+
start_time: start_time,
|
|
223
|
+
end_time: end_time,
|
|
224
|
+
input: input,
|
|
225
|
+
output: output,
|
|
226
|
+
metadata: metadata,
|
|
227
|
+
level: level,
|
|
228
|
+
status_message: status_message,
|
|
229
|
+
parent_observation_id: parent_observation_id,
|
|
230
|
+
version: version,
|
|
231
|
+
as_type: ObservationType::GUARDRAIL,
|
|
232
|
+
**kwargs
|
|
233
|
+
)
|
|
234
|
+
end
|
|
235
|
+
|
|
87
236
|
def score(name:, value:, data_type: nil, comment: nil, **kwargs)
|
|
88
237
|
@client.score(
|
|
89
238
|
trace_id: @id,
|
data/lib/langfuse/utils.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require 'securerandom'
|
|
2
2
|
require 'time'
|
|
3
|
+
require 'erb'
|
|
3
4
|
|
|
4
5
|
module Langfuse
|
|
5
6
|
module Utils
|
|
@@ -12,6 +13,10 @@ module Langfuse
|
|
|
12
13
|
Time.now.utc.iso8601(3)
|
|
13
14
|
end
|
|
14
15
|
|
|
16
|
+
def url_encode(string)
|
|
17
|
+
ERB::Util.url_encode(string.to_s)
|
|
18
|
+
end
|
|
19
|
+
|
|
15
20
|
def deep_symbolize_keys(hash)
|
|
16
21
|
return hash unless hash.is_a?(Hash)
|
|
17
22
|
|
data/lib/langfuse/version.rb
CHANGED
data/lib/langfuse.rb
CHANGED
data/test_offline.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: langfuse-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Richard Sun
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
11
|
+
date: 2025-12-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: concurrent-ruby
|
|
@@ -64,6 +64,20 @@ dependencies:
|
|
|
64
64
|
- - "<"
|
|
65
65
|
- !ruby/object:Gem::Version
|
|
66
66
|
version: '4.0'
|
|
67
|
+
- !ruby/object:Gem::Dependency
|
|
68
|
+
name: faraday-multipart
|
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - "~>"
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: '1.0'
|
|
74
|
+
type: :runtime
|
|
75
|
+
prerelease: false
|
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
77
|
+
requirements:
|
|
78
|
+
- - "~>"
|
|
79
|
+
- !ruby/object:Gem::Version
|
|
80
|
+
version: '1.0'
|
|
67
81
|
- !ruby/object:Gem::Dependency
|
|
68
82
|
name: json
|
|
69
83
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -198,11 +212,13 @@ files:
|
|
|
198
212
|
- docs/README.md
|
|
199
213
|
- docs/RELEASE_CHECKLIST.md
|
|
200
214
|
- docs/TYPE_VALIDATION_TROUBLESHOOTING.md
|
|
215
|
+
- docs/URL_ENCODING_FIX.md
|
|
201
216
|
- examples/auto_flush_control.rb
|
|
202
217
|
- examples/basic_tracing.rb
|
|
203
218
|
- examples/connection_config_demo.rb
|
|
204
219
|
- examples/event_usage.rb
|
|
205
220
|
- examples/prompt_management.rb
|
|
221
|
+
- examples/url_encoding_demo.rb
|
|
206
222
|
- langfuse-ruby.gemspec
|
|
207
223
|
- lib/langfuse.rb
|
|
208
224
|
- lib/langfuse/client.rb
|
|
@@ -210,6 +226,7 @@ files:
|
|
|
210
226
|
- lib/langfuse/evaluation.rb
|
|
211
227
|
- lib/langfuse/event.rb
|
|
212
228
|
- lib/langfuse/generation.rb
|
|
229
|
+
- lib/langfuse/observation_types.rb
|
|
213
230
|
- lib/langfuse/prompt.rb
|
|
214
231
|
- lib/langfuse/span.rb
|
|
215
232
|
- lib/langfuse/trace.rb
|
|
@@ -236,7 +253,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
236
253
|
requirements:
|
|
237
254
|
- - ">="
|
|
238
255
|
- !ruby/object:Gem::Version
|
|
239
|
-
version:
|
|
256
|
+
version: 3.1.0
|
|
240
257
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
241
258
|
requirements:
|
|
242
259
|
- - ">="
|