foobara-ai 0.0.4 → 0.0.5

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: a04cb75747f713b682ced3aef91fc7f5630f8fa5173abb755762d883b56d33b6
4
- data.tar.gz: cbfa07fc11c8e1b3f56dcfb6f1a98ec7a3d7fb2a3ad15b1923df1e972b3667a5
3
+ metadata.gz: ac867a51c46b2b89c3dc90dba0584d0c78d9a3aa480a249cd45828abb5baccc5
4
+ data.tar.gz: c727dff343804bafbb0a300274a80780b4717e89e98441f77ba1aa3516c392fd
5
5
  SHA512:
6
- metadata.gz: ddb7e385fc1f5b1a8f45d71e0d62a50b325822b551d781820d389461a73ae42c88a8765be843d76049c721f36f4621abd462679c9af2f789e18e332837f42faf
7
- data.tar.gz: 3a127986f25ad800cb10db0534026271c79462f8f7a6385db276905f25012925009f4946d96f0f4b4809061134e5a1586e870cbf02f9b25a10a8935b0c22efd5
6
+ metadata.gz: 7f6af8aa55bcfdd3b289729e7c31dbb3e2fb5a35cb11d05c9cf633e9d985d015d0f8ae080deec313bdfc85fc1f33111de15052e1175bb6f09922e6b734474be7
7
+ data.tar.gz: e3034cc9ff62eaafe2d12a9ce7a148e1389d001363c3050937f656b2d8720c4492a48e2d36df10a001a3ad2003948cbb301fd06707f798090af2f81dfb56142a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.0.5] - 2025-03-04
2
+
3
+ - Do not require all 3 services to function. Let user require which services they want to use.
4
+
1
5
  ## [0.0.4] - 2025-03-04
2
6
 
3
7
  - Add an instructions input that translates to a system prompt
data/README.md CHANGED
@@ -1,18 +1,25 @@
1
1
  # Foobara::Ai
2
2
 
3
- Currently, gives an Ask command based on the foobara code demo. Allows one
3
+ Implements a simple mental model of asking LLM services a question and getting an answer. Allows one
4
4
  to ask a question and get an answer while specifying which service to use as
5
5
  its implementation.
6
6
 
7
7
  ## Installation
8
8
 
9
9
  Typical stuff. Add `gem "foobara-ai"` to your Gemfile or .gemspec. Or if using in a local script you can also
10
- `gem install foobara-ai`
10
+ `gem install foobara-ai`. You also need to do the same for some combination of foobara-open-ai-api,
11
+ foobara-anthropic-api, or foobara-ollama-api, depending on which models you wish to ask against.
11
12
 
12
13
  ## Usage
13
14
 
