gpt-function 0.5.0 → 0.6.0

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: 4382f4c9861d57510b154ab5179854eee8fad548dd849f3b283d870f736e599e
4
- data.tar.gz: 498b2499d3d6ecdb03847a6b5c15f9d2f99c231d59655f3cf8a602898d525102
3
+ metadata.gz: 61133cf0bb081bfcc03dc1e0b2a69bbc7f043c7dc6fd9c5e56d0d9734c975575
4
+ data.tar.gz: b153cad22540e8b2ad46293c8dffc1aa63b27d48f87a60cb46a9d6cc869abc5d
5
5
  SHA512:
6
- metadata.gz: 6ba7a96725e99edb9d87f9467011357fbd8e8e40dc62f902420b480334af7b432bf071e1b63df7ce5e0645611bcb6355caff08d275e9905a21a638ec6033cc06
7
- data.tar.gz: 680facff33d5f9737fb4dbc6cfc10a08e35f221245cb1e90c82a3e280c4ed32a0f1129d52561e471ca210f984a4c973b671aec01445d7776fdb5815e1d25339b
6
+ metadata.gz: 69fed6886b79e1b3e0034d3de36273b0bddc6b1ff59bb03067b737621ee85030ad334ceea48d72b9173025661f92f3f05d396d921720a4ee45a9f74dc7e9da50
7
+ data.tar.gz: f375fa50fc60c54663e8c488385541caa711ee97cae76495c885b734ce826fe79dc703d13f3594e54a7d44371be6e1f7458990a527b1095fe562a7195b011df4
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") || false
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.6.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.6.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