lluminary 0.1.1 → 0.1.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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/lib/lluminary/config.rb +11 -1
  3. data/lib/lluminary/field_description.rb +34 -29
  4. data/lib/lluminary/provider_error.rb +2 -1
  5. data/lib/lluminary/providers/base.rb +5 -1
  6. data/lib/lluminary/providers/bedrock.rb +32 -30
  7. data/lib/lluminary/providers/openai.rb +28 -21
  8. data/lib/lluminary/providers/test.rb +9 -14
  9. data/lib/lluminary/result.rb +5 -2
  10. data/lib/lluminary/schema.rb +9 -16
  11. data/lib/lluminary/schema_model.rb +13 -10
  12. data/lib/lluminary/task.rb +84 -59
  13. data/lib/lluminary/validation_error.rb +2 -1
  14. data/lib/lluminary/version.rb +3 -2
  15. data/lib/lluminary.rb +23 -7
  16. data/spec/examples/analyze_text_spec.rb +7 -4
  17. data/spec/examples/color_analyzer_spec.rb +22 -22
  18. data/spec/examples/content_analyzer_spec.rb +27 -44
  19. data/spec/examples/historical_event_analyzer_spec.rb +18 -15
  20. data/spec/examples/price_analyzer_spec.rb +22 -28
  21. data/spec/examples/quote_task_spec.rb +9 -8
  22. data/spec/examples/sentiment_analysis_spec.rb +13 -10
  23. data/spec/examples/summarize_text_spec.rb +7 -4
  24. data/spec/lluminary/config_spec.rb +28 -26
  25. data/spec/lluminary/field_description_spec.rb +19 -21
  26. data/spec/lluminary/providers/base_spec.rb +11 -8
  27. data/spec/lluminary/providers/bedrock_spec.rb +47 -57
  28. data/spec/lluminary/providers/openai_spec.rb +27 -35
  29. data/spec/lluminary/providers/test_spec.rb +21 -16
  30. data/spec/lluminary/result_spec.rb +17 -10
  31. data/spec/lluminary/schema_model_spec.rb +31 -22
  32. data/spec/lluminary/schema_spec.rb +95 -107
  33. data/spec/lluminary/task_spec.rb +366 -300
  34. data/spec/spec_helper.rb +7 -2
  35. metadata +35 -19
@@ -1,135 +1,133 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+ require "spec_helper"
2
3
 
3
4
  RSpec.describe Lluminary::Schema do
4
5
  let(:schema) { described_class.new }
5
6
 
6
- describe '#initialize' do
7
- it 'creates an empty fields hash' do
7
+ describe "#initialize" do
8
+ it "creates an empty fields hash" do
8
9
  expect(schema.fields).to eq({})
9
10
  end
10
11
  end
11
12
 
12
- describe '#string' do
13
- it 'adds a string field to the schema' do
13
+ describe "#string" do
14
+ it "adds a string field to the schema" do
14
15
  schema.string(:name)
15
16
  expect(schema.fields).to eq({ name: { type: :string, description: nil } })
16
17
  end
17
18
 
18
- it 'adds a string field with description' do
19
+ it "adds a string field with description" do
19
20
  schema.string(:name, description: "The user's full name")
20
- expect(schema.fields).to eq({
21
- name: {
22
- type: :string,
23
- description: "The user's full name"
24
- }
25
- })
21
+ expect(schema.fields).to eq(
22
+ { name: { type: :string, description: "The user's full name" } }
23
+ )
26
24
  end
27
25
  end
28
26
 
29
- describe '#integer' do
30
- it 'adds an integer field to the schema' do
27
+ describe "#integer" do
28
+ it "adds an integer field to the schema" do
31
29
  schema.integer(:count)
32
- expect(schema.fields).to eq({ count: { type: :integer, description: nil } })
30
+ expect(schema.fields).to eq(
31
+ { count: { type: :integer, description: nil } }
32
+ )
33
33
  end
34
34
 
35
- it 'adds an integer field with description' do
35
+ it "adds an integer field with description" do
36
36
  schema.integer(:count, description: "The total number of items")
