payloop 0.0.2 → 0.0.3
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/CHANGELOG.md +5 -0
- data/lib/payloop/client.rb +1 -6
- data/lib/payloop/version.rb +1 -1
- data/lib/payloop/wrappers/base.rb +37 -4
- data/lib/payloop/wrappers/google.rb +18 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 79647d261089034fcabaf8bc8f02468c22a4dafac253f0e3b387bf169f0fe410
|
|
4
|
+
data.tar.gz: 5d7796139816c6f880d0acfa0e364065480835def4e1f98fa9fd30004a1cab6b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e87d2509afeee593b39cd9ab7a519f2fde382aaa939fecaa370cf4817aa38009a5c68a3550444052dbf0867a6162c6a3cd5771cfb039a4f812b280a9e3bb29f6
|
|
7
|
+
data.tar.gz: d7ac74462b724bce7178e6588d41bb6e91e4bf5ec98ff067bd41164cf17b4fd570892eacdb633b797fc3aab1857503cd4cf88998ad95d675be647980fd0f85d0
|
data/CHANGELOG.md
CHANGED
|
@@ -25,3 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
25
25
|
|
|
26
26
|
### Fixed
|
|
27
27
|
- Corrected Payloop request payload structure as needed
|
|
28
|
+
|
|
29
|
+
## [0.0.3] - 2025-10-27
|
|
30
|
+
|
|
31
|
+
### Fixed
|
|
32
|
+
- Corrected Payloop request payload structure for Google GenAI
|
data/lib/payloop/client.rb
CHANGED
|
@@ -36,12 +36,7 @@ module Payloop
|
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
# Set attribution for cost tracking
|
|
39
|
-
def attribution(parent_id:, parent_name: nil, subsidiary_id: nil, subsidiary_name: nil
|
|
40
|
-
parent_uuid: nil, subsidiary_uuid: nil)
|
|
41
|
-
# Support deprecated parameters
|
|
42
|
-
parent_id ||= parent_uuid
|
|
43
|
-
subsidiary_id ||= subsidiary_uuid
|
|
44
|
-
|
|
39
|
+
def attribution(parent_id:, parent_name: nil, subsidiary_id: nil, subsidiary_name: nil)
|
|
45
40
|
attr = Attribution.new(
|
|
46
41
|
parent_id: parent_id,
|
|
47
42
|
parent_name: parent_name,
|
data/lib/payloop/version.rb
CHANGED
|
@@ -100,16 +100,49 @@ module Payloop
|
|
|
100
100
|
when String
|
|
101
101
|
{ text: response }
|
|
102
102
|
else
|
|
103
|
-
|
|
103
|
+
# Try various serialization methods
|
|
104
|
+
if response.respond_to?(:as_json)
|
|
105
|
+
deep_copy(response.as_json)
|
|
106
|
+
elsif response.respond_to?(:to_h)
|
|
104
107
|
deep_copy(response.to_h)
|
|
105
108
|
elsif response.respond_to?(:to_hash)
|
|
106
109
|
deep_copy(response.to_hash)
|
|
107
110
|
else
|
|
108
|
-
|
|
111
|
+
# Extract instance variables for objects without serialization methods
|
|
112
|
+
extract_instance_variables(response)
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
rescue StandardError => e
|
|
116
|
+
# If extraction fails, try to provide useful debug info
|
|
117
|
+
{ raw: response.to_s, error: e.message }
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def extract_instance_variables(obj)
|
|
121
|
+
result = {}
|
|
122
|
+
obj.instance_variables.each do |var|
|
|
123
|
+
key = var.to_s.delete("@").to_sym
|
|
124
|
+
value = obj.instance_variable_get(var)
|
|
125
|
+
result[key] = serialize_value(value)
|
|
126
|
+
end
|
|
127
|
+
result
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def serialize_value(value)
|
|
131
|
+
case value
|
|
132
|
+
when Hash
|
|
133
|
+
value.transform_values { |v| serialize_value(v) }
|
|
134
|
+
when Array
|
|
135
|
+
value.map { |v| serialize_value(v) }
|
|
136
|
+
when String, Numeric, TrueClass, FalseClass, NilClass
|
|
137
|
+
value
|
|
138
|
+
else
|
|
139
|
+
# Recursively extract instance variables for nested objects
|
|
140
|
+
if value.respond_to?(:instance_variables)
|
|
141
|
+
extract_instance_variables(value)
|
|
142
|
+
else
|
|
143
|
+
value.to_s
|
|
109
144
|
end
|
|
110
145
|
end
|
|
111
|
-
rescue StandardError
|
|
112
|
-
{ raw: response.to_s }
|
|
113
146
|
end
|
|
114
147
|
|
|
115
148
|
def deep_copy(obj)
|
|
@@ -4,7 +4,7 @@ require_relative "constants"
|
|
|
4
4
|
|
|
5
5
|
module Payloop
|
|
6
6
|
module Wrappers
|
|
7
|
-
# Wrapper for Google GenerativeAI Ruby client
|
|
7
|
+
# Wrapper for Google GenerativeAI Ruby client (google-genai gem)
|
|
8
8
|
class Google
|
|
9
9
|
def initialize(config, collector)
|
|
10
10
|
@config = config
|
|
@@ -17,6 +17,9 @@ module Payloop
|
|
|
17
17
|
# Prevent double registration
|
|
18
18
|
return client if client.instance_variable_defined?(:@payloop_registered)
|
|
19
19
|
|
|
20
|
+
# Patch response class after client is validated (ensures gem is loaded)
|
|
21
|
+
patch_response_class!
|
|
22
|
+
|
|
20
23
|
# Store references in client instance
|
|
21
24
|
client.instance_variable_set(:@payloop_config, @config)
|
|
22
25
|
client.instance_variable_set(:@payloop_collector, @collector)
|
|
@@ -37,6 +40,20 @@ module Payloop
|
|
|
37
40
|
"Client does not appear to be a valid Google GenAI client (missing models method)"
|
|
38
41
|
end
|
|
39
42
|
|
|
43
|
+
# Monkey-patch the GenerateContentResponse class to include missing fields
|
|
44
|
+
def patch_response_class!
|
|
45
|
+
# Check if the constant exists and hasn't been patched yet
|
|
46
|
+
return unless defined?(::Google::Genai::Types::GenerateContentResponse)
|
|
47
|
+
return if ::Google::Genai::Types::GenerateContentResponse.instance_variable_defined?(:@_payloop_patched)
|
|
48
|
+
|
|
49
|
+
::Google::Genai::Types::GenerateContentResponse.class_eval do
|
|
50
|
+
# Use camelCase to match Google's API response keys
|
|
51
|
+
attr_accessor :modelVersion, :usageMetadata, :responseId, :createTime
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
::Google::Genai::Types::GenerateContentResponse.instance_variable_set(:@_payloop_patched, true)
|
|
55
|
+
end
|
|
56
|
+
|
|
40
57
|
def wrap_generate_content_method(client)
|
|
41
58
|
# Get the models resource
|
|
42
59
|
models_resource = client.models
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: payloop
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Payloop
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-10-
|
|
11
|
+
date: 2025-10-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: concurrent-ruby
|