Skip to content

Commit ae2d9fc

Browse files
committed
Add .default_llm_model and use the default from the first service actually available
1 parent 3f98331 commit ae2d9fc

File tree

9 files changed

+80
-38
lines changed

9 files changed

+80
-38
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [1.0.0] - 2025-07-09
2+
3+
- Add .default_llm_model
4+
15
## [0.0.14] - 2025-07-05
26

37
- o1 models don't support temperature so force it to 1

Gemfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ group :development do
1919
end
2020

2121
group :development, :test do
22-
gem "foobara-anthropic-api" # , path: "../anthropic-api"
23-
gem "foobara-ollama-api" # , path: "../ollama-api"
24-
gem "foobara-open-ai-api" # , path: "../open-ai-api"
22+
gem "foobara-anthropic-api", ">= 1.0.1", "< 2.0.0" # , path: "../anthropic-api"
23+
gem "foobara-ollama-api", ">= 1.0.0", "< 2.0.0" # , path: "../ollama-api"
24+
gem "foobara-open-ai-api", ">= 1.0.1", "< 2.0.0" # , path: "../open-ai-api"
2525
gem "pry"
2626
gem "pry-byebug"
2727
# TODO: Just adding this to suppress warnings seemingly coming from pry-byebug. Can probably remove this once

Gemfile.lock

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
foobara-ai (0.0.14)
4+
foobara-ai (1.0.0)
55

66
GEM
77
remote: https://rubygems.org/
@@ -55,12 +55,12 @@ GEM
5555
foobara-type-generator (~> 0.0.1)
5656
foobara-typescript-react-command-form-generator (~> 0.0.1)
5757
foobara-typescript-remote-command-generator (~> 0.0.1)
58-
foobara (0.0.135)
58+
foobara (0.0.136)
5959
bigdecimal
6060
foobara-lru-cache (~> 0.0.2)
6161
foobara-util (>= 1.0.0)
6262
inheritable-thread-vars (~> 0.0.1)
63-
foobara-anthropic-api (0.0.11)
63+
foobara-anthropic-api (1.0.1)
6464
foobara-cached-command
6565
foobara-http-api-command
6666
foobara-cached-command (0.0.2)
@@ -93,9 +93,9 @@ GEM
9393
foobara-lru-cache (0.0.2)
9494
foobara-mcp-connector-generator (0.0.6)
9595
foobara (~> 0.0.99)
96-
foobara-ollama-api (0.0.5)
96+
foobara-ollama-api (1.0.0)
9797
foobara-http-api-command
98-
foobara-open-ai-api (0.0.13)
98+
foobara-open-ai-api (1.0.1)
9999
foobara-cached-command
100100
foobara-http-api-command
101101
foobara-organization-generator (0.0.2)
@@ -131,7 +131,7 @@ GEM
131131
foobara-typescript-remote-command-generator (~> 0.0.1)
132132
foobara-typescript-remote-command-generator (0.0.24)
133133
foobara-files-generator (~> 0.0.1)
134-
foobara-util (1.0.0)
134+
foobara-util (1.0.1)
135135
formatador (1.1.0)
136136
guard (2.19.1)
137137
formatador (>= 0.2.4)
@@ -217,7 +217,7 @@ GEM
217217
diff-lcs (>= 1.2.0, < 2.0)
218218
rspec-support (~> 3.13.0)
219219
rspec-support (3.13.4)
220-
rubocop (1.77.0)
220+
rubocop (1.78.0)
221221
json (~> 2.3)
222222
language_server-protocol (~> 3.17.0.2)
223223
lint_roller (~> 1.1.0)
@@ -275,10 +275,10 @@ PLATFORMS
275275
DEPENDENCIES
276276
foob
277277
foobara-ai!
278-
foobara-anthropic-api
278+
foobara-anthropic-api (>= 1.0.1, < 2.0.0)
279279
foobara-dotenv-loader
280-
foobara-ollama-api
281-
foobara-open-ai-api
280+
foobara-ollama-api (>= 1.0.0, < 2.0.0)
281+
foobara-open-ai-api (>= 1.0.1, < 2.0.0)
282282
foobara-rubocop-rules
283283
foobara-spec-helpers
284284
guard-rspec

lib/foobara/ai.rb

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,14 @@ module Ai
77
module AnswerBot
88
foobara_domain!
99

10-
require_relative "../../src/foobara/ai/answer_bot/types/service_enum"
10+
require_relative "../../src/foobara/ai"
1111

12-
ai_services = {}
12+
AI_SERVICES = Ai.installed_ai_services
1313

14-
if defined?(Foobara::Ai::OpenAiApi)
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|
3215
foobara_depends_on domain
3316
end
3417

35-
AI_SERVICES = ai_services
36-
3718
base_dir = "#{__dir__}/../../src/foobara/ai/answer_bot"
3819

3920
AI_SERVICES.each_value do |domain|

spec/ai_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
RSpec.describe Foobara::Ai do
2+
describe ".default_llm_model" do
3+
subject { described_class.default_llm_model }
4+
5+
it { is_expected.to be_a(Symbol) }
6+
end
7+
end

src/foobara/ai.rb

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/foobara/ai/answer_bot/ask.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Ask < Foobara::Command
88
question :string, :required, "whatever you want to know!"
99
instructions :string, "Results in a system prompt. You can specify how you want the LLM to behave."
1010
service :service_enum, "If two services expose the same model, you can specify which one to use."
11-
model :model_enum, default: "claude-3-7-sonnet-20250219", description: "The model to use."
11+
model :model_enum, default: Ai.default_llm_model, description: "The model to use."
1212
end
1313

1414
result :string

src/foobara/ai/answer_bot/generate_next_message.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class GenerateNextMessage < Foobara::Command
77
inputs do
88
chat Types::Chat, :required
99
service :service_enum, "If two services expose the same model, you can specify which one to use."
10-
model :model_enum, default: "claude-3-7-sonnet-20250219", description: "The model to use."
10+
model :model_enum, default: Ai.default_llm_model, description: "The model to use."
1111
temperature :float
1212
end
1313

version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Foobara
22
module Ai
3-
VERSION = "0.0.14".freeze
3+
VERSION = "1.0.0".freeze
44
MINIMUM_RUBY_VERSION = ">= 3.4.0".freeze
55
end
66
end

0 commit comments

Comments
 (0)