37
- expect(schema.fields).to eq({
38
- count: {
39
- type: :integer,
40
- description: "The total number of items"
41
- }
42
- })
37
+ expect(schema.fields).to eq(
38
+ { count: { type: :integer, description: "The total number of items" } }
39
+ )
43
40
  end
44
41
  end
45
42
 
46
- describe '#boolean' do
47
- it 'adds a boolean field to the schema' do
43
+ describe "#boolean" do
44
+ it "adds a boolean field to the schema" do
48
45
  schema.boolean(:active)
49
- expect(schema.fields).to eq({ active: { type: :boolean, description: nil } })
46
+ expect(schema.fields).to eq(
47
+ { active: { type: :boolean, description: nil } }
48
+ )
50
49
  end
51
50
 
52
- it 'adds a boolean field with description' do
51
+ it "adds a boolean field with description" do
53
52
  schema.boolean(:active, description: "Whether the item is active")
54
- expect(schema.fields).to eq({
55
- active: {
56
- type: :boolean,
57
- description: "Whether the item is active"
58
- }
59
- })
53
+ expect(schema.fields).to eq(
54
+ {
55
+ active: {
56
+ type: :boolean,
57
+ description: "Whether the item is active"
58
+ }
59
+ }
60
+ )
60
61
  end
61
62
  end
62
63
 
63
- describe '#float' do
64
- it 'adds a float field to the schema' do
64
+ describe "#float" do
65
+ it "adds a float field to the schema" do
65
66
  schema.float(:price)
66
67
  expect(schema.fields).to eq({ price: { type: :float, description: nil } })
67
68
  end
68
69
 
69
- it 'adds a float field with description' do
70
+ it "adds a float field with description" do
70
71
  schema.float(:price, description: "The price of the item")
71
- expect(schema.fields).to eq({
72
- price: {
73
- type: :float,
74
- description: "The price of the item"
75
- }
76
- })
72
+ expect(schema.fields).to eq(
73
+ { price: { type: :float, description: "The price of the item" } }
74
+ )
77
75
  end
78
76
  end
79
77
 
80
- describe '#datetime' do
81
- it 'adds a datetime field to the schema' do
78
+ describe "#datetime" do
79
+ it "adds a datetime field to the schema" do
82
80
  schema.datetime(:start_time)
83
- expect(schema.fields).to eq({ start_time: { type: :datetime, description: nil } })
81
+ expect(schema.fields).to eq(
82
+ { start_time: { type: :datetime, description: nil } }
83
+ )
84
84
  end
85
85
 
86
- it 'adds a datetime field with description' do
86
+ it "adds a datetime field with description" do
87
87
  schema.datetime(:start_time, description: "When the event starts")
88
- expect(schema.fields).to eq({
89
- start_time: {
90
- type: :datetime,
91
- description: "When the event starts"
92
- }
93
- })
88
+ expect(schema.fields).to eq(
89
+ {
90
+ start_time: {
91
+ type: :datetime,
92
+ description: "When the event starts"
93
+ }
94
+ }
95
+ )
94
96
  end
95
97
  end
96
98
 
97
- describe '#fields' do
98
- it 'returns the fields hash' do
99
+ describe "#fields" do
100
+ it "returns the fields hash" do
99
101
  schema.string(:name)
100
102
  expect(schema.fields).to eq({ name: { type: :string, description: nil } })
101
103
  end
102
104
 
103
- it 'returns the same hash instance' do
105
+ it "returns the same hash instance" do
104
106
  schema.string(:name)
105
107
  first_call = schema.fields
106
108
  second_call = schema.fields
107
109
  expect(first_call).to be(second_call)
108
110
  end
109
111
 
110
- context 'with datetime fields' do
111
- let(:schema) do
112
- described_class.new.tap do |s|
113
- s.datetime(:start_time)
114
- end
115
- end
112
+ context "with datetime fields" do
113
+ let(:schema) { described_class.new.tap { |s| s.datetime(:start_time) } }
116
114
 
117
- it 'accepts DateTime values' do
115
+ it "accepts DateTime values" do
118
116
  errors = schema.validate(start_time: DateTime.now)
