activeagent 1.0.0.rc1 → 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 +31 -1
- data/lib/active_agent/providers/_base_provider.rb +92 -82
- data/lib/active_agent/providers/anthropic/_types.rb +2 -2
- data/lib/active_agent/providers/anthropic/request.rb +135 -81
- data/lib/active_agent/providers/anthropic/transforms.rb +353 -0
- data/lib/active_agent/providers/anthropic_provider.rb +96 -53
- data/lib/active_agent/providers/common/messages/_types.rb +37 -1
- data/lib/active_agent/providers/common/responses/base.rb +118 -70
- data/lib/active_agent/providers/common/usage.rb +385 -0
- data/lib/active_agent/providers/concerns/instrumentation.rb +263 -0
- data/lib/active_agent/providers/log_subscriber.rb +64 -246
- data/lib/active_agent/providers/mock_provider.rb +23 -23
- data/lib/active_agent/providers/ollama/chat/request.rb +214 -35
- data/lib/active_agent/providers/ollama/chat/transforms.rb +135 -0
- data/lib/active_agent/providers/ollama/embedding/request.rb +160 -47
- data/lib/active_agent/providers/ollama/embedding/transforms.rb +160 -0
- data/lib/active_agent/providers/ollama_provider.rb +0 -1
- data/lib/active_agent/providers/open_ai/_base.rb +3 -2
- data/lib/active_agent/providers/open_ai/chat/_types.rb +13 -1
- data/lib/active_agent/providers/open_ai/chat/request.rb +132 -186
- data/lib/active_agent/providers/open_ai/chat/transforms.rb +364 -0
- data/lib/active_agent/providers/open_ai/chat_provider.rb +57 -36
- data/lib/active_agent/providers/open_ai/embedding/_types.rb +13 -2
- data/lib/active_agent/providers/open_ai/embedding/request.rb +38 -70
- data/lib/active_agent/providers/open_ai/embedding/transforms.rb +88 -0
- data/lib/active_agent/providers/open_ai/responses/_types.rb +1 -7
- data/lib/active_agent/providers/open_ai/responses/request.rb +100 -134
- data/lib/active_agent/providers/open_ai/responses/transforms.rb +228 -0
- data/lib/active_agent/providers/open_ai/responses_provider.rb +77 -30
- data/lib/active_agent/providers/open_ai_provider.rb +0 -3
- data/lib/active_agent/providers/open_router/_types.rb +27 -1
- data/lib/active_agent/providers/open_router/options.rb +49 -1
- data/lib/active_agent/providers/open_router/request.rb +232 -66
- data/lib/active_agent/providers/open_router/requests/_types.rb +0 -1
- data/lib/active_agent/providers/open_router/requests/messages/_types.rb +37 -40
- data/lib/active_agent/providers/open_router/requests/messages/content/file.rb +19 -3
- data/lib/active_agent/providers/open_router/requests/messages/content/files/details.rb +15 -4
- data/lib/active_agent/providers/open_router/requests/plugin.rb +19 -3
- data/lib/active_agent/providers/open_router/requests/plugins/pdf_config.rb +30 -8
- data/lib/active_agent/providers/open_router/requests/prediction.rb +17 -0
- data/lib/active_agent/providers/open_router/requests/provider_preferences/max_price.rb +41 -7
- data/lib/active_agent/providers/open_router/requests/provider_preferences.rb +60 -19
- data/lib/active_agent/providers/open_router/requests/response_format.rb +30 -2
- data/lib/active_agent/providers/open_router/transforms.rb +134 -0
- data/lib/active_agent/providers/open_router_provider.rb +9 -0
- data/lib/active_agent/version.rb +1 -1
- metadata +15 -159
- data/lib/active_agent/generation_provider/open_router/types.rb +0 -505
- data/lib/active_agent/generation_provider/xai_provider.rb +0 -144
- data/lib/active_agent/providers/anthropic/requests/_types.rb +0 -190
- data/lib/active_agent/providers/anthropic/requests/container_params.rb +0 -19
- data/lib/active_agent/providers/anthropic/requests/content/base.rb +0 -21
- data/lib/active_agent/providers/anthropic/requests/content/sources/base.rb +0 -22
- data/lib/active_agent/providers/anthropic/requests/context_management_config.rb +0 -18
- data/lib/active_agent/providers/anthropic/requests/messages/_types.rb +0 -189
- data/lib/active_agent/providers/anthropic/requests/messages/assistant.rb +0 -23
- data/lib/active_agent/providers/anthropic/requests/messages/base.rb +0 -63
- data/lib/active_agent/providers/anthropic/requests/messages/content/_types.rb +0 -143
- data/lib/active_agent/providers/anthropic/requests/messages/content/base.rb +0 -21
- data/lib/active_agent/providers/anthropic/requests/messages/content/document.rb +0 -26
- data/lib/active_agent/providers/anthropic/requests/messages/content/image.rb +0 -23
- data/lib/active_agent/providers/anthropic/requests/messages/content/redacted_thinking.rb +0 -21
- data/lib/active_agent/providers/anthropic/requests/messages/content/search_result.rb +0 -27
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/_types.rb +0 -171
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/base.rb +0 -22
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/document_base64.rb +0 -25
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/document_file.rb +0 -23
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/document_text.rb +0 -25
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/document_url.rb +0 -23
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/image_base64.rb +0 -27
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/image_file.rb +0 -23
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/image_url.rb +0 -23
- data/lib/active_agent/providers/anthropic/requests/messages/content/text.rb +0 -22
- data/lib/active_agent/providers/anthropic/requests/messages/content/thinking.rb +0 -23
- data/lib/active_agent/providers/anthropic/requests/messages/content/tool_result.rb +0 -24
- data/lib/active_agent/providers/anthropic/requests/messages/content/tool_use.rb +0 -28
- data/lib/active_agent/providers/anthropic/requests/messages/user.rb +0 -21
- data/lib/active_agent/providers/anthropic/requests/metadata.rb +0 -18
- data/lib/active_agent/providers/anthropic/requests/response_format.rb +0 -22
- data/lib/active_agent/providers/anthropic/requests/thinking_config/_types.rb +0 -60
- data/lib/active_agent/providers/anthropic/requests/thinking_config/base.rb +0 -20
- data/lib/active_agent/providers/anthropic/requests/thinking_config/disabled.rb +0 -16
- data/lib/active_agent/providers/anthropic/requests/thinking_config/enabled.rb +0 -20
- data/lib/active_agent/providers/anthropic/requests/tool_choice/_types.rb +0 -78
- data/lib/active_agent/providers/anthropic/requests/tool_choice/any.rb +0 -17
- data/lib/active_agent/providers/anthropic/requests/tool_choice/auto.rb +0 -17
- data/lib/active_agent/providers/anthropic/requests/tool_choice/base.rb +0 -20
- data/lib/active_agent/providers/anthropic/requests/tool_choice/none.rb +0 -16
- data/lib/active_agent/providers/anthropic/requests/tool_choice/tool.rb +0 -20
- data/lib/active_agent/providers/ollama/chat/requests/_types.rb +0 -3
- data/lib/active_agent/providers/ollama/chat/requests/messages/_types.rb +0 -116
- data/lib/active_agent/providers/ollama/chat/requests/messages/assistant.rb +0 -19
- data/lib/active_agent/providers/ollama/chat/requests/messages/user.rb +0 -19
- data/lib/active_agent/providers/ollama/embedding/requests/_types.rb +0 -83
- data/lib/active_agent/providers/ollama/embedding/requests/options.rb +0 -104
- data/lib/active_agent/providers/open_ai/chat/requests/_types.rb +0 -229
- data/lib/active_agent/providers/open_ai/chat/requests/audio.rb +0 -24
- data/lib/active_agent/providers/open_ai/chat/requests/messages/_types.rb +0 -123
- data/lib/active_agent/providers/open_ai/chat/requests/messages/assistant.rb +0 -42
- data/lib/active_agent/providers/open_ai/chat/requests/messages/base.rb +0 -78
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/_types.rb +0 -133
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/audio.rb +0 -35
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/base.rb +0 -24
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/file.rb +0 -26
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/files/_types.rb +0 -60
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/files/details.rb +0 -41
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/image.rb +0 -37
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/refusal.rb +0 -25
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/text.rb +0 -25
- data/lib/active_agent/providers/open_ai/chat/requests/messages/developer.rb +0 -25
- data/lib/active_agent/providers/open_ai/chat/requests/messages/function.rb +0 -25
- data/lib/active_agent/providers/open_ai/chat/requests/messages/system.rb +0 -25
- data/lib/active_agent/providers/open_ai/chat/requests/messages/tool.rb +0 -26
- data/lib/active_agent/providers/open_ai/chat/requests/messages/user.rb +0 -32
- data/lib/active_agent/providers/open_ai/chat/requests/prediction.rb +0 -46
- data/lib/active_agent/providers/open_ai/chat/requests/response_format.rb +0 -53
- data/lib/active_agent/providers/open_ai/chat/requests/stream_options.rb +0 -24
- data/lib/active_agent/providers/open_ai/chat/requests/tool_choice.rb +0 -26
- data/lib/active_agent/providers/open_ai/chat/requests/tools/_types.rb +0 -5
- data/lib/active_agent/providers/open_ai/chat/requests/tools/base.rb +0 -22
- data/lib/active_agent/providers/open_ai/chat/requests/tools/custom_tool.rb +0 -41
- data/lib/active_agent/providers/open_ai/chat/requests/tools/function_tool.rb +0 -51
- data/lib/active_agent/providers/open_ai/chat/requests/web_search_options.rb +0 -45
- data/lib/active_agent/providers/open_ai/embedding/requests/_types.rb +0 -49
- data/lib/active_agent/providers/open_ai/responses/requests/_types.rb +0 -231
- data/lib/active_agent/providers/open_ai/responses/requests/conversation.rb +0 -23
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/_types.rb +0 -264
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/assistant_message.rb +0 -22
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/base.rb +0 -89
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/code_interpreter_tool_call.rb +0 -30
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/computer_tool_call.rb +0 -28
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/computer_tool_call_output.rb +0 -33
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/_types.rb +0 -207
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/base.rb +0 -22
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/input_audio.rb +0 -26
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/input_file.rb +0 -28
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/input_image.rb +0 -28
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/input_text.rb +0 -25
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/custom_tool_call.rb +0 -28
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/custom_tool_call_output.rb +0 -27
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/developer_message.rb +0 -20
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/file_search_tool_call.rb +0 -25
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/function_call_output.rb +0 -32
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/function_tool_call.rb +0 -28
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/image_gen_tool_call.rb +0 -27
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/input_message.rb +0 -31
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/item_reference.rb +0 -23
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/local_shell_tool_call.rb +0 -26
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/local_shell_tool_call_output.rb +0 -33
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/mcp_approval_request.rb +0 -30
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/mcp_approval_response.rb +0 -28
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/mcp_list_tools.rb +0 -29
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/mcp_tool_call.rb +0 -35
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/output_message.rb +0 -35
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/reasoning.rb +0 -33
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/system_message.rb +0 -20
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/tool_call_base.rb +0 -27
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/tool_message.rb +0 -23
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/user_message.rb +0 -20
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/web_search_tool_call.rb +0 -24
- data/lib/active_agent/providers/open_ai/responses/requests/prompt_reference.rb +0 -23
- data/lib/active_agent/providers/open_ai/responses/requests/reasoning.rb +0 -23
- data/lib/active_agent/providers/open_ai/responses/requests/stream_options.rb +0 -20
- data/lib/active_agent/providers/open_ai/responses/requests/text/_types.rb +0 -89
- data/lib/active_agent/providers/open_ai/responses/requests/text/base.rb +0 -22
- data/lib/active_agent/providers/open_ai/responses/requests/text/json_object.rb +0 -20
- data/lib/active_agent/providers/open_ai/responses/requests/text/json_schema.rb +0 -48
- data/lib/active_agent/providers/open_ai/responses/requests/text/plain.rb +0 -20
- data/lib/active_agent/providers/open_ai/responses/requests/text.rb +0 -41
- data/lib/active_agent/providers/open_ai/responses/requests/tool_choice.rb +0 -26
- data/lib/active_agent/providers/open_ai/responses/requests/tools/_types.rb +0 -112
- data/lib/active_agent/providers/open_ai/responses/requests/tools/base.rb +0 -25
- data/lib/active_agent/providers/open_ai/responses/requests/tools/code_interpreter_tool.rb +0 -23
- data/lib/active_agent/providers/open_ai/responses/requests/tools/computer_tool.rb +0 -27
- data/lib/active_agent/providers/open_ai/responses/requests/tools/custom_tool.rb +0 -28
- data/lib/active_agent/providers/open_ai/responses/requests/tools/file_search_tool.rb +0 -27
- data/lib/active_agent/providers/open_ai/responses/requests/tools/function_tool.rb +0 -29
- data/lib/active_agent/providers/open_ai/responses/requests/tools/image_generation_tool.rb +0 -37
- data/lib/active_agent/providers/open_ai/responses/requests/tools/local_shell_tool.rb +0 -21
- data/lib/active_agent/providers/open_ai/responses/requests/tools/mcp_tool.rb +0 -41
- data/lib/active_agent/providers/open_ai/responses/requests/tools/web_search_preview_tool.rb +0 -24
- data/lib/active_agent/providers/open_ai/responses/requests/tools/web_search_tool.rb +0 -25
- data/lib/active_agent/providers/open_ai/schema.yml +0 -65937
- data/lib/active_agent/providers/open_router/requests/message.rb +0 -1
- data/lib/active_agent/providers/open_router/requests/messages/assistant.rb +0 -20
- data/lib/active_agent/providers/open_router/requests/messages/user.rb +0 -30
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "base"
|
|
4
|
-
require_relative "enabled"
|
|
5
|
-
require_relative "disabled"
|
|
6
|
-
|
|
7
|
-
module ActiveAgent
|
|
8
|
-
module Providers
|
|
9
|
-
module Anthropic
|
|
10
|
-
module Requests
|
|
11
|
-
module ThinkingConfig
|
|
12
|
-
# Type for ThinkingConfig
|
|
13
|
-
class ThinkingConfigType < ActiveModel::Type::Value
|
|
14
|
-
def cast(value)
|
|
15
|
-
case value
|
|
16
|
-
when Base
|
|
17
|
-
value
|
|
18
|
-
when Hash
|
|
19
|
-
hash = value.deep_symbolize_keys
|
|
20
|
-
type = hash[:type]&.to_sym
|
|
21
|
-
|
|
22
|
-
case type
|
|
23
|
-
when :enabled
|
|
24
|
-
Enabled.new(**hash)
|
|
25
|
-
when :disabled
|
|
26
|
-
Disabled.new(**hash)
|
|
27
|
-
when nil
|
|
28
|
-
nil
|
|
29
|
-
else
|
|
30
|
-
raise ArgumentError, "Unknown thinking config type: #{type}"
|
|
31
|
-
end
|
|
32
|
-
when nil
|
|
33
|
-
nil
|
|
34
|
-
else
|
|
35
|
-
raise ArgumentError, "Cannot cast #{value.class} to ThinkingConfig"
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def serialize(value)
|
|
40
|
-
case value
|
|
41
|
-
when Base
|
|
42
|
-
value.serialize
|
|
43
|
-
when Hash
|
|
44
|
-
value
|
|
45
|
-
when nil
|
|
46
|
-
nil
|
|
47
|
-
else
|
|
48
|
-
raise ArgumentError, "Cannot serialize #{value.class}"
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def deserialize(value)
|
|
53
|
-
cast(value)
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "active_agent/providers/common/model"
|
|
4
|
-
|
|
5
|
-
module ActiveAgent
|
|
6
|
-
module Providers
|
|
7
|
-
module Anthropic
|
|
8
|
-
module Requests
|
|
9
|
-
module ThinkingConfig
|
|
10
|
-
# Base class for thinking configuration
|
|
11
|
-
class Base < Common::BaseModel
|
|
12
|
-
attribute :type, :string
|
|
13
|
-
|
|
14
|
-
validates :type, presence: true, inclusion: { in: %w[enabled disabled] }
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module ActiveAgent
|
|
4
|
-
module Providers
|
|
5
|
-
module Anthropic
|
|
6
|
-
module Requests
|
|
7
|
-
module ThinkingConfig
|
|
8
|
-
# Disabled thinking configuration
|
|
9
|
-
class Disabled < Base
|
|
10
|
-
attribute :type, :string, as: "disabled"
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module ActiveAgent
|
|
4
|
-
module Providers
|
|
5
|
-
module Anthropic
|
|
6
|
-
module Requests
|
|
7
|
-
module ThinkingConfig
|
|
8
|
-
# Enabled thinking configuration with budget
|
|
9
|
-
class Enabled < Base
|
|
10
|
-
attribute :type, :string, as: "enabled"
|
|
11
|
-
attribute :budget_tokens, :integer
|
|
12
|
-
|
|
13
|
-
validates :budget_tokens, presence: true
|
|
14
|
-
validates :budget_tokens, numericality: { greater_than_or_equal_to: 1024 }, allow_nil: false
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "base"
|
|
4
|
-
require_relative "auto"
|
|
5
|
-
require_relative "any"
|
|
6
|
-
require_relative "tool"
|
|
7
|
-
require_relative "none"
|
|
8
|
-
|
|
9
|
-
module ActiveAgent
|
|
10
|
-
module Providers
|
|
11
|
-
module Anthropic
|
|
12
|
-
module Requests
|
|
13
|
-
module ToolChoice
|
|
14
|
-
# Type for ToolChoice
|
|
15
|
-
class ToolChoiceType < ActiveModel::Type::Value
|
|
16
|
-
def cast(value)
|
|
17
|
-
case value
|
|
18
|
-
when Base
|
|
19
|
-
value
|
|
20
|
-
when Hash
|
|
21
|
-
hash = value.deep_symbolize_keys
|
|
22
|
-
type = hash[:type]&.to_sym
|
|
23
|
-
|
|
24
|
-
case type
|
|
25
|
-
when :auto
|
|
26
|
-
Auto.new(**hash)
|
|
27
|
-
when :any
|
|
28
|
-
Any.new(**hash)
|
|
29
|
-
when :tool
|
|
30
|
-
Tool.new(**hash)
|
|
31
|
-
when :none
|
|
32
|
-
None.new(**hash)
|
|
33
|
-
when nil
|
|
34
|
-
nil
|
|
35
|
-
else
|
|
36
|
-
raise ArgumentError, "Unknown tool choice type: #{type}"
|
|
37
|
-
end
|
|
38
|
-
when String, Symbol
|
|
39
|
-
# Allow string shortcuts like "auto", "any", "none"
|
|
40
|
-
case value.to_sym
|
|
41
|
-
when :auto
|
|
42
|
-
Auto.new
|
|
43
|
-
when :any
|
|
44
|
-
Any.new
|
|
45
|
-
when :none
|
|
46
|
-
None.new
|
|
47
|
-
else
|
|
48
|
-
raise ArgumentError, "Unknown tool choice: #{value}"
|
|
49
|
-
end
|
|
50
|
-
when nil
|
|
51
|
-
nil
|
|
52
|
-
else
|
|
53
|
-
raise ArgumentError, "Cannot cast #{value.class} to ToolChoice"
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def serialize(value)
|
|
58
|
-
case value
|
|
59
|
-
when Base
|
|
60
|
-
value.serialize
|
|
61
|
-
when Hash
|
|
62
|
-
value
|
|
63
|
-
when nil
|
|
64
|
-
nil
|
|
65
|
-
else
|
|
66
|
-
raise ArgumentError, "Cannot serialize #{value.class}"
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def deserialize(value)
|
|
71
|
-
cast(value)
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module ActiveAgent
|
|
4
|
-
module Providers
|
|
5
|
-
module Anthropic
|
|
6
|
-
module Requests
|
|
7
|
-
module ToolChoice
|
|
8
|
-
# Any tool choice - model will use any available tools
|
|
9
|
-
class Any < Base
|
|
10
|
-
attribute :type, :string, as: "any"
|
|
11
|
-
attribute :disable_parallel_tool_use, :boolean
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module ActiveAgent
|
|
4
|
-
module Providers
|
|
5
|
-
module Anthropic
|
|
6
|
-
module Requests
|
|
7
|
-
module ToolChoice
|
|
8
|
-
# Auto tool choice - model decides whether to use tools
|
|
9
|
-
class Auto < Base
|
|
10
|
-
attribute :type, :string, as: "auto"
|
|
11
|
-
attribute :disable_parallel_tool_use, :boolean
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "active_agent/providers/common/model"
|
|
4
|
-
|
|
5
|
-
module ActiveAgent
|
|
6
|
-
module Providers
|
|
7
|
-
module Anthropic
|
|
8
|
-
module Requests
|
|
9
|
-
module ToolChoice
|
|
10
|
-
# Base class for tool choice configurations
|
|
11
|
-
class Base < Common::BaseModel
|
|
12
|
-
attribute :type, :string
|
|
13
|
-
|
|
14
|
-
validates :type, presence: true, inclusion: { in: %w[auto any tool none] }
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module ActiveAgent
|
|
4
|
-
module Providers
|
|
5
|
-
module Anthropic
|
|
6
|
-
module Requests
|
|
7
|
-
module ToolChoice
|
|
8
|
-
# None tool choice - model will not use tools
|
|
9
|
-
class None < Base
|
|
10
|
-
attribute :type, :string, as: "none"
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module ActiveAgent
|
|
4
|
-
module Providers
|
|
5
|
-
module Anthropic
|
|
6
|
-
module Requests
|
|
7
|
-
module ToolChoice
|
|
8
|
-
# Tool choice - model will use the specified tool
|
|
9
|
-
class Tool < Base
|
|
10
|
-
attribute :type, :string, as: "tool"
|
|
11
|
-
attribute :name, :string
|
|
12
|
-
attribute :disable_parallel_tool_use, :boolean
|
|
13
|
-
|
|
14
|
-
validates :name, presence: true
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "active_agent/providers/open_ai/chat/requests/messages/_types"
|
|
4
|
-
|
|
5
|
-
require_relative "assistant"
|
|
6
|
-
require_relative "user"
|
|
7
|
-
|
|
8
|
-
module ActiveAgent
|
|
9
|
-
module Providers
|
|
10
|
-
module Ollama
|
|
11
|
-
module Chat
|
|
12
|
-
module Requests
|
|
13
|
-
module Messages
|
|
14
|
-
# Type for Messages array - uses Ollama's MessageType
|
|
15
|
-
class MessagesType < ActiveModel::Type::Value
|
|
16
|
-
def initialize
|
|
17
|
-
super
|
|
18
|
-
@message_type = MessageType.new
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def cast(value)
|
|
22
|
-
case value
|
|
23
|
-
when Array
|
|
24
|
-
value.map { |v| @message_type.cast(v) }
|
|
25
|
-
when nil
|
|
26
|
-
nil
|
|
27
|
-
else
|
|
28
|
-
raise ArgumentError, "Cannot cast #{value.class} to Messages array"
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def serialize(value)
|
|
33
|
-
case value
|
|
34
|
-
when Array
|
|
35
|
-
grouped = []
|
|
36
|
-
|
|
37
|
-
value.each do |message|
|
|
38
|
-
if grouped.empty? || grouped.last.role != message.role
|
|
39
|
-
grouped << message.deep_dup
|
|
40
|
-
else
|
|
41
|
-
grouped.last.content += message.content.deep_dup
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
grouped.map { |v| @message_type.serialize(v) }
|
|
46
|
-
when nil
|
|
47
|
-
nil
|
|
48
|
-
else
|
|
49
|
-
raise ArgumentError, "Cannot serialize #{value.class}"
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def deserialize(value)
|
|
54
|
-
cast(value)
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
# Type for individual Message
|
|
59
|
-
# Inherits from OpenAI but handles Ollama-specific message types
|
|
60
|
-
class MessageType < OpenAI::Chat::Requests::Messages::MessageType
|
|
61
|
-
def cast(value)
|
|
62
|
-
case value
|
|
63
|
-
when Assistant, User
|
|
64
|
-
value
|
|
65
|
-
when OpenAI::Chat::Requests::Messages::Base
|
|
66
|
-
value
|
|
67
|
-
when String
|
|
68
|
-
User.new(content: value)
|
|
69
|
-
when Hash
|
|
70
|
-
hash = value.deep_symbolize_keys
|
|
71
|
-
role = hash[:role]&.to_sym
|
|
72
|
-
|
|
73
|
-
case role
|
|
74
|
-
when :assistant
|
|
75
|
-
Assistant.new(**hash)
|
|
76
|
-
when :user, nil
|
|
77
|
-
User.new(**hash)
|
|
78
|
-
when :system
|
|
79
|
-
OpenAI::Chat::Requests::Messages::System.new(**hash)
|
|
80
|
-
when :developer
|
|
81
|
-
OpenAI::Chat::Requests::Messages::Developer.new(**hash)
|
|
82
|
-
when :tool
|
|
83
|
-
OpenAI::Chat::Requests::Messages::Tool.new(**hash)
|
|
84
|
-
else
|
|
85
|
-
raise ArgumentError, "Unknown message role: #{role.inspect}"
|
|
86
|
-
end
|
|
87
|
-
when nil
|
|
88
|
-
nil
|
|
89
|
-
else
|
|
90
|
-
raise ArgumentError, "Cannot cast #{value.class} to Message (expected Assistant, User, OpenAI Message, Hash, or nil)"
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def serialize(value)
|
|
95
|
-
case value
|
|
96
|
-
when OpenAI::Chat::Requests::Messages::Base
|
|
97
|
-
value.serialize
|
|
98
|
-
when Hash
|
|
99
|
-
value
|
|
100
|
-
when nil
|
|
101
|
-
nil
|
|
102
|
-
else
|
|
103
|
-
raise ArgumentError, "Cannot serialize #{value.class} as Message"
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def deserialize(value)
|
|
108
|
-
cast(value)
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module ActiveAgent
|
|
4
|
-
module Providers
|
|
5
|
-
module Ollama
|
|
6
|
-
module Chat
|
|
7
|
-
module Requests
|
|
8
|
-
module Messages
|
|
9
|
-
# Assistant message - messages sent by the model
|
|
10
|
-
# Inherits from OpenAI base as Ollama is largely compatible
|
|
11
|
-
class Assistant < OpenAI::Chat::Requests::Messages::Assistant
|
|
12
|
-
drop_attributes :reasoning
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module ActiveAgent
|
|
4
|
-
module Providers
|
|
5
|
-
module Ollama
|
|
6
|
-
module Chat
|
|
7
|
-
module Requests
|
|
8
|
-
module Messages
|
|
9
|
-
# User message - messages sent by an end user
|
|
10
|
-
# Ollama has the same user message format as OpenAI
|
|
11
|
-
class User < OpenAI::Chat::Requests::Messages::User
|
|
12
|
-
attribute :images # Array of base64 encoded images
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "options"
|
|
4
|
-
|
|
5
|
-
module ActiveAgent
|
|
6
|
-
module Providers
|
|
7
|
-
module Ollama
|
|
8
|
-
module Embedding
|
|
9
|
-
module Requests
|
|
10
|
-
# Custom type for handling embedding input
|
|
11
|
-
# Ollama only accepts strings or arrays of strings (no token arrays)
|
|
12
|
-
class InputType < ActiveModel::Type::Value
|
|
13
|
-
def cast(value)
|
|
14
|
-
case value
|
|
15
|
-
when String
|
|
16
|
-
[ value.presence ].compact
|
|
17
|
-
when Array
|
|
18
|
-
value.compact
|
|
19
|
-
when nil
|
|
20
|
-
nil
|
|
21
|
-
else
|
|
22
|
-
raise ArgumentError, "Cannot cast #{value.class} to Input (expected String or Array)"
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def serialize(value)
|
|
27
|
-
case value
|
|
28
|
-
when Array
|
|
29
|
-
# Return single string if array has only one string element
|
|
30
|
-
if value in [ String => string ]
|
|
31
|
-
string
|
|
32
|
-
else
|
|
33
|
-
value
|
|
34
|
-
end
|
|
35
|
-
when nil
|
|
36
|
-
nil
|
|
37
|
-
else
|
|
38
|
-
raise ArgumentError, "Cannot serialize #{value.class} as Input"
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def deserialize(value)
|
|
43
|
-
cast(value)
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
# Custom type for handling options
|
|
48
|
-
class OptionsType < ActiveModel::Type::Value
|
|
49
|
-
def cast(value)
|
|
50
|
-
case value
|
|
51
|
-
when Options
|
|
52
|
-
value
|
|
53
|
-
when Hash
|
|
54
|
-
Options.new(**value.symbolize_keys)
|
|
55
|
-
when nil
|
|
56
|
-
nil
|
|
57
|
-
else
|
|
58
|
-
raise ArgumentError, "Cannot cast #{value.class} to Options"
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def serialize(value)
|
|
63
|
-
case value
|
|
64
|
-
when Options
|
|
65
|
-
value.serialize
|
|
66
|
-
when Hash
|
|
67
|
-
value
|
|
68
|
-
when nil
|
|
69
|
-
nil
|
|
70
|
-
else
|
|
71
|
-
raise ArgumentError, "Cannot serialize #{value.class}"
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def deserialize(value)
|
|
76
|
-
cast(value)
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
end
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "active_agent/providers/common/model"
|
|
4
|
-
|
|
5
|
-
module ActiveAgent
|
|
6
|
-
module Providers
|
|
7
|
-
module Ollama
|
|
8
|
-
module Embedding
|
|
9
|
-
module Requests
|
|
10
|
-
class Options < Common::BaseModel
|
|
11
|
-
# Enable Mirostat sampling for controlling perplexity
|
|
12
|
-
# 0 = disabled, 1 = Mirostat, 2 = Mirostat 2.0 (default: 0)
|
|
13
|
-
attribute :mirostat, :integer
|
|
14
|
-
|
|
15
|
-
# Influences how quickly the algorithm responds to feedback from the generated text
|
|
16
|
-
# Lower learning rate = slower adjustments, higher = more responsive (default: 0.1)
|
|
17
|
-
attribute :mirostat_eta, :float
|
|
18
|
-
|
|
19
|
-
# Controls the balance between coherence and diversity of the output
|
|
20
|
-
# Lower value = more focused and coherent text (default: 5.0)
|
|
21
|
-
attribute :mirostat_tau, :float
|
|
22
|
-
|
|
23
|
-
# Sets the size of the context window used to generate the next token (default: 2048)
|
|
24
|
-
attribute :num_ctx, :integer
|
|
25
|
-
|
|
26
|
-
# Sets how far back for the model to look back to prevent repetition
|
|
27
|
-
# Default: 64, 0 = disabled, -1 = num_ctx
|
|
28
|
-
attribute :repeat_last_n, :integer
|
|
29
|
-
|
|
30
|
-
# Sets how strongly to penalize repetitions
|
|
31
|
-
# Higher value (e.g., 1.5) = stronger penalty, lower (e.g., 0.9) = more lenient (default: 1.1)
|
|
32
|
-
attribute :repeat_penalty, :float
|
|
33
|
-
|
|
34
|
-
# The temperature of the model
|
|
35
|
-
# Higher temperature = more creative answers (default: 0.8)
|
|
36
|
-
attribute :temperature, :float
|
|
37
|
-
|
|
38
|
-
# Sets the random number seed to use for generation
|
|
39
|
-
# Setting this to a specific number will make the model generate the same text for the same prompt (default: 0)
|
|
40
|
-
attribute :seed, :integer
|
|
41
|
-
|
|
42
|
-
# Sets the stop sequences to use
|
|
43
|
-
# When this pattern is encountered the LLM will stop generating text and return
|
|
44
|
-
# Can be a string or array of strings
|
|
45
|
-
attribute :stop
|
|
46
|
-
|
|
47
|
-
# Maximum number of tokens to predict when generating text
|
|
48
|
-
# Default: -1 (infinite generation)
|
|
49
|
-
attribute :num_predict, :integer
|
|
50
|
-
|
|
51
|
-
# Reduces the probability of generating nonsense
|
|
52
|
-
# Higher value (e.g. 100) = more diverse answers, lower (e.g. 10) = more conservative (default: 40)
|
|
53
|
-
attribute :top_k, :integer
|
|
54
|
-
|
|
55
|
-
# Works together with top-k
|
|
56
|
-
# Higher value (e.g., 0.95) = more diverse text, lower (e.g., 0.5) = more focused and conservative (default: 0.9)
|
|
57
|
-
attribute :top_p, :float
|
|
58
|
-
|
|
59
|
-
# Alternative to the top_p, and aims to ensure a balance of quality and variety
|
|
60
|
-
# Represents the minimum probability for a token to be considered, relative to the probability of the most likely token
|
|
61
|
-
# For example, with p=0.05 and the most likely token having a probability of 0.9,
|
|
62
|
-
# logits with a value less than 0.045 are filtered out (default: 0.0)
|
|
63
|
-
attribute :min_p, :float
|
|
64
|
-
|
|
65
|
-
# Validations
|
|
66
|
-
validates :mirostat, inclusion: { in: [ 0, 1, 2 ] }, allow_nil: true
|
|
67
|
-
validates :mirostat_eta, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true
|
|
68
|
-
validates :mirostat_tau, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true
|
|
69
|
-
validates :num_ctx, numericality: { greater_than: 0, only_integer: true }, allow_nil: true
|
|
70
|
-
validates :repeat_last_n, numericality: { greater_than_or_equal_to: -1, only_integer: true }, allow_nil: true
|
|
71
|
-
validates :repeat_penalty, numericality: { greater_than: 0 }, allow_nil: true
|
|
72
|
-
validates :temperature, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true
|
|
73
|
-
validates :seed, numericality: { only_integer: true }, allow_nil: true
|
|
74
|
-
validates :num_predict, numericality: { greater_than_or_equal_to: -1, only_integer: true }, allow_nil: true
|
|
75
|
-
validates :top_k, numericality: { greater_than: 0, only_integer: true }, allow_nil: true
|
|
76
|
-
validates :top_p, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 1 }, allow_nil: true
|
|
77
|
-
validates :min_p, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 1 }, allow_nil: true
|
|
78
|
-
|
|
79
|
-
validate :validate_stop_format
|
|
80
|
-
|
|
81
|
-
private
|
|
82
|
-
|
|
83
|
-
def validate_stop_format
|
|
84
|
-
return if stop.nil?
|
|
85
|
-
|
|
86
|
-
unless stop.is_a?(String) || stop.is_a?(Array)
|
|
87
|
-
errors.add(:stop, "must be a string or array of strings")
|
|
88
|
-
return
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
if stop.is_a?(Array)
|
|
92
|
-
stop.each_with_index do |item, index|
|
|
93
|
-
unless item.is_a?(String)
|
|
94
|
-
errors.add(:stop, "array elements must be strings at index #{index}")
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
end
|