15
+ You need to require whichever services you want to use before requiring foobara/ai.
16
+
14
17
  ```ruby
15
- > result = Ask.run!(question: "What is the pH of honey?", service: "open-ai")
18
+ > require "foobara/open_ai_api"
19
+ > require "foobara/anthropic_api"
20
+ > require "foobara/ollama_api"
21
+ > require "foobara/ai"
22
+ > result = Ask.run!(question: "What is the pH of honey?", model: "gpt-3.5-turbo")
16
23
  > puts result
17
24
  The pH of honey typically ranges between 3.2 and 4.5.
18
25
  >
data/lib/foobara/ai.rb CHANGED
@@ -1,8 +1,37 @@
1
1
  require "foobara/all"
2
- require "foobara/open_ai_api"
3
- require "foobara/anthropic_api"
4
- require "foobara/ollama_api"
5
2
 
6
- require_relative "../../src/foobara/ai/answer_bot"
3
+ module Foobara
4
+ module Ai
5
+ foobara_organization!
7
6
 
8
- Foobara::Util.require_directory "#{__dir__}/../../src"
7
+ module AnswerBot
8
+ foobara_domain!
9
+
10
+ base_dir = "#{__dir__}/../../src/foobara/ai/answer_bot"
11
+ Util.require_directory "#{base_dir}/types"
12
+ Dir["#{base_dir}/domain_mappers/*.rb"].each { |f| require f }
13
+ Dir["#{base_dir}/*.rb"].each { |f| require f }
14
+
15
+ ai_services = {}
16
+
17
+ Types::ServiceEnum.all_values.each do |service|
18
+ domain = case service
19
+ when Types::ServiceEnum::OPEN_AI
20
+ OpenAiApi
21
+ when Types::ServiceEnum::ANTHROPIC
22
+ AnthropicApi
23
+ when Types::ServiceEnum::OLLAMA
24
+ OllamaApi
25
+ end
26
+
27
+ ai_services[service] = domain
28
+ foobara_depends_on domain
29
+
30
+ path = Util.underscore(domain.foobara_domain_name)
31
+ Util.require_directory "#{__dir__}/../../src/foobara/ai/answer_bot/domain_mappers/#{path}"
32
+ end
33
+
34
+ AI_SERVICES = ai_services
35
+ end
36
+ end
37
+ end
@@ -12,17 +12,13 @@ module Foobara
12
12
  def map
13
13
  symbol = model.to_sym
14
14
 
15
- if Ai::OpenAiApi::Types::ModelEnum.value?(symbol)
16
- Types::ServiceEnum::OPEN_AI
17
- elsif Ai::AnthropicApi::Types::ModelEnum.value?(symbol)
18
- Types::ServiceEnum::ANTHROPIC
19
- elsif Ai::OllamaApi::Types::ModelEnum.value?(symbol)
20
- Types::ServiceEnum::OLLAMA
21
- else
22
- # :nocov:
23
- raise "Unknown model: #{model}"
24
- # :nocov:
15
+ AnswerBot::AI_SERVICES.each_pair do |service, domain|
16
+ return service if domain::Types::ModelEnum.value?(symbol)
25
17
  end
18
+
19
+ # :nocov:
20
+ raise "Unknown model: #{model}"
21
+ # :nocov:
26
22
  end
27
23
 
28
24
  alias model from
@@ -2,11 +2,13 @@ module Foobara
2
2
  module Ai
3
3
  module AnswerBot
4
4
  module Types
5
- ServiceEnum = Foobara::Enumerated.make_module(
6
- "anthropic",
7
- "open-ai",
8
- "ollama"
9
- )
5
+ services = []
6
+
7
+ services << "open-ai" if defined?(Foobara::Ai::OpenAiApi)
8
+ services << "anthropic" if defined?(Foobara::Ai::AnthropicApi)
9
+ services << "ollama" if defined?(Foobara::Ai::OllamaApi)
10
+
11
+ ServiceEnum = Foobara::Enumerated.make_module(services)
10
12
  end
11
13
 
12
14
  foobara_register_type(:service_enum, :symbol, one_of: Types::ServiceEnum)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara-ai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
@@ -62,8 +62,6 @@ files:
62
62
  - LICENSE.txt
63
63
  - README.md
64
64
  - lib/foobara/ai.rb
65
- - src/foobara/ai.rb
66
- - src/foobara/ai/answer_bot.rb
67
65
  - src/foobara/ai/answer_bot/ask.rb
68
66
  - src/foobara/ai/answer_bot/domain_mappers/anthropic_api/message_result_to_answer.rb
69
67
  - src/foobara/ai/answer_bot/domain_mappers/anthropic_api/model_to_foobara_model.rb
@@ -106,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
104
  - !ruby/object:Gem::Version
107
105
  version: '0'
108
106
  requirements: []
109
- rubygems_version: 3.6.3
107
+ rubygems_version: 3.6.5
110
108
  specification_version: 4
111
109
  summary: No description. Add one.
112
110
  test_files: []
@@ -1,9 +0,0 @@
1
- module Foobara
2
- module Ai
3
- module AnswerBot
4
- foobara_domain!
5
-
6
- foobara_depends_on OpenAiApi, AnthropicApi, OllamaApi
7
- end
8
- end
9
- end
data/src/foobara/ai.rb DELETED
@@ -1,5 +0,0 @@
1
- module Foobara
2
- module Ai
3
- foobara_organization!
4
- end
5
- end