119
117
  expect(errors).to be_empty
120
118
  end
121
119
 
122
- it 'accepts nil values' do
120
+ it "accepts nil values" do
123
121
  errors = schema.validate(start_time: nil)
124
122
  expect(errors).to be_empty
125
123
  end
126
124
 
127
- it 'returns errors for non-DateTime values' do
125
+ it "returns errors for non-DateTime values" do
128
126
  errors = schema.validate(start_time: "2024-01-01")
129
127
  expect(errors).to contain_exactly("Start time must be a DateTime")
130
128
  end
131
129
 
132
- it 'can be required using presence validation' do
130
+ it "can be required using presence validation" do
133
131
  schema.validates :start_time, presence: true
134
132
  errors = schema.validate(start_time: nil)
135
133
  expect(errors).to contain_exactly("Start time can't be blank")
@@ -137,7 +135,7 @@ RSpec.describe Lluminary::Schema do
137
135
  end
138
136
  end
139
137
 
140
- describe '#validate' do
138
+ describe "#validate" do
141
139
  let(:schema) do
142
140
  described_class.new.tap do |s|
143
141
  s.string(:name)
@@ -145,12 +143,12 @@ RSpec.describe Lluminary::Schema do
145
143
  end
146
144
  end
147
145
 
148
- it 'returns no errors when all values match their field types' do
146
+ it "returns no errors when all values match their field types" do
149
147
  errors = schema.validate(name: "John", age: 30)
150
148
  expect(errors).to be_empty
151
149
  end
152
150
 
153
- it 'returns errors for type mismatches' do
151
+ it "returns errors for type mismatches" do
154
152
  errors = schema.validate(name: 123, age: "30")
155
153
  expect(errors).to contain_exactly(
156
154
  "Name must be a String",
@@ -158,95 +156,83 @@ RSpec.describe Lluminary::Schema do
158
156
  )
159
157
  end
160
158
 
161
- context 'with boolean fields' do
162
- let(:schema) do
163
- described_class.new.tap do |s|
164
- s.boolean(:active)
165
- end
166
- end
159
+ context "with boolean fields" do
160
+ let(:schema) { described_class.new.tap { |s| s.boolean(:active) } }
167
161
 
168
- it 'accepts true values' do
162
+ it "accepts true values" do
169
163
  errors = schema.validate(active: true)
170
164
  expect(errors).to be_empty
171
165
  end
172
166
 
173
- it 'accepts false values' do
167
+ it "accepts false values" do
174
168
  errors = schema.validate(active: false)
175
169
  expect(errors).to be_empty
176
170
  end
177
171
 
178
- it 'accepts nil values' do
172
+ it "accepts nil values" do
179
173
  errors = schema.validate(active: nil)
180
174
  expect(errors).to be_empty
181
175
  end
182
176
 
183
- it 'returns errors for non-boolean values' do
184
- errors = schema.validate(active: 'true')
177
+ it "returns errors for non-boolean values" do
178
+ errors = schema.validate(active: "true")
185
179
  expect(errors).to contain_exactly("Active must be true or false")
186
180
 
187
181
  errors = schema.validate(active: 1)
188
182
  expect(errors).to contain_exactly("Active must be true or false")
189
183
  end
190
184
 
191
- it 'can be required using presence validation' do
185
+ it "can be required using presence validation" do
192
186
  schema.validates :active, presence: true
193
187
  errors = schema.validate(active: nil)
194
188
  expect(errors).to contain_exactly("Active can't be blank")
195
189
  end
196
190
  end
197
191
 
198
- context 'with string fields' do
199
- let(:schema) do
200
- described_class.new.tap do |s|
201
- s.string(:name)
202
- end
203
- end
192
+ context "with string fields" do
193
+ let(:schema) { described_class.new.tap { |s| s.string(:name) } }
204
194
 
205
- it 'accepts string values' do
195
+ it "accepts string values" do
206
196
  errors = schema.validate(name: "John")
207
197
  expect(errors).to be_empty
208
198
  end
209
199
 
