verica-observability 0.1.5 → 0.1.6
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/lib/verica/ruby_openai_wrapper.rb +32 -4
- data/lib/verica/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 820f96678415298ec28ca60e281ae11030e9b00430f5e3dde551dac6f631ce1a
|
|
4
|
+
data.tar.gz: 721b988d642ead26441fa349a1db35eb28033842e2c3f6ea65c6eab90152c692
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ce6fb5297710557c1a0fefc1ed8189737bd14fc5a7c6dc127fbd15002315f6e0da430a92d1675533acb8defedd4fc991f55d9fe2cfc821d3b760c94d4408e073
|
|
7
|
+
data.tar.gz: f23bf257a139e816217cd75a43cfa4c4db8ba869806e3668c26f505f342304db9238144e643e7000b6e3895bfc0fda389b3e881732f8b7db133cc44714cff0ec
|
|
@@ -77,10 +77,7 @@ module Verica
|
|
|
77
77
|
# usage chunk, without mutating any nested hash the caller passed.
|
|
78
78
|
def build_streaming_parameters(parameters, stream_key, accumulator)
|
|
79
79
|
user_proc = parameters[stream_key]
|
|
80
|
-
wrapped =
|
|
81
|
-
safely { accumulator.add(args.first) }
|
|
82
|
-
user_proc.call(*args)
|
|
83
|
-
end
|
|
80
|
+
wrapped = wrap_stream_callable(user_proc, accumulator)
|
|
84
81
|
|
|
85
82
|
copy = parameters.dup
|
|
86
83
|
copy[stream_key] = wrapped
|
|
@@ -98,6 +95,37 @@ module Verica
|
|
|
98
95
|
copy
|
|
99
96
|
end
|
|
100
97
|
|
|
98
|
+
# ruby-openai dispatches on the stream callable's ARITY: OpenAI::Stream
|
|
99
|
+
# (8.x, lib/openai/stream.rb) computes `user_proc.arity.abs` (Proc) or
|
|
100
|
+
# `user_proc.method(:call).arity.abs` (other callables) at construction and
|
|
101
|
+
# then calls `user_proc.call(*[chunk, event].first(arity))` — so an arity-1
|
|
102
|
+
# callable gets (chunk) and an arity-2 one gets (chunk, event). Our
|
|
103
|
+
# replacement must MIRROR the user callable's arity, or a strict 2-arity
|
|
104
|
+
# lambda (`->(chunk, _bytesize)`) behind our old splat proc (arity -1, abs
|
|
105
|
+
# 1) would receive ONE arg and raise ArgumentError — a caller-visible
|
|
106
|
+
# behavior change the fail-open contract forbids. Accumulation stays inside
|
|
107
|
+
# `safely`; the user's call stays outside it so their errors propagate.
|
|
108
|
+
def wrap_stream_callable(user_proc, accumulator)
|
|
109
|
+
arity = user_proc.respond_to?(:arity) ? user_proc.arity : user_proc.method(:call).arity
|
|
110
|
+
case arity
|
|
111
|
+
when 1
|
|
112
|
+
proc do |chunk|
|
|
113
|
+
safely { accumulator.add(chunk) }
|
|
114
|
+
user_proc.call(chunk)
|
|
115
|
+
end
|
|
116
|
+
when 2
|
|
117
|
+
proc do |chunk, bytesize|
|
|
118
|
+
safely { accumulator.add(chunk) }
|
|
119
|
+
user_proc.call(chunk, bytesize)
|
|
120
|
+
end
|
|
121
|
+
else
|
|
122
|
+
proc do |*args|
|
|
123
|
+
safely { accumulator.add(args.first) }
|
|
124
|
+
user_proc.call(*args)
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
101
129
|
def annotate(span, parameters, response, accumulator = nil)
|
|
102
130
|
cfg = Verica.config
|
|
103
131
|
model = parameters[:model] || parameters['model']
|
data/lib/verica/version.rb
CHANGED