activeagent 0.6.3 → 1.0.0.rc1
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 +210 -2
- data/README.md +15 -24
- data/lib/active_agent/base.rb +389 -39
- data/lib/active_agent/concerns/callbacks.rb +251 -0
- data/lib/active_agent/concerns/observers.rb +147 -0
- data/lib/active_agent/concerns/parameterized.rb +292 -0
- data/lib/active_agent/concerns/provider.rb +120 -0
- data/lib/active_agent/concerns/queueing.rb +36 -0
- data/lib/active_agent/concerns/rescue.rb +64 -0
- data/lib/active_agent/concerns/streaming.rb +282 -0
- data/lib/active_agent/concerns/tooling.rb +23 -0
- data/lib/active_agent/concerns/view.rb +150 -0
- data/lib/active_agent/configuration.rb +442 -20
- data/lib/active_agent/generation.rb +141 -47
- data/lib/active_agent/generation_provider/open_router/types.rb +505 -0
- data/lib/active_agent/generation_provider/xai_provider.rb +144 -0
- data/lib/active_agent/providers/_base_provider.rb +410 -0
- data/lib/active_agent/providers/anthropic/_types.rb +63 -0
- data/lib/active_agent/providers/anthropic/options.rb +53 -0
- data/lib/active_agent/providers/anthropic/request.rb +109 -0
- data/lib/active_agent/providers/anthropic/requests/_types.rb +190 -0
- data/lib/active_agent/providers/anthropic/requests/container_params.rb +19 -0
- data/lib/active_agent/providers/anthropic/requests/content/base.rb +21 -0
- data/lib/active_agent/providers/anthropic/requests/content/sources/base.rb +22 -0
- data/lib/active_agent/providers/anthropic/requests/context_management_config.rb +18 -0
- data/lib/active_agent/providers/anthropic/requests/messages/_types.rb +189 -0
- data/lib/active_agent/providers/anthropic/requests/messages/assistant.rb +23 -0
- data/lib/active_agent/providers/anthropic/requests/messages/base.rb +63 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/_types.rb +143 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/base.rb +21 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/document.rb +26 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/image.rb +23 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/redacted_thinking.rb +21 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/search_result.rb +27 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/_types.rb +171 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/base.rb +22 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/document_base64.rb +25 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/document_file.rb +23 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/document_text.rb +25 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/document_url.rb +23 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/image_base64.rb +27 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/image_file.rb +23 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/image_url.rb +23 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/text.rb +22 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/thinking.rb +23 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/tool_result.rb +24 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/tool_use.rb +28 -0
- data/lib/active_agent/providers/anthropic/requests/messages/user.rb +21 -0
- data/lib/active_agent/providers/anthropic/requests/metadata.rb +18 -0
- data/lib/active_agent/providers/anthropic/requests/response_format.rb +22 -0
- data/lib/active_agent/providers/anthropic/requests/thinking_config/_types.rb +60 -0
- data/lib/active_agent/providers/anthropic/requests/thinking_config/base.rb +20 -0
- data/lib/active_agent/providers/anthropic/requests/thinking_config/disabled.rb +16 -0
- data/lib/active_agent/providers/anthropic/requests/thinking_config/enabled.rb +20 -0
- data/lib/active_agent/providers/anthropic/requests/tool_choice/_types.rb +78 -0
- data/lib/active_agent/providers/anthropic/requests/tool_choice/any.rb +17 -0
- data/lib/active_agent/providers/anthropic/requests/tool_choice/auto.rb +17 -0
- data/lib/active_agent/providers/anthropic/requests/tool_choice/base.rb +20 -0
- data/lib/active_agent/providers/anthropic/requests/tool_choice/none.rb +16 -0
- data/lib/active_agent/providers/anthropic/requests/tool_choice/tool.rb +20 -0
- data/lib/active_agent/providers/anthropic_provider.rb +211 -0
- data/lib/active_agent/providers/common/messages/_types.rb +124 -0
- data/lib/active_agent/providers/common/messages/assistant.rb +57 -0
- data/lib/active_agent/providers/common/messages/base.rb +17 -0
- data/lib/active_agent/providers/common/messages/system.rb +20 -0
- data/lib/active_agent/providers/common/messages/tool.rb +21 -0
- data/lib/active_agent/providers/common/messages/user.rb +20 -0
- data/lib/active_agent/providers/common/model.rb +361 -0
- data/lib/active_agent/providers/common/response.rb +13 -0
- data/lib/active_agent/providers/common/responses/_types.rb +51 -0
- data/lib/active_agent/providers/common/responses/base.rb +151 -0
- data/lib/active_agent/providers/common/responses/embed.rb +33 -0
- data/lib/active_agent/providers/common/responses/format.rb +31 -0
- data/lib/active_agent/providers/common/responses/message.rb +3 -0
- data/lib/active_agent/providers/common/responses/prompt.rb +42 -0
- data/lib/active_agent/providers/concerns/exception_handler.rb +72 -0
- data/lib/active_agent/providers/concerns/previewable.rb +150 -0
- data/lib/active_agent/providers/log_subscriber.rb +360 -0
- data/lib/active_agent/providers/mock/_types.rb +77 -0
- data/lib/active_agent/providers/mock/embedding_request.rb +17 -0
- data/lib/active_agent/providers/mock/messages/_types.rb +103 -0
- data/lib/active_agent/providers/mock/messages/assistant.rb +26 -0
- data/lib/active_agent/providers/mock/messages/base.rb +63 -0
- data/lib/active_agent/providers/mock/messages/user.rb +18 -0
- data/lib/active_agent/providers/mock/options.rb +30 -0
- data/lib/active_agent/providers/mock/request.rb +38 -0
- data/lib/active_agent/providers/mock_provider.rb +311 -0
- data/lib/active_agent/providers/ollama/_types.rb +5 -0
- data/lib/active_agent/providers/ollama/chat/_types.rb +44 -0
- data/lib/active_agent/providers/ollama/chat/request.rb +70 -0
- data/lib/active_agent/providers/ollama/chat/requests/_types.rb +3 -0
- data/lib/active_agent/providers/ollama/chat/requests/messages/_types.rb +116 -0
- data/lib/active_agent/providers/ollama/chat/requests/messages/assistant.rb +19 -0
- data/lib/active_agent/providers/ollama/chat/requests/messages/user.rb +19 -0
- data/lib/active_agent/providers/ollama/embedding/_types.rb +44 -0
- data/lib/active_agent/providers/ollama/embedding/request.rb +77 -0
- data/lib/active_agent/providers/ollama/embedding/requests/_types.rb +83 -0
- data/lib/active_agent/providers/ollama/embedding/requests/options.rb +104 -0
- data/lib/active_agent/providers/ollama/options.rb +27 -0
- data/lib/active_agent/providers/ollama_provider.rb +95 -0
- data/lib/active_agent/providers/open_ai/_base.rb +58 -0
- data/lib/active_agent/providers/open_ai/_types.rb +5 -0
- data/lib/active_agent/providers/open_ai/chat/_types.rb +44 -0
- data/lib/active_agent/providers/open_ai/chat/request.rb +215 -0
- data/lib/active_agent/providers/open_ai/chat/requests/_types.rb +229 -0
- data/lib/active_agent/providers/open_ai/chat/requests/audio.rb +24 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/_types.rb +123 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/assistant.rb +42 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/base.rb +78 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/_types.rb +133 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/audio.rb +35 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/base.rb +24 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/file.rb +26 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/files/_types.rb +60 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/files/details.rb +41 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/image.rb +37 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/refusal.rb +25 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/text.rb +25 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/developer.rb +25 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/function.rb +25 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/system.rb +25 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/tool.rb +26 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/user.rb +32 -0
- data/lib/active_agent/providers/open_ai/chat/requests/prediction.rb +46 -0
- data/lib/active_agent/providers/open_ai/chat/requests/response_format.rb +53 -0
- data/lib/active_agent/providers/open_ai/chat/requests/stream_options.rb +24 -0
- data/lib/active_agent/providers/open_ai/chat/requests/tool_choice.rb +26 -0
- data/lib/active_agent/providers/open_ai/chat/requests/tools/_types.rb +5 -0
- data/lib/active_agent/providers/open_ai/chat/requests/tools/base.rb +22 -0
- data/lib/active_agent/providers/open_ai/chat/requests/tools/custom_tool.rb +41 -0
- data/lib/active_agent/providers/open_ai/chat/requests/tools/function_tool.rb +51 -0
- data/lib/active_agent/providers/open_ai/chat/requests/web_search_options.rb +45 -0
- data/lib/active_agent/providers/open_ai/chat_provider.rb +198 -0
- data/lib/active_agent/providers/open_ai/embedding/_types.rb +45 -0
- data/lib/active_agent/providers/open_ai/embedding/request.rb +85 -0
- data/lib/active_agent/providers/open_ai/embedding/requests/_types.rb +49 -0
- data/lib/active_agent/providers/open_ai/options.rb +74 -0
- data/lib/active_agent/providers/open_ai/responses/_types.rb +50 -0
- data/lib/active_agent/providers/open_ai/responses/request.rb +163 -0
- data/lib/active_agent/providers/open_ai/responses/requests/_types.rb +231 -0
- data/lib/active_agent/providers/open_ai/responses/requests/conversation.rb +23 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/_types.rb +264 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/assistant_message.rb +22 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/base.rb +89 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/code_interpreter_tool_call.rb +30 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/computer_tool_call.rb +28 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/computer_tool_call_output.rb +33 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/_types.rb +207 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/base.rb +22 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/input_audio.rb +26 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/input_file.rb +28 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/input_image.rb +28 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/input_text.rb +25 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/custom_tool_call.rb +28 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/custom_tool_call_output.rb +27 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/developer_message.rb +20 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/file_search_tool_call.rb +25 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/function_call_output.rb +32 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/function_tool_call.rb +28 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/image_gen_tool_call.rb +27 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/input_message.rb +31 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/item_reference.rb +23 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/local_shell_tool_call.rb +26 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/local_shell_tool_call_output.rb +33 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/mcp_approval_request.rb +30 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/mcp_approval_response.rb +28 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/mcp_list_tools.rb +29 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/mcp_tool_call.rb +35 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/output_message.rb +35 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/reasoning.rb +33 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/system_message.rb +20 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/tool_call_base.rb +27 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/tool_message.rb +23 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/user_message.rb +20 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/web_search_tool_call.rb +24 -0
- data/lib/active_agent/providers/open_ai/responses/requests/prompt_reference.rb +23 -0
- data/lib/active_agent/providers/open_ai/responses/requests/reasoning.rb +23 -0
- data/lib/active_agent/providers/open_ai/responses/requests/stream_options.rb +20 -0
- data/lib/active_agent/providers/open_ai/responses/requests/text/_types.rb +89 -0
- data/lib/active_agent/providers/open_ai/responses/requests/text/base.rb +22 -0
- data/lib/active_agent/providers/open_ai/responses/requests/text/json_object.rb +20 -0
- data/lib/active_agent/providers/open_ai/responses/requests/text/json_schema.rb +48 -0
- data/lib/active_agent/providers/open_ai/responses/requests/text/plain.rb +20 -0
- data/lib/active_agent/providers/open_ai/responses/requests/text.rb +41 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tool_choice.rb +26 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/_types.rb +112 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/base.rb +25 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/code_interpreter_tool.rb +23 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/computer_tool.rb +27 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/custom_tool.rb +28 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/file_search_tool.rb +27 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/function_tool.rb +29 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/image_generation_tool.rb +37 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/local_shell_tool.rb +21 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/mcp_tool.rb +41 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/web_search_preview_tool.rb +24 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/web_search_tool.rb +25 -0
- data/lib/active_agent/providers/open_ai/responses_provider.rb +153 -0
- data/lib/active_agent/providers/open_ai/schema.yml +65937 -0
- data/lib/active_agent/providers/open_ai_provider.rb +97 -0
- data/lib/active_agent/providers/open_router/_types.rb +45 -0
- data/lib/active_agent/providers/open_router/options.rb +93 -0
- data/lib/active_agent/providers/open_router/request.rb +83 -0
- data/lib/active_agent/providers/open_router/requests/_types.rb +198 -0
- data/lib/active_agent/providers/open_router/requests/message.rb +1 -0
- data/lib/active_agent/providers/open_router/requests/messages/_types.rb +59 -0
- data/lib/active_agent/providers/open_router/requests/messages/assistant.rb +20 -0
- data/lib/active_agent/providers/open_router/requests/messages/content/_types.rb +97 -0
- data/lib/active_agent/providers/open_router/requests/messages/content/file.rb +27 -0
- data/lib/active_agent/providers/open_router/requests/messages/content/files/_types.rb +61 -0
- data/lib/active_agent/providers/open_router/requests/messages/content/files/details.rb +26 -0
- data/lib/active_agent/providers/open_router/requests/messages/user.rb +30 -0
- data/lib/active_agent/providers/open_router/requests/plugin.rb +25 -0
- data/lib/active_agent/providers/open_router/requests/plugins/_types.rb +46 -0
- data/lib/active_agent/providers/open_router/requests/plugins/pdf_config.rb +29 -0
- data/lib/active_agent/providers/open_router/requests/prediction.rb +17 -0
- data/lib/active_agent/providers/open_router/requests/provider_preferences/_types.rb +44 -0
- data/lib/active_agent/providers/open_router/requests/provider_preferences/max_price.rb +30 -0
- data/lib/active_agent/providers/open_router/requests/provider_preferences.rb +64 -0
- data/lib/active_agent/providers/open_router/requests/response_format.rb +49 -0
- data/lib/active_agent/providers/open_router_provider.rb +53 -0
- data/lib/active_agent/providers/openai_provider.rb +2 -0
- data/lib/active_agent/providers/openrouter_provider.rb +2 -0
- data/lib/active_agent/railtie.rb +8 -6
- data/lib/active_agent/schema_generator.rb +333 -166
- data/lib/active_agent/version.rb +1 -1
- data/lib/active_agent.rb +112 -36
- data/lib/generators/active_agent/agent/USAGE +78 -0
- data/lib/generators/active_agent/{agent_generator.rb → agent/agent_generator.rb} +14 -4
- data/lib/generators/active_agent/install/USAGE +25 -0
- data/lib/generators/active_agent/{install_generator.rb → install/install_generator.rb} +1 -19
- data/lib/generators/active_agent/templates/agent.rb.tt +7 -3
- data/lib/generators/active_agent/templates/application_agent.rb.tt +0 -2
- data/lib/generators/erb/agent_generator.rb +31 -16
- data/lib/generators/erb/templates/instructions.md.erb.tt +3 -0
- data/lib/generators/erb/templates/instructions.md.tt +3 -0
- data/lib/generators/erb/templates/instructions.text.tt +1 -0
- data/lib/generators/erb/templates/message.md.erb.tt +5 -0
- data/lib/generators/erb/templates/schema.json.tt +10 -0
- data/lib/generators/test_unit/agent_generator.rb +1 -1
- data/lib/generators/test_unit/templates/functional_test.rb.tt +4 -2
- metadata +320 -65
- data/lib/active_agent/action_prompt/action.rb +0 -13
- data/lib/active_agent/action_prompt/base.rb +0 -623
- data/lib/active_agent/action_prompt/message.rb +0 -126
- data/lib/active_agent/action_prompt/prompt.rb +0 -136
- data/lib/active_agent/action_prompt.rb +0 -19
- data/lib/active_agent/callbacks.rb +0 -33
- data/lib/active_agent/generation_provider/anthropic_provider.rb +0 -163
- data/lib/active_agent/generation_provider/base.rb +0 -55
- data/lib/active_agent/generation_provider/base_adapter.rb +0 -19
- data/lib/active_agent/generation_provider/error_handling.rb +0 -167
- data/lib/active_agent/generation_provider/log_subscriber.rb +0 -92
- data/lib/active_agent/generation_provider/message_formatting.rb +0 -107
- data/lib/active_agent/generation_provider/ollama_provider.rb +0 -66
- data/lib/active_agent/generation_provider/open_ai_provider.rb +0 -279
- data/lib/active_agent/generation_provider/open_router_provider.rb +0 -385
- data/lib/active_agent/generation_provider/parameter_builder.rb +0 -119
- data/lib/active_agent/generation_provider/response.rb +0 -75
- data/lib/active_agent/generation_provider/responses_adapter.rb +0 -44
- data/lib/active_agent/generation_provider/stream_processing.rb +0 -58
- data/lib/active_agent/generation_provider/tool_management.rb +0 -142
- data/lib/active_agent/generation_provider.rb +0 -67
- data/lib/active_agent/log_subscriber.rb +0 -44
- data/lib/active_agent/parameterized.rb +0 -75
- data/lib/active_agent/prompt_helper.rb +0 -19
- data/lib/active_agent/queued_generation.rb +0 -12
- data/lib/active_agent/rescuable.rb +0 -34
- data/lib/active_agent/sanitizers.rb +0 -40
- data/lib/active_agent/streaming.rb +0 -34
- data/lib/active_agent/test_case.rb +0 -125
- data/lib/generators/USAGE +0 -47
- data/lib/generators/active_agent/USAGE +0 -56
- data/lib/generators/erb/install_generator.rb +0 -44
- data/lib/generators/erb/templates/layout.html.erb.tt +0 -1
- data/lib/generators/erb/templates/layout.json.erb.tt +0 -1
- data/lib/generators/erb/templates/layout.text.erb.tt +0 -1
- data/lib/generators/erb/templates/view.html.erb.tt +0 -5
- data/lib/generators/erb/templates/view.json.erb.tt +0 -16
- /data/lib/active_agent/{preview.rb → concerns/preview.rb} +0 -0
- /data/lib/generators/erb/templates/{view.text.erb.tt → message.text.erb.tt} +0 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "request"
|
|
4
|
+
|
|
5
|
+
module ActiveAgent
|
|
6
|
+
module Providers
|
|
7
|
+
module Ollama
|
|
8
|
+
module Chat
|
|
9
|
+
# Type for Request model
|
|
10
|
+
class RequestType < ActiveModel::Type::Value
|
|
11
|
+
def cast(value)
|
|
12
|
+
case value
|
|
13
|
+
when Request
|
|
14
|
+
value
|
|
15
|
+
when Hash
|
|
16
|
+
Request.new(**value.deep_symbolize_keys)
|
|
17
|
+
when nil
|
|
18
|
+
nil
|
|
19
|
+
else
|
|
20
|
+
raise ArgumentError, "Cannot cast #{value.class} to Request"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def serialize(value)
|
|
25
|
+
case value
|
|
26
|
+
when Request
|
|
27
|
+
value.serialize
|
|
28
|
+
when Hash
|
|
29
|
+
value
|
|
30
|
+
when nil
|
|
31
|
+
nil
|
|
32
|
+
else
|
|
33
|
+
raise ArgumentError, "Cannot serialize #{value.class}"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def deserialize(value)
|
|
38
|
+
cast(value)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../open_ai/chat/request"
|
|
4
|
+
require_relative "requests/_types"
|
|
5
|
+
|
|
6
|
+
module ActiveAgent
|
|
7
|
+
module Providers
|
|
8
|
+
module Ollama
|
|
9
|
+
module Chat
|
|
10
|
+
# Ollama uses the same request structure as OpenAI's chat completion API
|
|
11
|
+
# This class exists to allow for Ollama-specific customizations.
|
|
12
|
+
class Request < OpenAI::Chat::Request
|
|
13
|
+
# Messages array (required)
|
|
14
|
+
attribute :messages, Requests::Messages::MessagesType.new
|
|
15
|
+
|
|
16
|
+
# Ollama-specific parameters
|
|
17
|
+
|
|
18
|
+
# Format: return response in json or as a JSON schema
|
|
19
|
+
# Can be "json" or a JSON schema object
|
|
20
|
+
attribute :format
|
|
21
|
+
|
|
22
|
+
# Options: additional model parameters (temperature, num_predict, etc.)
|
|
23
|
+
# Hash of key-value pairs for model-specific options
|
|
24
|
+
attribute :options
|
|
25
|
+
|
|
26
|
+
# Keep alive: controls how long the model stays loaded in memory
|
|
27
|
+
# String duration (e.g., "5m", "1h") or integer in seconds
|
|
28
|
+
# Default: "5m"
|
|
29
|
+
attribute :keep_alive
|
|
30
|
+
|
|
31
|
+
# Raw: if true, no formatting will be applied to the prompt
|
|
32
|
+
# You may use this if you are specifying a full templated prompt
|
|
33
|
+
attribute :raw, :boolean, default: false
|
|
34
|
+
|
|
35
|
+
# Validations for Ollama-specific parameters
|
|
36
|
+
validate :validate_format
|
|
37
|
+
validate :validate_options_format
|
|
38
|
+
|
|
39
|
+
# Common Format Compatability
|
|
40
|
+
def messages=(value)
|
|
41
|
+
case value
|
|
42
|
+
when Array
|
|
43
|
+
super((messages || []) | value)
|
|
44
|
+
else
|
|
45
|
+
super((messages || []) | [ value ])
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
|
|
51
|
+
def validate_format
|
|
52
|
+
return if format.nil?
|
|
53
|
+
return if format == "json"
|
|
54
|
+
return if format.is_a?(Hash) # JSON schema object
|
|
55
|
+
|
|
56
|
+
errors.add(:format, "must be 'json' or a JSON schema object")
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def validate_options_format
|
|
60
|
+
return if options.nil?
|
|
61
|
+
|
|
62
|
+
unless options.is_a?(Hash)
|
|
63
|
+
errors.add(:options, "must be a hash of model parameters")
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -0,0 +1,116 @@
|
|
|
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
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "request"
|
|
4
|
+
|
|
5
|
+
module ActiveAgent
|
|
6
|
+
module Providers
|
|
7
|
+
module Ollama
|
|
8
|
+
module Embedding
|
|
9
|
+
# Type for Request model
|
|
10
|
+
class RequestType < ActiveModel::Type::Value
|
|
11
|
+
def cast(value)
|
|
12
|
+
case value
|
|
13
|
+
when Request
|
|
14
|
+
value
|
|
15
|
+
when Hash
|
|
16
|
+
Request.new(**value.deep_symbolize_keys)
|
|
17
|
+
when nil
|
|
18
|
+
nil
|
|
19
|
+
else
|
|
20
|
+
raise ArgumentError, "Cannot cast #{value.class} to Request"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def serialize(value)
|
|
25
|
+
case value
|
|
26
|
+
when Request
|
|
27
|
+
value.serialize
|
|
28
|
+
when Hash
|
|
29
|
+
value
|
|
30
|
+
when nil
|
|
31
|
+
nil
|
|
32
|
+
else
|
|
33
|
+
raise ArgumentError, "Cannot serialize #{value.class}"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def deserialize(value)
|
|
38
|
+
cast(value)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "active_agent/providers/common/model"
|
|
4
|
+
require_relative "requests/_types"
|
|
5
|
+
|
|
6
|
+
module ActiveAgent
|
|
7
|
+
module Providers
|
|
8
|
+
module Ollama
|
|
9
|
+
module Embedding
|
|
10
|
+
class Request < Common::BaseModel
|
|
11
|
+
# Model name to generate embeddings from (required)
|
|
12
|
+
attribute :model, :string
|
|
13
|
+
|
|
14
|
+
# Input text or list of text to generate embeddings for (required)
|
|
15
|
+
# Can be a string or array of strings
|
|
16
|
+
attribute :input, Requests::InputType.new
|
|
17
|
+
|
|
18
|
+
# Truncates the end of each input to fit within context length (optional)
|
|
19
|
+
# Returns error if false and context length is exceeded
|
|
20
|
+
# Defaults to true
|
|
21
|
+
attribute :truncate, :boolean, default: true
|
|
22
|
+
|
|
23
|
+
# Additional model parameters listed in the documentation for the Modelfile (optional)
|
|
24
|
+
# such as temperature
|
|
25
|
+
attribute :options, Requests::OptionsType.new
|
|
26
|
+
|
|
27
|
+
# Controls how long the model will stay loaded into memory following the request (optional)
|
|
28
|
+
# Default: 5m
|
|
29
|
+
attribute :keep_alive, :string
|
|
30
|
+
|
|
31
|
+
# Validations
|
|
32
|
+
validates :model, :input, presence: true
|
|
33
|
+
|
|
34
|
+
# Custom validations
|
|
35
|
+
validate :validate_input_format
|
|
36
|
+
validate :validate_input_not_empty
|
|
37
|
+
|
|
38
|
+
# To merge over global prompt/model options over
|
|
39
|
+
delegate_attributes :mirostat, :mirostat_eta, :mirostat_tau, :num_ctx, :repeat_last_n, :repeat_penalty,
|
|
40
|
+
:temperature, :seed, :num_predict, :top_k, :top_p, :min_p,
|
|
41
|
+
to: :options
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
def validate_input_format
|
|
46
|
+
return if input.nil?
|
|
47
|
+
|
|
48
|
+
unless input.is_a?(Array)
|
|
49
|
+
errors.add(:input, "must be stored as an array internally")
|
|
50
|
+
return
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Validate array contents - Ollama only accepts strings
|
|
54
|
+
input.each_with_index do |item, index|
|
|
55
|
+
unless item.is_a?(String)
|
|
56
|
+
errors.add(:input, "array elements must be strings at index #{index}")
|
|
57
|
+
next
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
if item.empty?
|
|
61
|
+
errors.add(:input, "cannot contain empty strings at index #{index}")
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def validate_input_not_empty
|
|
67
|
+
return if input.nil?
|
|
68
|
+
|
|
69
|
+
if input.is_a?(Array) && input.empty?
|
|
70
|
+
errors.add(:input, "cannot be an empty array")
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
|
@@ -0,0 +1,104 @@
|
|
|
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
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../open_ai/options"
|
|
4
|
+
|
|
5
|
+
module ActiveAgent
|
|
6
|
+
module Providers
|
|
7
|
+
module Ollama
|
|
8
|
+
class Options < ActiveAgent::Providers::OpenAI::Options
|
|
9
|
+
attribute :base_url, :string, fallback: "http://127.0.0.1:11434/v1"
|
|
10
|
+
attribute :api_key, :string, fallback: "ollama"
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
|
|
14
|
+
def resolve_api_key(kwargs)
|
|
15
|
+
kwargs[:api_key] ||
|
|
16
|
+
kwargs[:access_token] ||
|
|
17
|
+
ENV["OLLAMA_API_KEY"] ||
|
|
18
|
+
ENV["OLLAMA_ACCESS_TOKEN"]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Not Used as Part of Ollama
|
|
22
|
+
def resolve_organization_id(settings) = nil
|
|
23
|
+
def resolve_project_id(settings) = nil
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|