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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 179e07f9889543da9092844457585650ecef766cc9cbc8fdf10225c1606e3e30
4
- data.tar.gz: 99c8a02603324aa3c5b8fa14acd401483f8a0b8d67ef5f761d4785f7e37aed2d
3
+ metadata.gz: 820f96678415298ec28ca60e281ae11030e9b00430f5e3dde551dac6f631ce1a
4
+ data.tar.gz: 721b988d642ead26441fa349a1db35eb28033842e2c3f6ea65c6eab90152c692
5
5
  SHA512:
6
- metadata.gz: cb9b59ec8c73e36a93409399842b5554b54f0f9583d96583f219d1b0fa2c5fbd716e81fe791473bef6e317186bc083fded6e3f511e1a70cfde73216df154d9b8
7
- data.tar.gz: 286212de59d6b2aba37cf9e0ee9a149968c44b9c0a426e367b8e13552d751458d57efb8e0b1ffaed5e530ef0255473bbca342e23fb8c1dac7eedb76f4d0e2c3d
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 = proc do |*args|
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']
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Verica
4
- VERSION = '0.1.5'
4
+ VERSION = '0.1.6'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: verica-observability
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Verica