ox-ai-workers 0.6.0 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 173694a4b29ea7a2c690add1cdbf322d62b005427c1310f5ea6dde2dea0a8c81
4
- data.tar.gz: 1687d91cffe2ca48a50a4b5669ab3bcf2874a2e8b649d668a7ee6a3806e3eb8f
3
+ metadata.gz: 811df931f990a04c2764d1e5dc952e69e1dfc409bfe942ff87822ef8b755a6c9
4
+ data.tar.gz: 1d591cc02bec476f76707de96acadd58bb0cda60a1af0bf6657150e9360e02e0
5
5
  SHA512:
6
- metadata.gz: a162f9ef5c72938e502cd5c491a018643d75f833aad9a767388d222e440526b33d85aac263d9db4ab3448429ce97e16fba90bf1a70358c672ac4fe4c1b74b22d
7
- data.tar.gz: 8c807fdaac63f3c75cfe770b966ac3e1f6e537a7a4942d253ee2385b449ce0c37205ecd98e07c68e8aa4a0b1a2b3dd86c53a2355d2378b3e6e6e21b0b9d83f8a
6
+ metadata.gz: e4629630ea656bb07ab2da027852ebc262901e7dfb09d27b73071727eed149c850a3b4f40c03e094792c630f32642f9dc2c8c5a6786b5283e4a03916b8c47f8b
7
+ data.tar.gz: c57849c113e05f41fad7a51ab17b86878a27b61b4f7abff08dbac478114efe2ba697fce94ebfff23551931e982d07ae7e2d808d54adb3f28424bc29381b574d7
data/CHANGELOG.md CHANGED
@@ -1,4 +1,6 @@
1
- ## [Unreleased]
1
+ ## [0.6.2] - 2024-08-024
2
+
3
+ - Rails ActiveRecord support
2
4
 
3
5
  ## [0.6.0] - 2024-08-02
4
6
 
data/README.md CHANGED
@@ -179,6 +179,53 @@ As a worker, you can use different classes depending on your needs:
179
179
 
180
180
  - `OxAiWorkers::DelayedRequest`: This class is used for batch API requests, ideal for operations that do not require immediate execution. Using `DelayedRequest` can save up to 50% on costs as requests are executed when the remote server is less busy, but no later than within 24 hours.
181
181
 
182
+ ### Rails Projects with DelayedRequest
183
+
184
+ Generate your model to store the `batch_id` in the database:
185
+
186
+ ```bash
187
+ rails generate model MyRequestWithStore batch_id:string
188
+ ```
189
+
190
+ In your `app/models/my_request_with_store.rb` file, add the following code:
191
+
192
+ ```ruby
193
+ class MyRequestWithStore < ApplicationRecord
194
+ def delayed_request
195
+ @worker ||= OxAiWorkers::DelayedRequest.new(batch_id: self.batch_id)
196
+ end
197
+ end
198
+ ```
199
+
200
+ Then you can use the iterator like this:
201
+
202
+ ```ruby
203
+ # Fetch the first stored batch
204
+ my_store = MyRequestWithStore.first
205
+
206
+ # Get the worker
207
+ my_worker = my_store.delayed_request
208
+
209
+ # Create the iterator
210
+ iterator = OxAiWorkers::Iterator.new(worker: my_worker)
211
+ # ... use the iterator
212
+
213
+ # Destroy the store after completion
214
+ my_store.destroy if my_worker.completed?
215
+ ```
216
+
217
+ To store your batches in the database, use the following code:
218
+
219
+ ```ruby
220
+ # Get the worker from the iterator
221
+ my_worker = iterator.worker
222
+
223
+ # Store the batch_id if it's not completed
224
+ unless my_worker.completed?
225
+ my_store = MyRequestWithStore.create!(batch_id: my_worker.batch_id)
226
+ end
227
+ ```
228
+
182
229
  ## Command Line Interface (CLI)
