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 +4 -4
- data/README.md +15 -9
- data/lib/gpt_function/batch.rb +16 -1
- data/lib/gpt_function/version.rb +1 -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: 61133cf0bb081bfcc03dc1e0b2a69bbc7f043c7dc6fd9c5e56d0d9734c975575
|
4
|
+
data.tar.gz: b153cad22540e8b2ad46293c8dffc1aa63b27d48f87a60cb46a9d6cc869abc5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
97
|
+
class BatchStatus < ApplicationRecord
|
103
98
|
class << self
|
104
99
|
def enqueue(hash)
|
105
|
-
|
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
|
113
|
+
model = first
|
114
|
+
model.destroy
|
115
|
+
model.payload
|
111
116
|
end
|
112
117
|
end
|
113
118
|
end
|
114
119
|
|
115
|
-
|
120
|
+
|
121
|
+
GptFunction.configure(api_key: '...', model: 'gpt-4o-mini', batch_storage: BatchStatus)
|
116
122
|
```
|
117
123
|
|
118
124
|
## License
|
data/lib/gpt_function/batch.rb
CHANGED
@@ -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.
|
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
|
data/lib/gpt_function/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2024-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|