210
- it 'accepts nil values' do
200
+ it "accepts nil values" do
211
201
  errors = schema.validate(name: nil)
212
202
  expect(errors).to be_empty
213
203
  end
214
204
 
215
- it 'returns errors for non-string values' do
205
+ it "returns errors for non-string values" do
216
206
  errors = schema.validate(name: 123)
217
207
  expect(errors).to contain_exactly("Name must be a String")
218
208
  end
219
209
 
220
- it 'can be required using presence validation' do
210
+ it "can be required using presence validation" do
221
211
  schema.validates :name, presence: true
222
212
  errors = schema.validate(name: nil)
223
213
  expect(errors).to contain_exactly("Name can't be blank")
224
214
  end
225
215
  end
226
216
 
227
- context 'with integer fields' do
228
- let(:schema) do
229
- described_class.new.tap do |s|
230
- s.integer(:age)
231
- end
232
- end
217
+ context "with integer fields" do
218
+ let(:schema) { described_class.new.tap { |s| s.integer(:age) } }
233
219
 
234
- it 'accepts integer values' do
220
+ it "accepts integer values" do
235
221
  errors = schema.validate(age: 30)
236
222
  expect(errors).to be_empty
237
223
  end
238
224
 
239
- it 'accepts nil values' do
225
+ it "accepts nil values" do
240
226
  errors = schema.validate(age: nil)
241
227
  expect(errors).to be_empty
242
228
  end
243
229
 
244
- it 'returns errors for non-integer values' do
230
+ it "returns errors for non-integer values" do
245
231
  errors = schema.validate(age: "30")
246
232
  expect(errors).to contain_exactly("Age must be an Integer")
247
233
  end
248
234
 
249
- it 'can be required using presence validation' do
235
+ it "can be required using presence validation" do
250
236
  schema.validates :age, presence: true
251
237
  errors = schema.validate(age: nil)
252
238
  expect(errors).to contain_exactly("Age can't be blank")
@@ -254,7 +240,7 @@ RSpec.describe Lluminary::Schema do
254
240
  end
255
241
  end
256
242
 
257
- describe 'ActiveModel validations' do
243
+ describe "ActiveModel validations" do
258
244
  let(:schema) do
259
245
  described_class.new.tap do |s|
260
246
  s.string(:name)
@@ -265,12 +251,12 @@ RSpec.describe Lluminary::Schema do
265
251
  end
266
252
  end
267
253
 
268
- it 'generates a class that includes ActiveModel::Validations' do
254
+ it "generates a class that includes ActiveModel::Validations" do
269
255
  schema_model = schema.schema_model
270
256
  expect(schema_model.ancestors).to include(ActiveModel::Validations)
271
257
  end
272
258
 
273
- it 'adds accessors for defined fields' do
259
+ it "adds accessors for defined fields" do
274
260
  schema_model = schema.schema_model
275
261
  instance = schema_model.new
276
262
  instance.name = "John"
@@ -279,24 +265,26 @@ RSpec.describe Lluminary::Schema do
279
265
  expect(instance.age).to eq(30)
280
266
  end
281
267
 
282
- it 'validates presence' do
268
+ it "validates presence" do
283
269
  schema_model = schema.schema_model
284
270
  instance = schema_model.new
285
271
  expect(instance.valid?).to be false
286
272
  expect(instance.errors.full_messages).to include("Name can't be blank")
287
273
  end
288
274
 
289
- it 'validates numericality' do
275
+ it "validates numericality" do
290
276
  schema_model = schema.schema_model
291
277
  instance = schema_model.new(name: "John", age: 0)
292
278
  expect(instance.valid?).to be false
293
- expect(instance.errors.full_messages).to include("Age must be greater than 0")
279
+ expect(instance.errors.full_messages).to include(
280
+ "Age must be greater than 0"
281
+ )
294
282
  end
295
283
 
296
- it 'returns true for valid instances' do
284
+ it "returns true for valid instances" do
297
285
  schema_model = schema.schema_model
298
286
  instance = schema_model.new(name: "John", age: 30)
299
287
  expect(instance.valid?).to be true
300
288
  end
301
289
  end
302
- end
290
+ end