foobara-ai 0.0.13 → 1.0.0
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 +8 -0
- data/lib/foobara/ai.rb +3 -22
- data/src/foobara/ai/answer_bot/ask.rb +1 -1
- data/src/foobara/ai/answer_bot/domain_mappers/open_ai_api/chat_to_generate_chat_completion.rb +7 -1
- data/src/foobara/ai/answer_bot/generate_next_message.rb +1 -1
- data/src/foobara/ai.rb +50 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa2a8e4b0d4b634506aa49974927e7a3aecd0ba36b7992b27e58d051264e4cd7
|
4
|
+
data.tar.gz: 593b5f446f52e566f7e77821e2873c5561e38e6ae10e595a547896def58ab493
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37b829fa773865a26180bf8ae386973b7f6062a89dd5aab090ad5e866a2b8dab7a6e471e759164ea714fbc25fac203b3d26c36197def11eb4dd2d7775f8caf27
|
7
|
+
data.tar.gz: 4c054fbbfacf099659792bfd3158ae31a6ebfeaf51625d41c13c64e9c1820adea2e474ffdc0a09d319e2a96c1ffeb63775ac4ecb25167b664ee7ac7a00bbae00
|
data/CHANGELOG.md
CHANGED
data/lib/foobara/ai.rb
CHANGED
@@ -7,33 +7,14 @@ module Foobara
|
|
7
7
|
module AnswerBot
|
8
8
|
foobara_domain!
|
9
9
|
|
10
|
-
require_relative "../../src/foobara/ai
|
10
|
+
require_relative "../../src/foobara/ai"
|
11
11
|
|
12
|
-
|
12
|
+
AI_SERVICES = Ai.installed_ai_services
|
13
13
|
|
14
|
-
|
15
|
-
ai_services[Types::ServiceEnum::OPEN_AI] = OpenAiApi
|
16
|
-
end
|
17
|
-
if defined?(Foobara::Ai::AnthropicApi)
|
18
|
-
ai_services[Types::ServiceEnum::ANTHROPIC] = AnthropicApi
|
19
|
-
end
|
20
|
-
if defined?(Foobara::Ai::OllamaApi)
|
21
|
-
ai_services[Types::ServiceEnum::OLLAMA] = OllamaApi
|
22
|
-
end
|
23
|
-
|
24
|
-
if ai_services.empty?
|
25
|
-
# :nocov:
|
26
|
-
require "foobara/anthropic_api"
|
27
|
-
ai_services = { Types::ServiceEnum::ANTHROPIC => AnthropicApi }
|
28
|
-
# :nocov:
|
29
|
-
end
|
30
|
-
|
31
|
-
ai_services.each_value do |domain|
|
14
|
+
AI_SERVICES.each_value do |domain|
|
32
15
|
foobara_depends_on domain
|
33
16
|
end
|
34
17
|
|
35
|
-
AI_SERVICES = ai_services
|
36
|
-
|
37
18
|
base_dir = "#{__dir__}/../../src/foobara/ai/answer_bot"
|
38
19
|
|
39
20
|
AI_SERVICES.each_value do |domain|
|
@@ -8,7 +8,7 @@ module Foobara
|
|
8
8
|
question :string, :required, "whatever you want to know!"
|
9
9
|
instructions :string, "Results in a system prompt. You can specify how you want the LLM to behave."
|
10
10
|
service :service_enum, "If two services expose the same model, you can specify which one to use."
|
11
|
-
model :model_enum, default:
|
11
|
+
model :model_enum, default: Ai.default_llm_model, description: "The model to use."
|
12
12
|
end
|
13
13
|
|
14
14
|
result :string
|
data/src/foobara/ai/answer_bot/domain_mappers/open_ai_api/chat_to_generate_chat_completion.rb
CHANGED
@@ -21,7 +21,9 @@ module Foobara
|
|
21
21
|
}
|
22
22
|
|
23
23
|
if temperature
|
24
|
-
|
24
|
+
# NOTE: some models don't support temperature, like o1. Instead of possibly receiving an error
|
25
|
+
# we will set the temperature to 1 which prevents a 400. Maybe print a warning instead?
|
26
|
+
inputs[:temperature] = model_supports_temperature? ? temperature : 1
|
25
27
|
end
|
26
28
|
|
27
29
|
if model
|
@@ -42,6 +44,10 @@ module Foobara
|
|
42
44
|
def model
|
43
45
|
from[:model]
|
44
46
|
end
|
47
|
+
|
48
|
+
def model_supports_temperature?
|
49
|
+
model && model.to_s !~ /\Ao1(-|$)/
|
50
|
+
end
|
45
51
|
end
|
46
52
|
end
|
47
53
|
end
|
@@ -7,7 +7,7 @@ module Foobara
|
|
7
7
|
inputs do
|
8
8
|
chat Types::Chat, :required
|
9
9
|
service :service_enum, "If two services expose the same model, you can specify which one to use."
|
10
|
-
model :model_enum, default:
|
10
|
+
model :model_enum, default: Ai.default_llm_model, description: "The model to use."
|
11
11
|
temperature :float
|
12
12
|
end
|
13
13
|
|
data/src/foobara/ai.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require_relative "ai/answer_bot/types/service_enum"
|
2
|
+
|
3
|
+
module Foobara
|
4
|
+
module Ai
|
5
|
+
class << self
|
6
|
+
def anthropic_setup?
|
7
|
+
defined?(Ai::AnthropicApi)
|
8
|
+
end
|
9
|
+
|
10
|
+
def open_ai_setup?
|
11
|
+
defined?(Ai::OpenAiApi)
|
12
|
+
end
|
13
|
+
|
14
|
+
def ollama_setup?
|
15
|
+
defined?(Ai::OllamaApi)
|
16
|
+
end
|
17
|
+
|
18
|
+
def installed_ai_services
|
19
|
+
return @ai_services if @ai_services
|
20
|
+
|
21
|
+
@ai_services = {}
|
22
|
+
|
23
|
+
if anthropic_setup?
|
24
|
+
@ai_services[AnswerBot::Types::ServiceEnum::ANTHROPIC] = AnthropicApi
|
25
|
+
end
|
26
|
+
|
27
|
+
if open_ai_setup?
|
28
|
+
@ai_services[AnswerBot::Types::ServiceEnum::OPEN_AI] = OpenAiApi
|
29
|
+
end
|
30
|
+
|
31
|
+
if ollama_setup?
|
32
|
+
@ai_services[AnswerBot::Types::ServiceEnum::OLLAMA] = OllamaApi
|
33
|
+
end
|
34
|
+
|
35
|
+
if @ai_services.empty?
|
36
|
+
# :nocov:
|
37
|
+
require "foobara/anthropic_api"
|
38
|
+
@ai_services = { Types::ServiceEnum::ANTHROPIC => AnthropicApi }
|
39
|
+
# :nocov:
|
40
|
+
end
|
41
|
+
|
42
|
+
@ai_services
|
43
|
+
end
|
44
|
+
|
45
|
+
def default_llm_model
|
46
|
+
@default_llm_model ||= installed_ai_services.values.first.default_llm_model
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
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: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miles Georgi
|
@@ -20,6 +20,7 @@ files:
|
|
20
20
|
- LICENSE.txt
|
21
21
|
- README.md
|
22
22
|
- lib/foobara/ai.rb
|
23
|
+
- src/foobara/ai.rb
|
23
24
|
- src/foobara/ai/answer_bot/ask.rb
|
24
25
|
- src/foobara/ai/answer_bot/domain_mappers/anthropic_api/chat_to_create_message.rb
|
25
26
|
- src/foobara/ai/answer_bot/domain_mappers/anthropic_api/message_result_to_answer.rb
|