omniai-openai 1.3.1 → 1.3.2
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 +19 -1
- data/lib/omniai/openai/assistant.rb +1 -1
- data/lib/omniai/openai/thread/messages.rb +1 -1
- data/lib/omniai/openai/thread/run.rb +47 -0
- data/lib/omniai/openai/thread/runs.rb +1 -1
- data/lib/omniai/openai/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: 7cb12222b6c13b368f2f25d55c66ff57e98114830a32bdd54ee82947aaf38674
|
4
|
+
data.tar.gz: 7600584957b977be573321a25a995f720fde9e9112fdd3e1b8676ce3d75461e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75f8bdbfff09e789058e15bf962efcbbe0146b3e522e5efc701ca1303ef734b68f6d19094502c2e8fd89f5db213687b6c5001967e3dfd1b46eaab060b4c4e4c0
|
7
|
+
data.tar.gz: 5b206397432e32277bda4767bad41707699607cf93e9a396570cbe78ab668f42b5c34c75f99d26d93cccd042b9c08359a899a4f375fabae7fc6c55a587515550
|
data/README.md
CHANGED
@@ -268,8 +268,17 @@ client.files.all
|
|
268
268
|
|
269
269
|
### Uploading a File
|
270
270
|
|
271
|
+
#### Using a File
|
272
|
+
|
273
|
+
```ruby
|
274
|
+
file = client.files.build(io: File.open('demo.pdf', 'wb'))
|
275
|
+
file.save!
|
276
|
+
```
|
277
|
+
|
278
|
+
#### Using a Path
|
279
|
+
|
271
280
|
```ruby
|
272
|
-
file = client.files.build(io:
|
281
|
+
file = client.files.build(io: 'demo.pdf'))
|
273
282
|
file.save!
|
274
283
|
```
|
275
284
|
|
@@ -428,6 +437,15 @@ run.metadata = { user: 'Ringo' }
|
|
428
437
|
run.save!
|
429
438
|
```
|
430
439
|
|
440
|
+
#### Polling a Run
|
441
|
+
|
442
|
+
```ruby
|
443
|
+
run.terminated? # false
|
444
|
+
run.poll!
|
445
|
+
run.terminated? # true
|
446
|
+
run.status # 'cancelled' / 'failed' / 'completed' / 'expired'
|
447
|
+
```
|
448
|
+
|
431
449
|
#### Cancelling a Run
|
432
450
|
|
433
451
|
```ruby
|
@@ -5,6 +5,20 @@ module OmniAI
|
|
5
5
|
class Thread
|
6
6
|
# An OpenAI run within a thread.
|
7
7
|
class Run
|
8
|
+
module Status
|
9
|
+
CANCELLED = 'cancelled'
|
10
|
+
FAILED = 'failed'
|
11
|
+
COMPLETED = 'completed'
|
12
|
+
EXPIRED = 'expired'
|
13
|
+
end
|
14
|
+
|
15
|
+
TERMINATED_STATUSES = [
|
16
|
+
Status::CANCELLED,
|
17
|
+
Status::FAILED,
|
18
|
+
Status::COMPLETED,
|
19
|
+
Status::EXPIRED,
|
20
|
+
].freeze
|
21
|
+
|
8
22
|
# @!attribute [rw] id
|
9
23
|
# @return [String, nil]
|
10
24
|
attr_accessor :id
|
@@ -143,6 +157,22 @@ module OmniAI
|
|
143
157
|
self
|
144
158
|
end
|
145
159
|
|
160
|
+
# @raise [HTTPError]
|
161
|
+
# @return [OmniAI::OpenAI::Thread]
|
162
|
+
def reload!
|
163
|
+
raise Error, 'unable to fetch! without an ID' unless @id
|
164
|
+
|
165
|
+
response = @client.connection
|
166
|
+
.accept(:json)
|
167
|
+
.headers(HEADERS)
|
168
|
+
.get(path)
|
169
|
+
|
170
|
+
raise HTTPError, response.flush unless response.status.ok?
|
171
|
+
|
172
|
+
parse(data: response.parse)
|
173
|
+
self
|
174
|
+
end
|
175
|
+
|
146
176
|
# @raise [OmniAI::Error]
|
147
177
|
# @return [OmniAI::OpenAI::Thread]
|
148
178
|
def cancel!
|
@@ -153,6 +183,23 @@ module OmniAI
|
|
153
183
|
self
|
154
184
|
end
|
155
185
|
|
186
|
+
# @param interval [Integer, Float, nil] optional (seconds)
|
187
|
+
#
|
188
|
+
# @return [OmniAI::OpenAI::Thread::Run]
|
189
|
+
def poll!(delay: 2)
|
190
|
+
loop do
|
191
|
+
reload!
|
192
|
+
break if terminated?
|
193
|
+
|
194
|
+
sleep(delay) if delay
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
# @return [Boolean]
|
199
|
+
def terminated?
|
200
|
+
TERMINATED_STATUSES.include?(@status)
|
201
|
+
end
|
202
|
+
|
156
203
|
private
|
157
204
|
|
158
205
|
class << self
|