gpt-function 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gpt_function/batch.rb +8 -9
- data/lib/gpt_function/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: 4382f4c9861d57510b154ab5179854eee8fad548dd849f3b283d870f736e599e
|
4
|
+
data.tar.gz: 498b2499d3d6ecdb03847a6b5c15f9d2f99c231d59655f3cf8a602898d525102
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ba7a96725e99edb9d87f9467011357fbd8e8e40dc62f902420b480334af7b432bf071e1b63df7ce5e0645611bcb6355caff08d275e9905a21a638ec6033cc06
|
7
|
+
data.tar.gz: 680facff33d5f9737fb4dbc6cfc10a08e35f221245cb1e90c82a3e280c4ed32a0f1129d52561e471ca210f984a4c973b671aec01445d7776fdb5815e1d25339b
|
data/lib/gpt_function/batch.rb
CHANGED
@@ -28,8 +28,7 @@ class GptFunction
|
|
28
28
|
attr_reader :request_counts_completed
|
29
29
|
attr_reader :request_counts_failed
|
30
30
|
|
31
|
-
attr_reader :
|
32
|
-
attr_reader :metadata_batch_description
|
31
|
+
attr_reader :metadata
|
33
32
|
|
34
33
|
def initialize(hash)
|
35
34
|
@id = hash["id"]
|
@@ -55,8 +54,7 @@ class GptFunction
|
|
55
54
|
@request_counts_completed = hash.dig("request_counts", "completed")
|
56
55
|
@request_counts_failed = hash.dig("request_counts", "failed")
|
57
56
|
|
58
|
-
@
|
59
|
-
@metadata_batch_description = hash.dig("metadata", "batch_description")
|
57
|
+
@metadata = hash.dig("metadata")
|
60
58
|
end
|
61
59
|
|
62
60
|
def to_hash
|
@@ -82,8 +80,7 @@ class GptFunction
|
|
82
80
|
request_counts_total: request_counts_total,
|
83
81
|
request_counts_completed: request_counts_completed,
|
84
82
|
request_counts_failed: request_counts_failed,
|
85
|
-
|
86
|
-
metadata_batch_description: metadata_batch_description,
|
83
|
+
metadata: metadata
|
87
84
|
}
|
88
85
|
end
|
89
86
|
|
@@ -189,7 +186,7 @@ class GptFunction
|
|
189
186
|
end
|
190
187
|
end
|
191
188
|
|
192
|
-
def create(requests)
|
189
|
+
def create(requests, metadata: nil)
|
193
190
|
requests = requests.each_with_index.map do |request, index|
|
194
191
|
{
|
195
192
|
custom_id: "request-#{index + 1}",
|
@@ -206,11 +203,13 @@ class GptFunction
|
|
206
203
|
uri = URI('https://api.openai.com/v1/batches')
|
207
204
|
request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
|
208
205
|
request['Authorization'] = "Bearer #{GptFunction.api_key}"
|
209
|
-
|
206
|
+
body = {
|
210
207
|
input_file_id: file.id,
|
211
208
|
endpoint: '/v1/chat/completions',
|
212
209
|
completion_window: '24h'
|
213
|
-
}
|
210
|
+
}
|
211
|
+
body[:metadata] = metadata unless metadata.nil?
|
212
|
+
request.body = body.to_json
|
214
213
|
|
215
214
|
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
216
215
|
http.request(request)
|
data/lib/gpt_function/version.rb
CHANGED