183
230
 
184
231
  1. Navigate to the required directory.
@@ -52,6 +52,8 @@ module OxAiWorkers
52
52
  cleanup
53
53
 
54
54
  super()
55
+
56
+ tick_or_wait if requested?
55
57
  end
56
58
 
57
59
  #
@@ -168,6 +170,10 @@ module OxAiWorkers
168
170
 
169
171
  def external_request
170
172
  @worker.request!
173
+ tick_or_wait
174
+ end
175
+
176
+ def tick_or_wait
171
177
  if OxAiWorkers.configuration.wait_for_complete
172
178
  wait_for_complete
173
179
  else
@@ -7,7 +7,7 @@ module OxAiWorkers
7
7
  include OxAiWorkers::StateHelper
8
8
  extend StateMachines::MacroMethods
9
9
 
10
- state_machine :state, initial: :idle do
10
+ state_machine :state, initial: ->(t) { t.worker.requested? ? :requested : :idle } do
11
11
  before_transition from: any, do: :log_me
12
12
 
13
13
  after_transition on: :iterate, do: :next_iteration
@@ -0,0 +1,35 @@
1
+ # def getDocument doc1, &block
2
+ # document = getFileBin(doc1)
3
+ # content = nil
4
+ # unless document.nil?
5
+ # extension = doc1['file_name'].split('.').last.downcase
6
+ # if extension == "docx"
7
+ # docx = Docx::Document.open document#.read
8
+ # content = docx.instance_variable_get("@doc").xpath('//w:document//w:body').children.map{ |c|
9
+ # if c.name == 'p' # paragraph
10
+ # paragraph = docx.send(:parse_paragraph_from, c)
11
+ # ReverseMarkdown.convert(paragraph.to_html).strip
12
+ # elsif c.name = 'tbl' # table
13
+ # table = docx.send(:parse_table_from, c)
14
+ # table.rows.map { |row| row.cells.map { |cell| cell.paragraphs.map(&:text).reject { |c| c.empty? }.join("\\n ") }.join(" | ") }.join("\n")
15
+ # else # other types?
16
+ # c.content
17
+ # end
18
+ # }.reject { |c| c.empty? }.join("\n\n")
19
+ # #content = ReverseMarkdown.convert(docx.to_html)
20
+ # makeTempFileWithContent(content, ["file_#{@current_user.id}", ".txt"]) do |file|
21
+ # yield(content, doc1['file_name'], file)
22
+ # end
23
+ # elsif %w[xlsx xls ods].include?(extension)
24
+ # xlsx = Roo::Spreadsheet.open document, extension: extension.to_sym
25
+ # content = xlsx.to_csv
26
+ # makeTempFileWithContent(content, ["file_#{@current_user.id}", ".csv"]) do |file|
27
+ # yield(content, doc1['file_name'], file)
28
+ # end
29
+ # elsif %w[csv txt ini asc log kicad_sch cpp h rb c hpp erb md yml].include?(extension)
30
+ # yield(document.read.force_encoding("UTF-8"), doc1['file_name'], nil)
31
+ # else
32
+ # yield(nil, doc1['file_name'], nil)
33
+ # end
34
+ # end
35
+ # end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OxAiWorkers
4
- VERSION = '0.6.0'
4
+ VERSION = '0.6.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ox-ai-workers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Smolev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-09 00:00:00.000000000 Z
11
+ date: 2024-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -156,6 +156,7 @@ files:
156
156
  - lib/oxaiworkers/state_batch.rb
157
157
  - lib/oxaiworkers/state_helper.rb
158
158
  - lib/oxaiworkers/state_tools.rb
159
+ - lib/oxaiworkers/tool/converter.rb
159
160
  - lib/oxaiworkers/tool/database.rb
160
161
  - lib/oxaiworkers/tool/eval.rb
161
162
  - lib/oxaiworkers/tool/file_system.rb