gpt-function 0.5.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4382f4c9861d57510b154ab5179854eee8fad548dd849f3b283d870f736e599e
4
- data.tar.gz: 498b2499d3d6ecdb03847a6b5c15f9d2f99c231d59655f3cf8a602898d525102
3
+ metadata.gz: 6bba9981ceaa4edd441b41d6fe05ddf9f6a7a8545e66853fb7d863e600fd2c91
4
+ data.tar.gz: c5c729ddf3db4c76ba9d44edc6de991c68088ff054cc1e04a9d69ac95e368190
5
5
  SHA512:
6
- metadata.gz: 6ba7a96725e99edb9d87f9467011357fbd8e8e40dc62f902420b480334af7b432bf071e1b63df7ce5e0645611bcb6355caff08d275e9905a21a638ec6033cc06
7
- data.tar.gz: 680facff33d5f9737fb4dbc6cfc10a08e35f221245cb1e90c82a3e280c4ed32a0f1129d52561e471ca210f984a4c973b671aec01445d7776fdb5815e1d25339b
6
+ metadata.gz: 72266ef62eea0e2807de3fc3ddd1c7228b7e9115ca8ae3cc05e35b4526ff23afcb63e8b9f938828f3514a65ad1844d39f6421cd2569572a5a49c8c39e1b72215
7
+ data.tar.gz: b001c0c07bd574348abb06fbf68394dc42b830d7ed9be58622827fcd0518dcaa05cafc4fdee9837d5a49a4968a63205680cc01ad166b2850dfa94bf8b43befc4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gpt-function (0.4.0)
4
+ gpt-function (0.6.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -4,11 +4,6 @@
4
4
 
5
5
  你可以確保每次呼叫 GPT 函數時,接近 100% 都會得到相同的結果。
6
6
 
7
- 目前能夠使用的模型有:
8
-
9
- - gpt-4-1106-preview
10
- - gpt-3.5-turbo-1106
11
-
12
7
 
13
8
  ## Installation
14
9
 
@@ -99,20 +94,31 @@ end
99
94
  Batch Storage 整合 Active Record 的範例:
100
95
 
101
96
  ```ruby
102
- class Model < ApplicationRecord
97
+ class BatchStatus < ApplicationRecord
103
98
  class << self
104
99
  def enqueue(hash)
105
- create!(hash)
100
+ model = BatchStatus.new
101
+ model.batch_id = hash[:id]
102
+ model.status = hash[:status]
103
+ model.request_counts_completed = hash[:request_counts_completed]
104
+ model.request_counts_failed = hash[:request_counts_failed]
105
+ model.request_counts_total = hash[:request_counts_total]
106
+ model.metadata = hash[:metadata]
107
+ model.payload = hash
108
+ model.save
106
109
  true
107
110
  end
108
111
 
109
112
  def dequeue
110
- first&.destroy
113
+ model = first
114
+ model.destroy
115
+ model.payload
111
116
  end
112
117
  end
113
118
  end
114
119
 
115
- GptFunction.configure(api_key: '...', model: 'gpt-4o-mini', batch_storage: Model)
120
+
121
+ GptFunction.configure(api_key: '...', model: 'gpt-4o-mini', batch_storage: BatchStatus)
116
122
  ```
117
123
 
118
124
  ## License
@@ -102,6 +102,11 @@ class GptFunction
102
102
  @output_file ||= File.from_id(output_file_id)
103
103
  end
104
104
 
105
+ def error_file
106
+ return nil if error_file_id.nil?
107
+ @error_file ||= File.from_id(error_file_id)
108
+ end
109
+
105
110
  def input_jsonl
106
111
  @input_jsonl ||= input_file&.jsonl || []
107
112
  end
@@ -167,6 +172,10 @@ class GptFunction
167
172
  ["failed", "completed", "expired", "cancelled"].include? status
168
173
  end
169
174
 
175
+ def auto_delete
176
+ metadata&.dig("auto_delete") == "true"
177
+ end
178
+
170
179
  class << self
171
180
  def list(limit: 20, after: nil)
172
181
  # 創建批次請求
@@ -287,7 +296,13 @@ class GptFunction
287
296
  yield batch
288
297
 
289
298
  # 如果 batch 還未處理完成,將批次請求重新加入 Storage
290
- batch.enqueue unless batch.is_processed
299
+ if batch.is_processed && auto_delete
300
+ batch&.input_file&.delete rescue nil
301
+ batch&.output_file&.delete rescue nil
302
+ batch&.error_file&.delete rescue nil
303
+ else
304
+ batch.enqueue
305
+ end
291
306
  end
292
307
 
293
308
  true
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class GptFunction
4
- VERSION = "0.5.0"
4
+ VERSION = "0.7.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gpt-function
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - etrex kuo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-03 00:00:00.000000000 Z
11
+ date: 2024-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv