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,85 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "active_agent/providers/common/model"
|
|
4
|
+
require_relative "_types"
|
|
5
|
+
|
|
6
|
+
module ActiveAgent
|
|
7
|
+
module Providers
|
|
8
|
+
module OpenAI
|
|
9
|
+
module Embedding
|
|
10
|
+
class Request < Common::BaseModel
|
|
11
|
+
# Input text to embed (required)
|
|
12
|
+
# Can be a string or array of strings or array of token arrays
|
|
13
|
+
# - Must not exceed max input tokens for the model (8192 for all embedding models)
|
|
14
|
+
# - Cannot be an empty string
|
|
15
|
+
# - Arrays must be 2048 dimensions or less
|
|
16
|
+
# - Maximum of 300,000 tokens summed across all inputs in a single request
|
|
17
|
+
attribute :input, Requests::InputType.new
|
|
18
|
+
|
|
19
|
+
# Model ID (required)
|
|
20
|
+
attribute :model, :string
|
|
21
|
+
|
|
22
|
+
# Number of dimensions for output embeddings (optional)
|
|
23
|
+
# Only supported in text-embedding-3 and later models
|
|
24
|
+
attribute :dimensions, :integer
|
|
25
|
+
|
|
26
|
+
# Format for returned embeddings (optional)
|
|
27
|
+
# Can be "float" or "base64"
|
|
28
|
+
attribute :encoding_format, :string, default: "float"
|
|
29
|
+
|
|
30
|
+
# Unique identifier for end-user (optional, deprecated)
|
|
31
|
+
# Can help OpenAI monitor and detect abuse
|
|
32
|
+
attribute :user, :string
|
|
33
|
+
|
|
34
|
+
# Validations
|
|
35
|
+
validates :input, :model, presence: true
|
|
36
|
+
validates :encoding_format, inclusion: { in: %w[float base64] }, allow_nil: true
|
|
37
|
+
validates :dimensions, numericality: { greater_than: 0 }, allow_nil: true
|
|
38
|
+
|
|
39
|
+
# Custom validations
|
|
40
|
+
validate :validate_input_format
|
|
41
|
+
validate :validate_input_not_empty
|
|
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
|
|
54
|
+
input.each_with_index do |item, index|
|
|
55
|
+
case item
|
|
56
|
+
when String
|
|
57
|
+
if item.empty?
|
|
58
|
+
errors.add(:input, "cannot contain empty strings at index #{index}")
|
|
59
|
+
end
|
|
60
|
+
when Array
|
|
61
|
+
# Token array validation
|
|
62
|
+
if item.length > 2048
|
|
63
|
+
errors.add(:input, "token arrays must be 2048 dimensions or less at index #{index}")
|
|
64
|
+
end
|
|
65
|
+
if item.empty?
|
|
66
|
+
errors.add(:input, "cannot contain empty token arrays at index #{index}")
|
|
67
|
+
end
|
|
68
|
+
else
|
|
69
|
+
errors.add(:input, "array elements must be strings or token arrays at index #{index}")
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def validate_input_not_empty
|
|
75
|
+
return if input.nil?
|
|
76
|
+
|
|
77
|
+
if input.is_a?(Array) && input.empty?
|
|
78
|
+
errors.add(:input, "cannot be an empty array")
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ActiveAgent
|
|
4
|
+
module Providers
|
|
5
|
+
module OpenAI
|
|
6
|
+
module Embedding
|
|
7
|
+
module Requests
|
|
8
|
+
# Custom type for handling embedding input
|
|
9
|
+
# Can be a string, array of strings, or array of token arrays
|
|
10
|
+
# Always stores internally as an array for consistency
|
|
11
|
+
class InputType < ActiveModel::Type::Value
|
|
12
|
+
def cast(value)
|
|
13
|
+
case value
|
|
14
|
+
when String
|
|
15
|
+
[ value.presence ].compact
|
|
16
|
+
when Array
|
|
17
|
+
value.compact
|
|
18
|
+
when nil
|
|
19
|
+
nil
|
|
20
|
+
else
|
|
21
|
+
raise ArgumentError, "Cannot cast #{value.class} to Input (expected String or Array)"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def serialize(value)
|
|
26
|
+
case value
|
|
27
|
+
when Array
|
|
28
|
+
# Return single string if array has only one string element
|
|
29
|
+
if value in [ String => string ]
|
|
30
|
+
string
|
|
31
|
+
else
|
|
32
|
+
value
|
|
33
|
+
end
|
|
34
|
+
when nil
|
|
35
|
+
nil
|
|
36
|
+
else
|
|
37
|
+
raise ArgumentError, "Cannot serialize #{value.class}"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def deserialize(value)
|
|
42
|
+
cast(value)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "active_agent/providers/common/model"
|
|
4
|
+
|
|
5
|
+
module ActiveAgent
|
|
6
|
+
module Providers
|
|
7
|
+
module OpenAI
|
|
8
|
+
class Options < Common::BaseModel
|
|
9
|
+
attribute :api_key, :string
|
|
10
|
+
attribute :organization, :string # Organization ID
|
|
11
|
+
attribute :project, :string # Project ID ,
|
|
12
|
+
attribute :webhook_secret, :string
|
|
13
|
+
attribute :base_url, :string
|
|
14
|
+
|
|
15
|
+
attribute :max_retries, :integer, default: ::OpenAI::Client::DEFAULT_MAX_RETRIES
|
|
16
|
+
attribute :timeout, :float, default: ::OpenAI::Client::DEFAULT_TIMEOUT_IN_SECONDS
|
|
17
|
+
attribute :initial_retry_delay, :float, default: ::OpenAI::Client::DEFAULT_INITIAL_RETRY_DELAY
|
|
18
|
+
attribute :max_retry_delay, :float, default: ::OpenAI::Client::DEFAULT_MAX_RETRY_DELAY
|
|
19
|
+
|
|
20
|
+
validates :api_key, presence: true
|
|
21
|
+
|
|
22
|
+
# Backwards Compatibility
|
|
23
|
+
alias_attribute :host, :base_url
|
|
24
|
+
alias_attribute :uri_base, :base_url
|
|
25
|
+
alias_attribute :organization_id, :organization
|
|
26
|
+
alias_attribute :project_id, :project
|
|
27
|
+
alias_attribute :access_token, :api_key
|
|
28
|
+
alias_attribute :request_timeout, :timeout
|
|
29
|
+
|
|
30
|
+
# Initialize from a hash (kwargs) with fallback to environment variables and OpenAI gem configuration
|
|
31
|
+
def initialize(kwargs = {})
|
|
32
|
+
kwargs = kwargs.deep_symbolize_keys if kwargs.respond_to?(:deep_symbolize_keys)
|
|
33
|
+
|
|
34
|
+
super(**deep_compact(kwargs.except(:default_url_options).merge(
|
|
35
|
+
api_key: resolve_api_key(kwargs),
|
|
36
|
+
organization_id: resolve_organization_id(kwargs),
|
|
37
|
+
project_id: resolve_project_id(kwargs),
|
|
38
|
+
)))
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def extra_headers
|
|
42
|
+
{}
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
def resolve_api_key(kwargs)
|
|
48
|
+
kwargs[:api_key] ||
|
|
49
|
+
kwargs[:access_token] ||
|
|
50
|
+
ENV["OPENAI_API_KEY"] ||
|
|
51
|
+
ENV["OPEN_AI_API_KEY"] ||
|
|
52
|
+
ENV["OPENAI_ACCESS_TOKEN"] ||
|
|
53
|
+
ENV["OPEN_AI_ACCESS_TOKEN"]
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def resolve_organization_id(kwargs)
|
|
57
|
+
kwargs[:organization] ||
|
|
58
|
+
kwargs[:organization_id] ||
|
|
59
|
+
ENV["OPENAI_ORG_ID"] ||
|
|
60
|
+
ENV["OPEN_AI_ORG_ID"] ||
|
|
61
|
+
ENV["OPENAI_ORGANIZATION_ID"] ||
|
|
62
|
+
ENV["OPEN_AI_ORGANIZATION_ID"]
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def resolve_project_id(kwargs)
|
|
66
|
+
kwargs[:project] ||
|
|
67
|
+
kwargs[:project_id]
|
|
68
|
+
ENV["OPENAI_PROJECT_ID"] ||
|
|
69
|
+
ENV["OPEN_AI_PROJECT_ID"]
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "request"
|
|
4
|
+
|
|
5
|
+
module ActiveAgent
|
|
6
|
+
module Providers
|
|
7
|
+
module OpenAI
|
|
8
|
+
module Responses
|
|
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
|
+
hash = value.serialize
|
|
28
|
+
|
|
29
|
+
if hash[:input] in [ { role: "user", content: String } ]
|
|
30
|
+
hash[:input] = hash[:input][0][:content]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
hash
|
|
34
|
+
when Hash
|
|
35
|
+
value
|
|
36
|
+
when nil
|
|
37
|
+
nil
|
|
38
|
+
else
|
|
39
|
+
raise ArgumentError, "Cannot serialize #{value.class}"
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def deserialize(value)
|
|
44
|
+
cast(value)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,163 @@
|
|
|
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 OpenAI
|
|
9
|
+
module Responses
|
|
10
|
+
class Request < Common::BaseModel
|
|
11
|
+
# Background execution
|
|
12
|
+
attribute :background, :boolean, default: false
|
|
13
|
+
|
|
14
|
+
# Conversation
|
|
15
|
+
attribute :conversation, Requests::ConversationType.new
|
|
16
|
+
|
|
17
|
+
# Include additional output data
|
|
18
|
+
attribute :include, default: -> { [] } # Array of strings
|
|
19
|
+
|
|
20
|
+
# Input items (text, image, or file inputs)
|
|
21
|
+
attribute :input, Requests::Inputs::MessagesType.new
|
|
22
|
+
|
|
23
|
+
# Instructions (system/developer message)
|
|
24
|
+
attribute :instructions, :string
|
|
25
|
+
|
|
26
|
+
# Token limits
|
|
27
|
+
attribute :max_output_tokens, :integer
|
|
28
|
+
attribute :max_tool_calls, :integer
|
|
29
|
+
|
|
30
|
+
# Metadata
|
|
31
|
+
attribute :metadata # Hash of key-value pairs
|
|
32
|
+
|
|
33
|
+
# Model ID
|
|
34
|
+
attribute :model, :string
|
|
35
|
+
|
|
36
|
+
# Parallel tool calls
|
|
37
|
+
attribute :parallel_tool_calls, :boolean, default: true
|
|
38
|
+
|
|
39
|
+
# Previous response ID for multi-turn conversations
|
|
40
|
+
attribute :previous_response_id, :string
|
|
41
|
+
|
|
42
|
+
# Prompt template reference
|
|
43
|
+
attribute :prompt, Requests::PromptReferenceType.new
|
|
44
|
+
|
|
45
|
+
# Cache key for optimization
|
|
46
|
+
attribute :prompt_cache_key, :string
|
|
47
|
+
|
|
48
|
+
# Reasoning configuration (for o-series and gpt-5 models)
|
|
49
|
+
attribute :reasoning, Requests::ReasoningType.new
|
|
50
|
+
|
|
51
|
+
# Safety identifier for usage policy detection
|
|
52
|
+
attribute :safety_identifier, :string
|
|
53
|
+
|
|
54
|
+
# Service tier
|
|
55
|
+
attribute :service_tier, :string, default: "auto"
|
|
56
|
+
|
|
57
|
+
# Storage
|
|
58
|
+
attribute :store, :boolean, default: true
|
|
59
|
+
|
|
60
|
+
# Streaming
|
|
61
|
+
attribute :stream, :boolean, default: false
|
|
62
|
+
attribute :stream_options, Requests::StreamOptionsType.new
|
|
63
|
+
|
|
64
|
+
# Temperature sampling
|
|
65
|
+
attribute :temperature, :float, default: 1
|
|
66
|
+
|
|
67
|
+
# Text response configuration
|
|
68
|
+
attribute :text, Requests::TextType.new
|
|
69
|
+
|
|
70
|
+
# Tool choice
|
|
71
|
+
attribute :tool_choice, Requests::ToolChoiceType.new
|
|
72
|
+
|
|
73
|
+
# Tools array
|
|
74
|
+
attribute :tools, Requests::Tools::ToolsType.new
|
|
75
|
+
|
|
76
|
+
# Top logprobs
|
|
77
|
+
attribute :top_logprobs, :integer
|
|
78
|
+
|
|
79
|
+
# Top P sampling
|
|
80
|
+
attribute :top_p, :float, default: 1
|
|
81
|
+
|
|
82
|
+
# Truncation strategy
|
|
83
|
+
attribute :truncation, :string, default: "disabled"
|
|
84
|
+
|
|
85
|
+
# User identifier (deprecated, use safety_identifier or prompt_cache_key)
|
|
86
|
+
attribute :user, :string
|
|
87
|
+
|
|
88
|
+
# Validations
|
|
89
|
+
validates :max_output_tokens, numericality: { greater_than: 0 }, allow_nil: true
|
|
90
|
+
validates :max_tool_calls, numericality: { greater_than: 0 }, allow_nil: true
|
|
91
|
+
validates :temperature, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 2 }, allow_nil: true
|
|
92
|
+
validates :top_p, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 1 }, allow_nil: true
|
|
93
|
+
validates :top_logprobs, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 20 }, allow_nil: true
|
|
94
|
+
validates :service_tier, inclusion: { in: %w[auto default flex priority] }, allow_nil: true
|
|
95
|
+
validates :truncation, inclusion: { in: %w[auto disabled] }, allow_nil: true
|
|
96
|
+
|
|
97
|
+
validate :validate_conversation_exclusivity
|
|
98
|
+
validate :validate_metadata_format
|
|
99
|
+
validate :validate_include_values
|
|
100
|
+
|
|
101
|
+
# Common Format Mapping
|
|
102
|
+
alias_attribute :messages, :input
|
|
103
|
+
alias_attribute :message, :input
|
|
104
|
+
alias_attribute :response_format, :text
|
|
105
|
+
|
|
106
|
+
# Common Format Compatability
|
|
107
|
+
def instructions=(value)
|
|
108
|
+
super(value.is_a?(Array) ? value.join("\n") : value)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
private
|
|
112
|
+
|
|
113
|
+
def validate_conversation_exclusivity
|
|
114
|
+
if conversation.present? && previous_response_id.present?
|
|
115
|
+
errors.add(:base, "Cannot use both conversation and previous_response_id")
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def validate_metadata_format
|
|
120
|
+
return if metadata.nil?
|
|
121
|
+
|
|
122
|
+
unless metadata.is_a?(Hash)
|
|
123
|
+
errors.add(:metadata, "must be a hash")
|
|
124
|
+
return
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
metadata.each do |key, value|
|
|
128
|
+
if key.to_s.length > 64
|
|
129
|
+
errors.add(:metadata, "keys must be 64 characters or less")
|
|
130
|
+
end
|
|
131
|
+
if value.to_s.length > 512
|
|
132
|
+
errors.add(:metadata, "values must be 512 characters or less")
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
if metadata.size > 16
|
|
137
|
+
errors.add(:metadata, "must have 16 key-value pairs or less")
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def validate_include_values
|
|
142
|
+
return if include.nil? || include.empty?
|
|
143
|
+
|
|
144
|
+
valid_include_values = [
|
|
145
|
+
"web_search_call.action.sources",
|
|
146
|
+
"code_interpreter_call.outputs",
|
|
147
|
+
"computer_call_output.output.image_url",
|
|
148
|
+
"file_search_call.results",
|
|
149
|
+
"message.input_image.image_url",
|
|
150
|
+
"message.output_text.logprobs",
|
|
151
|
+
"reasoning.encrypted_content"
|
|
152
|
+
]
|
|
153
|
+
|
|
154
|
+
invalid_values = include - valid_include_values
|
|
155
|
+
if invalid_values.any?
|
|
156
|
+
errors.add(:include, "contains invalid values: #{invalid_values.join(', ')}")
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "inputs/_types"
|
|
4
|
+
require_relative "tools/_types"
|
|
5
|
+
|
|
6
|
+
require_relative "conversation"
|
|
7
|
+
require_relative "prompt_reference"
|
|
8
|
+
require_relative "reasoning"
|
|
9
|
+
require_relative "stream_options"
|
|
10
|
+
require_relative "text"
|
|
11
|
+
require_relative "tool_choice"
|
|
12
|
+
|
|
13
|
+
module ActiveAgent
|
|
14
|
+
module Providers
|
|
15
|
+
module OpenAI
|
|
16
|
+
module Responses
|
|
17
|
+
module Requests
|
|
18
|
+
class ConversationType < ActiveModel::Type::Value
|
|
19
|
+
def cast(value)
|
|
20
|
+
case value
|
|
21
|
+
when Conversation
|
|
22
|
+
value
|
|
23
|
+
when Hash
|
|
24
|
+
Conversation.new(**value.symbolize_keys)
|
|
25
|
+
when String
|
|
26
|
+
value # Can be a conversation ID string
|
|
27
|
+
when nil
|
|
28
|
+
nil
|
|
29
|
+
else
|
|
30
|
+
raise ArgumentError, "Cannot cast #{value.class} to Conversation"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def serialize(value)
|
|
35
|
+
case value
|
|
36
|
+
when Conversation
|
|
37
|
+
value.serialize
|
|
38
|
+
when Hash
|
|
39
|
+
value
|
|
40
|
+
when String
|
|
41
|
+
value
|
|
42
|
+
when nil
|
|
43
|
+
nil
|
|
44
|
+
else
|
|
45
|
+
raise ArgumentError, "Cannot serialize #{value.class}"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def deserialize(value)
|
|
50
|
+
cast(value)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
class PromptReferenceType < ActiveModel::Type::Value
|
|
55
|
+
def cast(value)
|
|
56
|
+
case value
|
|
57
|
+
when PromptReference
|
|
58
|
+
value
|
|
59
|
+
when Hash
|
|
60
|
+
PromptReference.new(**value.symbolize_keys)
|
|
61
|
+
when nil
|
|
62
|
+
nil
|
|
63
|
+
else
|
|
64
|
+
raise ArgumentError, "Cannot cast #{value.class} to PromptReference"
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def serialize(value)
|
|
69
|
+
case value
|
|
70
|
+
when PromptReference
|
|
71
|
+
value.serialize
|
|
72
|
+
when Hash
|
|
73
|
+
value
|
|
74
|
+
when nil
|
|
75
|
+
nil
|
|
76
|
+
else
|
|
77
|
+
raise ArgumentError, "Cannot serialize #{value.class}"
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def deserialize(value)
|
|
82
|
+
cast(value)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
class ReasoningType < ActiveModel::Type::Value
|
|
87
|
+
def cast(value)
|
|
88
|
+
case value
|
|
89
|
+
when Reasoning
|
|
90
|
+
value
|
|
91
|
+
when Hash
|
|
92
|
+
Reasoning.new(**value.symbolize_keys)
|
|
93
|
+
when nil
|
|
94
|
+
nil
|
|
95
|
+
else
|
|
96
|
+
raise ArgumentError, "Cannot cast #{value.class} to Reasoning"
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def serialize(value)
|
|
101
|
+
case value
|
|
102
|
+
when Reasoning
|
|
103
|
+
value.serialize
|
|
104
|
+
when Hash
|
|
105
|
+
value
|
|
106
|
+
when nil
|
|
107
|
+
nil
|
|
108
|
+
else
|
|
109
|
+
raise ArgumentError, "Cannot serialize #{value.class}"
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def deserialize(value)
|
|
114
|
+
cast(value)
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
class StreamOptionsType < ActiveModel::Type::Value
|
|
119
|
+
def cast(value)
|
|
120
|
+
case value
|
|
121
|
+
when StreamOptions
|
|
122
|
+
value
|
|
123
|
+
when Hash
|
|
124
|
+
StreamOptions.new(**value.symbolize_keys)
|
|
125
|
+
when nil
|
|
126
|
+
nil
|
|
127
|
+
else
|
|
128
|
+
raise ArgumentError, "Cannot cast #{value.class} to StreamOptions"
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def serialize(value)
|
|
133
|
+
case value
|
|
134
|
+
when StreamOptions
|
|
135
|
+
value.serialize
|
|
136
|
+
when Hash
|
|
137
|
+
value
|
|
138
|
+
when nil
|
|
139
|
+
nil
|
|
140
|
+
else
|
|
141
|
+
raise ArgumentError, "Cannot serialize #{value.class}"
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def deserialize(value)
|
|
146
|
+
cast(value)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
class TextType < ActiveModel::Type::Value
|
|
151
|
+
def cast(value)
|
|
152
|
+
case value
|
|
153
|
+
when Text
|
|
154
|
+
value
|
|
155
|
+
when Hash
|
|
156
|
+
if value.key?(:json_schema)
|
|
157
|
+
Text.new(**value.symbolize_keys.except(:type)) # Prevent Losing the Schema on Format setting
|
|
158
|
+
else
|
|
159
|
+
Text.new(**value.symbolize_keys)
|
|
160
|
+
end
|
|
161
|
+
when nil
|
|
162
|
+
nil
|
|
163
|
+
else
|
|
164
|
+
raise ArgumentError, "Cannot cast #{value.class} to Text"
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def serialize(value)
|
|
169
|
+
case value
|
|
170
|
+
when Text
|
|
171
|
+
value.serialize
|
|
172
|
+
when Hash
|
|
173
|
+
value
|
|
174
|
+
when nil
|
|
175
|
+
nil
|
|
176
|
+
else
|
|
177
|
+
raise ArgumentError, "Cannot serialize #{value.class}"
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def deserialize(value)
|
|
182
|
+
cast(value)
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
class ToolChoiceType < ActiveModel::Type::Value
|
|
187
|
+
def cast(value)
|
|
188
|
+
case value
|
|
189
|
+
when ToolChoice
|
|
190
|
+
value
|
|
191
|
+
when Hash
|
|
192
|
+
ToolChoice.new(**value.symbolize_keys)
|
|
193
|
+
when String
|
|
194
|
+
ToolChoice.new(mode: value)
|
|
195
|
+
when nil
|
|
196
|
+
nil
|
|
197
|
+
else
|
|
198
|
+
raise ArgumentError, "Cannot cast #{value.class} to ToolChoice"
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def serialize(value)
|
|
203
|
+
case value
|
|
204
|
+
when ToolChoice
|
|
205
|
+
hash = value.serialize
|
|
206
|
+
# If it's just a mode string, return the string
|
|
207
|
+
if hash[:mode].present? && hash[:type].blank? && hash[:function].blank? && hash[:custom].blank?
|
|
208
|
+
hash[:mode]
|
|
209
|
+
else
|
|
210
|
+
hash
|
|
211
|
+
end
|
|
212
|
+
when Hash
|
|
213
|
+
value
|
|
214
|
+
when String
|
|
215
|
+
value
|
|
216
|
+
when nil
|
|
217
|
+
nil
|
|
218
|
+
else
|
|
219
|
+
raise ArgumentError, "Cannot serialize #{value.class}"
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def deserialize(value)
|
|
224
|
+
cast(value)
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "active_agent/providers/common/model"
|
|
4
|
+
|
|
5
|
+
module ActiveAgent
|
|
6
|
+
module Providers
|
|
7
|
+
module OpenAI
|
|
8
|
+
module Responses
|
|
9
|
+
module Requests
|
|
10
|
+
class Conversation < Common::BaseModel
|
|
11
|
+
# Conversation ID
|
|
12
|
+
attribute :id, :string
|
|
13
|
+
|
|
14
|
+
# Optional: Store conversation items
|
|
15
|
+
attribute :store, :boolean
|
|
16
|
+
|
|
17
|
+
validates :id, presence: true, if: -> { store.nil? }
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|