active_cortex 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d69240425c3faa7beaf76c5fc9b48beea6d9b5d3ec032ac01d874b5b240b1754
4
- data.tar.gz: 2507aff2c4a6ed7b8d32cbcb2372d9fc3a759e5d43ad568df0633553a0825f66
3
+ metadata.gz: c1020861a0627f8c3df3db06459b51287e067cb8ecee1a3c9ee412e80aa374d9
4
+ data.tar.gz: 6e6c36fff9beec9b256f8bae8b72e118da33b4b6a4535cbe6574c09d8561489f
5
5
  SHA512:
6
- metadata.gz: 15c2ba257de168c3aeedcc494ae796575d881e4dade4affc4017075bb0dc1678e544c98d058f5750606b64cfcd1f9ba24f274784e2b988c8c950af85e530f3fc
7
- data.tar.gz: f78d0887c9f2890089fea953a4a199b31720fee26e603521022552035e2969b07631c8c52baced8b70b30639f70b3d5d4fbada1266b324254a2c6aff17c7c88d
6
+ metadata.gz: 6536b4dc37ff820006cc77d9d0f15255640dc6be9732bdbcbf1e7e1262f33b650f42c174f593592db979cc0fc8a9e47fbdbc6733c824a9fd50676a44bb42d21e
7
+ data.tar.gz: ea9d43ad9662b87f6262d2df69fedfbead2e5a171a6d7e8effd1f64d8043e8f3ab185eefc34e6d43dfd63c7c2fd94883c4f9137ec531ea1082156fbf71b9cd95
@@ -0,0 +1,45 @@
1
+ class ActiveCortex::Generator::Boolean < ActiveCortex::Generator
2
+ def self.accepts?(record:, field_name:)
3
+ record.class.attribute_types[field_name.to_s].type == :boolean
4
+ end
5
+
6
+ def self.generate(record:, field_name:)
7
+ record.send("#{field_name}=", generation)
8
+ end
9
+
10
+ def generation
11
+ openai_content || raise(ActiveCortex::Error, openai_error_message)
12
+ end
13
+
14
+ private
15
+
16
+ def convert_to_boolean(content)
17
+ case content
18
+ when "Yes", "yes", "True", "true", "1"
19
+ true
20
+ when "No", "no", "False", "false", "0"
21
+ false
22
+ else
23
+ raise ActiveCortex::Error, "Could not convert content to boolean: #{content}"
24
+ end
25
+ end
26
+
27
+ def openai_content
28
+ convert_to_boolean(openai_response["choices"][0]["message"]["content"])
29
+ rescue
30
+ nil
31
+ end
32
+
33
+ def openai_error_message
34
+ "Error from OpenAI. " + { response: openai_response }.to_json
35
+ end
36
+
37
+ def openai_response
38
+ @openai_response ||= openai_client.chat(parameters: {
39
+ model: model,
40
+ messages: [
41
+ { role: "user", content: prompt }
42
+ ],
43
+ })
44
+ end
45
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveCortex
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/active_cortex.rb CHANGED
@@ -4,6 +4,7 @@ require "active_cortex/railtie"
4
4
  require "active_cortex/generator"
5
5
  require "active_cortex/generator/text"
6
6
  require "active_cortex/generator/has_many"
7
+ require "active_cortex/generator/boolean"
7
8
  require "active_cortex/model"
8
9
 
9
10
  module ActiveCortex
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_cortex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ori Marash
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-20 00:00:00.000000000 Z
11
+ date: 2024-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -65,6 +65,7 @@ files:
65
65
  - lib/active_cortex.rb
66
66
  - lib/active_cortex/config.rb
67
67
  - lib/active_cortex/generator.rb
68
+ - lib/active_cortex/generator/boolean.rb
68
69
  - lib/active_cortex/generator/has_many.rb
69
70
  - lib/active_cortex/generator/text.rb
70
71
  - lib/active_cortex/model.rb