foobara-ai 0.0.12 → 0.0.14
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/src/foobara/ai/answer_bot/ask.rb +4 -1
- data/src/foobara/ai/answer_bot/domain_mappers/anthropic_api/chat_to_create_message.rb +56 -0
- data/src/foobara/ai/answer_bot/domain_mappers/anthropic_api/message_result_to_message.rb +23 -0
- data/src/foobara/ai/answer_bot/domain_mappers/ollama_api/chat_completion_result_to_message.rb +25 -0
- data/src/foobara/ai/answer_bot/domain_mappers/ollama_api/chat_to_generate_chat_completion.rb +52 -0
- data/src/foobara/ai/answer_bot/domain_mappers/open_ai_api/chat_completion_result_to_message.rb +25 -0
- data/src/foobara/ai/answer_bot/domain_mappers/open_ai_api/chat_to_generate_chat_completion.rb +56 -0
- data/src/foobara/ai/answer_bot/generate_next_message.rb +49 -0
- data/src/foobara/ai/answer_bot/types/chat.rb +13 -0
- data/src/foobara/ai/answer_bot/types/message.rb +18 -0
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c915b80c804ceddc6311400052b2a7cce0011bfcfda4d80dc200f63e50382e5
|
4
|
+
data.tar.gz: 3e50a758f4b65631c5c535fcce51aca9013170cdcd856760c956bb3605b1acff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1eb53a355a90be12c04da34da4449c22ef8808c4b9bb98e422285a363089d5284fbf916138bc60dcfab525ade24016fdda5878649b9310d9c662857326d9ea0a
|
7
|
+
data.tar.gz: 6d825776dc6a23720bf90d72c9f61aed29665f19625d8c36dcd03388f751ccae3b798c38cab8c388c0f15b3b69f7fe17e42d7c52a61d7e6145e6cf3ce103d30c
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## [0.0.14] - 2025-07-05
|
2
|
+
|
3
|
+
- o1 models don't support temperature so force it to 1
|
4
|
+
|
5
|
+
## [0.0.13] - 2025-06-27
|
6
|
+
|
7
|
+
- Add GenerateChatCompletion command
|
8
|
+
|
1
9
|
## [0.0.12] - 2025-05-27
|
2
10
|
|
3
11
|
- Do not load service models in parallel due to undiagnosed race condition somewhere
|
@@ -43,7 +43,10 @@ module Foobara
|
|
43
43
|
inputs[:instructions] = instructions
|
44
44
|
end
|
45
45
|
|
46
|
-
|
46
|
+
inputs = domain_map!(inputs, to: ai_command)
|
47
|
+
answer = run_subcommand!(ai_command, inputs)
|
48
|
+
|
49
|
+
self.answer = domain_map!(answer, to: :string)
|
47
50
|
end
|
48
51
|
end
|
49
52
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require_relative "../../types/model_enum"
|
2
|
+
|
3
|
+
module Foobara
|
4
|
+
module Ai
|
5
|
+
module AnswerBot
|
6
|
+
module DomainMappers
|
7
|
+
module AnthropicApi
|
8
|
+
class ChatToCreateMessage < Foobara::DomainMapper
|
9
|
+
from do
|
10
|
+
chat Types::Chat, :required
|
11
|
+
temperature :float
|
12
|
+
model :model_enum
|
13
|
+
end
|
14
|
+
to Foobara::Ai::AnthropicApi::CreateMessage
|
15
|
+
|
16
|
+
def map
|
17
|
+
system_messages, non_system_messages = chat.messages.partition(&:system?)
|
18
|
+
|
19
|
+
inputs = {
|
20
|
+
messages: non_system_messages.map do |message|
|
21
|
+
{ role: message.role, content: message.content }
|
22
|
+
end
|
23
|
+
}
|
24
|
+
|
25
|
+
unless system_messages.empty?
|
26
|
+
inputs[:system] = system_messages.map(&:content).join("\n")
|
27
|
+
end
|
28
|
+
|
29
|
+
if temperature
|
30
|
+
inputs[:temperature] = temperature
|
31
|
+
end
|
32
|
+
|
33
|
+
if model
|
34
|
+
inputs[:model] = model
|
35
|
+
end
|
36
|
+
|
37
|
+
inputs
|
38
|
+
end
|
39
|
+
|
40
|
+
def chat
|
41
|
+
from[:chat]
|
42
|
+
end
|
43
|
+
|
44
|
+
def temperature
|
45
|
+
from[:temperature]
|
46
|
+
end
|
47
|
+
|
48
|
+
def model
|
49
|
+
from[:model]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Foobara
|
2
|
+
module Ai
|
3
|
+
module AnswerBot
|
4
|
+
module DomainMappers
|
5
|
+
module AnthropicApi
|
6
|
+
class MessageResultToMessage < Foobara::DomainMapper
|
7
|
+
from Foobara::Ai::AnthropicApi::Types::MessageResult
|
8
|
+
to Types::Message
|
9
|
+
|
10
|
+
def map
|
11
|
+
{
|
12
|
+
content: message_result.content.last.text,
|
13
|
+
role: message_result.role
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
alias message_result from
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Foobara
|
2
|
+
module Ai
|
3
|
+
module AnswerBot
|
4
|
+
module DomainMappers
|
5
|
+
module OllamaApi
|
6
|
+
class ChatCompletionResultToMessage < Foobara::DomainMapper
|
7
|
+
from Foobara::Ai::OllamaApi::Types::ChatCompletion
|
8
|
+
to Types::Message
|
9
|
+
|
10
|
+
def map
|
11
|
+
message = chat_completion.message
|
12
|
+
|
13
|
+
{
|
14
|
+
content: message.content,
|
15
|
+
role: message.role
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
alias chat_completion from
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require_relative "../../types/model_enum"
|
2
|
+
|
3
|
+
module Foobara
|
4
|
+
module Ai
|
5
|
+
module AnswerBot
|
6
|
+
module DomainMappers
|
7
|
+
module OllamaApi
|
8
|
+
class ChatToGenerateChatCompletion < Foobara::DomainMapper
|
9
|
+
from do
|
10
|
+
chat Types::Chat, :required
|
11
|
+
temperature :float
|
12
|
+
model :model_enum
|
13
|
+
end
|
14
|
+
to Foobara::Ai::OllamaApi::GenerateChatCompletion
|
15
|
+
|
16
|
+
def map
|
17
|
+
inputs = {
|
18
|
+
messages: chat.messages.map do |message|
|
19
|
+
{ role: message.role, content: message.content }
|
20
|
+
end
|
21
|
+
}
|
22
|
+
|
23
|
+
if temperature
|
24
|
+
inputs[:options] = {
|
25
|
+
temperature:
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
if model
|
30
|
+
inputs[:model] = model
|
31
|
+
end
|
32
|
+
|
33
|
+
inputs
|
34
|
+
end
|
35
|
+
|
36
|
+
def chat
|
37
|
+
from[:chat]
|
38
|
+
end
|
39
|
+
|
40
|
+
def temperature
|
41
|
+
from[:temperature]
|
42
|
+
end
|
43
|
+
|
44
|
+
def model
|
45
|
+
from[:model]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/src/foobara/ai/answer_bot/domain_mappers/open_ai_api/chat_completion_result_to_message.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Foobara
|
2
|
+
module Ai
|
3
|
+
module AnswerBot
|
4
|
+
module DomainMappers
|
5
|
+
module OpenAiApi
|
6
|
+
class ChatCompletionResultToMessage < Foobara::DomainMapper
|
7
|
+
from Foobara::Ai::OpenAiApi::Types::ChatCompletion
|
8
|
+
to Types::Message
|
9
|
+
|
10
|
+
def map
|
11
|
+
message = chat_completion.choices.first.message
|
12
|
+
|
13
|
+
{
|
14
|
+
content: message.content,
|
15
|
+
role: message.role
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
alias chat_completion from
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require_relative "../../types/model_enum"
|
2
|
+
|
3
|
+
module Foobara
|
4
|
+
module Ai
|
5
|
+
module AnswerBot
|
6
|
+
module DomainMappers
|
7
|
+
module OpenAiApi
|
8
|
+
class ChatToGenerateChatCompletion < Foobara::DomainMapper
|
9
|
+
from do
|
10
|
+
chat Types::Chat, :required
|
11
|
+
temperature :float
|
12
|
+
model :model_enum
|
13
|
+
end
|
14
|
+
to Foobara::Ai::OpenAiApi::CreateChatCompletion
|
15
|
+
|
16
|
+
def map
|
17
|
+
inputs = {
|
18
|
+
messages: chat.messages.map do |message|
|
19
|
+
{ role: message.role, content: message.content }
|
20
|
+
end
|
21
|
+
}
|
22
|
+
|
23
|
+
if temperature
|
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
|
27
|
+
end
|
28
|
+
|
29
|
+
if model
|
30
|
+
inputs[:model] = model
|
31
|
+
end
|
32
|
+
|
33
|
+
inputs
|
34
|
+
end
|
35
|
+
|
36
|
+
def chat
|
37
|
+
from[:chat]
|
38
|
+
end
|
39
|
+
|
40
|
+
def temperature
|
41
|
+
from[:temperature]
|
42
|
+
end
|
43
|
+
|
44
|
+
def model
|
45
|
+
from[:model]
|
46
|
+
end
|
47
|
+
|
48
|
+
def model_supports_temperature?
|
49
|
+
model && model.to_s !~ /\Ao1(-|$)/
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Foobara
|
2
|
+
module Ai
|
3
|
+
module AnswerBot
|
4
|
+
class GenerateNextMessage < Foobara::Command
|
5
|
+
description "Takes a chat and generates the next message using the model of your choice."
|
6
|
+
|
7
|
+
inputs do
|
8
|
+
chat Types::Chat, :required
|
9
|
+
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."
|
11
|
+
temperature :float
|
12
|
+
end
|
13
|
+
|
14
|
+
result Types::Message
|
15
|
+
|
16
|
+
AI_SERVICES.each_key do |service|
|
17
|
+
command = Foobara::Ai::AnswerBot::DomainMappers::ServiceToChatCompletionCommand.map!(service)
|
18
|
+
depends_on command
|
19
|
+
end
|
20
|
+
|
21
|
+
def execute
|
22
|
+
determine_ai_service
|
23
|
+
determine_ai_command
|
24
|
+
run_ai_service
|
25
|
+
|
26
|
+
next_message
|
27
|
+
end
|
28
|
+
|
29
|
+
attr_accessor :ai_command, :response, :ai_service, :next_message
|
30
|
+
|
31
|
+
def determine_ai_service
|
32
|
+
self.ai_service = service || domain_map!(model, from: :model_enum)
|
33
|
+
end
|
34
|
+
|
35
|
+
def determine_ai_command
|
36
|
+
self.ai_command = Foobara::Ai::AnswerBot::DomainMappers::ServiceToChatCompletionCommand.map!(ai_service)
|
37
|
+
end
|
38
|
+
|
39
|
+
def run_ai_service
|
40
|
+
inputs = { chat:, temperature:, model: }
|
41
|
+
inputs = domain_map!(inputs, to: ai_command)
|
42
|
+
next_message = run_subcommand!(ai_command, inputs)
|
43
|
+
|
44
|
+
self.next_message = domain_map!(next_message, to: Types::Message)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Foobara
|
2
|
+
module Ai
|
3
|
+
module AnswerBot
|
4
|
+
module Types
|
5
|
+
class Message < Foobara::Model
|
6
|
+
attributes do
|
7
|
+
role :symbol, one_of: [:assistant, :user, :system]
|
8
|
+
content :string
|
9
|
+
end
|
10
|
+
|
11
|
+
def system?
|
12
|
+
role == :system
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
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: 0.0.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miles Georgi
|
@@ -21,22 +21,31 @@ files:
|
|
21
21
|
- README.md
|
22
22
|
- lib/foobara/ai.rb
|
23
23
|
- src/foobara/ai/answer_bot/ask.rb
|
24
|
+
- src/foobara/ai/answer_bot/domain_mappers/anthropic_api/chat_to_create_message.rb
|
24
25
|
- src/foobara/ai/answer_bot/domain_mappers/anthropic_api/message_result_to_answer.rb
|
26
|
+
- src/foobara/ai/answer_bot/domain_mappers/anthropic_api/message_result_to_message.rb
|
25
27
|
- src/foobara/ai/answer_bot/domain_mappers/anthropic_api/model_to_foobara_model.rb
|
26
28
|
- src/foobara/ai/answer_bot/domain_mappers/anthropic_api/model_to_model_enum_string.rb
|
27
29
|
- src/foobara/ai/answer_bot/domain_mappers/anthropic_api/question_to_create_message.rb
|
28
30
|
- src/foobara/ai/answer_bot/domain_mappers/model_to_ai_service.rb
|
31
|
+
- src/foobara/ai/answer_bot/domain_mappers/ollama_api/chat_completion_result_to_message.rb
|
29
32
|
- src/foobara/ai/answer_bot/domain_mappers/ollama_api/chat_completion_to_answer.rb
|
33
|
+
- src/foobara/ai/answer_bot/domain_mappers/ollama_api/chat_to_generate_chat_completion.rb
|
30
34
|
- src/foobara/ai/answer_bot/domain_mappers/ollama_api/model_to_foobara_model.rb
|
31
35
|
- src/foobara/ai/answer_bot/domain_mappers/ollama_api/model_to_model_enum_string.rb
|
32
36
|
- src/foobara/ai/answer_bot/domain_mappers/ollama_api/question_to_generate_chat_completion.rb
|
37
|
+
- src/foobara/ai/answer_bot/domain_mappers/open_ai_api/chat_completion_result_to_message.rb
|
33
38
|
- src/foobara/ai/answer_bot/domain_mappers/open_ai_api/chat_completion_to_answer.rb
|
39
|
+
- src/foobara/ai/answer_bot/domain_mappers/open_ai_api/chat_to_generate_chat_completion.rb
|
34
40
|
- src/foobara/ai/answer_bot/domain_mappers/open_ai_api/model_to_foobara_model.rb
|
35
41
|
- src/foobara/ai/answer_bot/domain_mappers/open_ai_api/model_to_model_enum_string.rb
|
36
42
|
- src/foobara/ai/answer_bot/domain_mappers/open_ai_api/question_to_create_chat_completion.rb
|
37
43
|
- src/foobara/ai/answer_bot/domain_mappers/service_to_command.rb
|
38
44
|
- src/foobara/ai/answer_bot/domain_mappers/service_to_list_models_command.rb
|
45
|
+
- src/foobara/ai/answer_bot/generate_next_message.rb
|
39
46
|
- src/foobara/ai/answer_bot/list_models.rb
|
47
|
+
- src/foobara/ai/answer_bot/types/chat.rb
|
48
|
+
- src/foobara/ai/answer_bot/types/message.rb
|
40
49
|
- src/foobara/ai/answer_bot/types/model.rb
|
41
50
|
- src/foobara/ai/answer_bot/types/model_enum.rb
|
42
51
|
- src/foobara/ai/answer_bot/types/service_enum.rb
|
@@ -62,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
71
|
- !ruby/object:Gem::Version
|
63
72
|
version: '0'
|
64
73
|
requirements: []
|
65
|
-
rubygems_version: 3.6.
|
74
|
+
rubygems_version: 3.6.9
|
66
75
|
specification_version: 4
|
67
76
|
summary: No description. Add one.
|
68
77
|
test_files: []
|