inference_activity 1.0.2 → 1.0.4
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/inference_activity/version.rb +1 -1
- data/lib/inference_activity.rb +34 -26
- 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: 6bcc34079f0bc6196d753af6f6e4db32f181aad5a1cf5b770f75f3fe84f52306
|
|
4
|
+
data.tar.gz: 576cc9c88d15f05ab35c912c2b3f2fe21ebd018f8af85a8a9beb8d9e59169312
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f45f7e5f7f6f6e3863e1acc03d50381367536bb25b68b536fd3b300f9faa2204b98aabd3c1bcde5042b7c2d42b8c534470297d6cc5beee6fa00a72443c6df2ea
|
|
7
|
+
data.tar.gz: d9f0447a52814eea0f2f6d54f86878e3039cf6dc6d6af37a28d7a19f4a5d72ca79a85076edb6577918856747f22493880606978788310674faf5f5153bb16dd8
|
data/lib/inference_activity.rb
CHANGED
|
@@ -68,40 +68,47 @@ module InferenceActivity
|
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
def redact_response(response)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
71
|
+
if response.is_a?(Integer)
|
|
72
|
+
{
|
|
73
|
+
headers: {},
|
|
74
|
+
data: {}
|
|
75
|
+
}
|
|
76
|
+
else
|
|
77
|
+
data = parse_response_body(response)
|
|
78
|
+
uri = URI(response.uri)
|
|
79
|
+
|
|
80
|
+
if data.is_a?(Hash)
|
|
81
|
+
if uri.path.end_with?('/v1/chat/completions') && data['choices']
|
|
82
|
+
data['choices'] = data['choices'].map do |choice|
|
|
83
|
+
if choice['message']
|
|
84
|
+
choice.merge('message' => choice['message'].merge('content' => '[REDACTED]'))
|
|
85
|
+
else
|
|
86
|
+
choice
|
|
87
|
+
end
|
|
81
88
|
end
|
|
82
89
|
end
|
|
83
|
-
end
|
|
84
90
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
91
|
+
if uri.path.end_with?('/v1/embeddings') && data['data']
|
|
92
|
+
data['data'] = data['data'].map do |item|
|
|
93
|
+
item.merge('embedding' => '[REDACTED]')
|
|
94
|
+
end
|
|
88
95
|
end
|
|
89
|
-
end
|
|
90
96
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
+
if uri.path.end_with?('/v1/images/generations') && data['data']
|
|
98
|
+
data['data'] = data['data'].map do |item|
|
|
99
|
+
redacted = item.dup
|
|
100
|
+
redacted['b64_json'] = '[REDACTED]' if item.key?('b64_json')
|
|
101
|
+
redacted['revised_prompt'] = '[REDACTED]' if item.key?('revised_prompt')
|
|
102
|
+
redacted
|
|
103
|
+
end
|
|
97
104
|
end
|
|
98
105
|
end
|
|
99
|
-
end
|
|
100
106
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
107
|
+
{
|
|
108
|
+
headers: response.each_header.to_h,
|
|
109
|
+
data: data
|
|
110
|
+
}
|
|
111
|
+
end
|
|
105
112
|
end
|
|
106
113
|
|
|
107
114
|
def parse_request_body(request)
|
|
@@ -113,6 +120,7 @@ module InferenceActivity
|
|
|
113
120
|
end
|
|
114
121
|
|
|
115
122
|
def parse_response_body(response)
|
|
123
|
+
return {} if response.is_a?(Integer)
|
|
116
124
|
JSON.parse(response.body)
|
|
117
125
|
rescue JSON::ParserError
|
|
118
126
|
response.body
|