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 +4 -4
- data/Gemfile.lock +1 -1
- 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: 6bba9981ceaa4edd441b41d6fe05ddf9f6a7a8545e66853fb7d863e600fd2c91
|
4
|
+
data.tar.gz: c5c729ddf3db4c76ba9d44edc6de991c68088ff054cc1e04a9d69ac95e368190
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72266ef62eea0e2807de3fc3ddd1c7228b7e9115ca8ae3cc05e35b4526ff23afcb63e8b9f938828f3514a65ad1844d39f6421cd2569572a5a49c8c39e1b72215
|
7
|
+
data.tar.gz: b001c0c07bd574348abb06fbf68394dc42b830d7ed9be58622827fcd0518dcaa05cafc4fdee9837d5a49a4968a63205680cc01ad166b2850dfa94bf8b43befc4
|
data/Gemfile.lock
CHANGED
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") == "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.
|
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.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-
|
11
|
+
date: 2024-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|