foobara-ai 0.0.4 → 0.0.6
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/CHANGELOG.md +4 -0
- data/README.md +10 -3
- data/lib/foobara/ai.rb +38 -5
- data/src/foobara/ai/answer_bot/domain_mappers/model_to_ai_service.rb +6 -10
- data/src/foobara/ai/answer_bot/list_models.rb +8 -5
- data/src/foobara/ai/answer_bot/types/service_enum.rb +7 -5
- metadata +2 -4
- data/src/foobara/ai/answer_bot.rb +0 -9
- data/src/foobara/ai.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 719ee8692eed22e62bd0e301ca5f1e4727589a1fd72e560d25426c690cb9f22d
|
4
|
+
data.tar.gz: 25e9e0949d1dc59756d91356a0d7ff5f1c82a16bb4e4103a16233dd53257af63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59d758c93295a8b88a27cbb53c3b2931b2e4aa5dc6dc6d697a8d08f4f0a351619a37cb341ab082db4e670a760d479e30cdc10ee4e09cd45e2799404cc4d89d44
|
7
|
+
data.tar.gz: 99ebe34989602702326edb2680fa7b1755d2092ca6be63b2b2e35bec9739634aefafb8e574f8cc832f3590a2b92444902b7d3aff5525e45fc16744779703909d
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,18 +1,25 @@
|
|
1
1
|
# Foobara::Ai
|
2
2
|
|
3
|
-
|
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
|
-
>
|
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,41 @@
|
|
1
1
|
require "foobara/all"
|
2
|
-
require "foobara/open_ai_api"
|
3
|
-
require "foobara/anthropic_api"
|
4
|
-
require "foobara/ollama_api"
|
5
2
|
|
6
|
-
|
3
|
+
module Foobara
|
4
|
+
module Ai
|
5
|
+
foobara_organization!
|
7
6
|
|
8
|
-
|
7
|
+
module AnswerBot
|
8
|
+
foobara_domain!
|
9
|
+
|
10
|
+
require_relative "../../src/foobara/ai/answer_bot/types/service_enum"
|
11
|
+
|
12
|
+
ai_services = {}
|
13
|
+
|
14
|
+
Types::ServiceEnum.all_values.each do |service|
|
15
|
+
domain = case service
|
16
|
+
when Types::ServiceEnum::OPEN_AI
|
17
|
+
OpenAiApi
|
18
|
+
when Types::ServiceEnum::ANTHROPIC
|
19
|
+
AnthropicApi
|
20
|
+
when Types::ServiceEnum::OLLAMA
|
21
|
+
OllamaApi
|
22
|
+
end
|
23
|
+
|
24
|
+
ai_services[service] = domain
|
25
|
+
foobara_depends_on domain
|
26
|
+
end
|
27
|
+
|
28
|
+
AI_SERVICES = ai_services
|
29
|
+
|
30
|
+
base_dir = "#{__dir__}/../../src/foobara/ai/answer_bot"
|
31
|
+
Util.require_directory "#{base_dir}/types"
|
32
|
+
Dir["#{base_dir}/domain_mappers/*.rb"].each { |f| require f }
|
33
|
+
Dir["#{base_dir}/*.rb"].each { |f| require f }
|
34
|
+
|
35
|
+
AI_SERVICES.each_value do |domain|
|
36
|
+
path = Util.underscore(domain.foobara_domain_name)
|
37
|
+
Util.require_directory "#{base_dir}/domain_mappers/#{path}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -12,17 +12,13 @@ module Foobara
|
|
12
12
|
def map
|
13
13
|
symbol = model.to_sym
|
14
14
|
|
15
|
-
|
16
|
-
Types::
|
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
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require_relative "types/service_enum"
|
1
2
|
require_relative "types/model"
|
2
3
|
|
3
4
|
module Foobara
|
@@ -8,11 +9,13 @@ module Foobara
|
|
8
9
|
|
9
10
|
result [Types::Model]
|
10
11
|
|
11
|
-
LIST_COMMANDS =
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
LIST_COMMANDS = AI_SERVICES.values.map do |domain|
|
13
|
+
if domain == OllamaApi
|
14
|
+
OllamaApi::ListLocalModels
|
15
|
+
else
|
16
|
+
domain::ListModels
|
17
|
+
end
|
18
|
+
end
|
16
19
|
|
17
20
|
depends_on(*LIST_COMMANDS)
|
18
21
|
|
@@ -2,11 +2,13 @@ module Foobara
|
|
2
2
|
module Ai
|
3
3
|
module AnswerBot
|
4
4
|
module Types
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
+
version: 0.0.6
|
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.
|
107
|
+
rubygems_version: 3.6.5
|
110
108
|
specification_version: 4
|
111
109
|
summary: No description. Add one.
|
112
110
|
test_files: []
|