ruby_llm-agents 1.0.0 → 1.2.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/app/controllers/concerns/ruby_llm/agents/paginatable.rb +9 -3
- data/app/controllers/concerns/ruby_llm/agents/sortable.rb +58 -0
- data/app/controllers/ruby_llm/agents/agents_controller.rb +59 -16
- data/app/controllers/ruby_llm/agents/dashboard_controller.rb +144 -20
- data/app/controllers/ruby_llm/agents/executions_controller.rb +13 -16
- data/app/controllers/ruby_llm/agents/workflows_controller.rb +279 -90
- data/app/helpers/ruby_llm/agents/application_helper.rb +100 -0
- data/app/mailers/ruby_llm/agents/alert_mailer.rb +84 -0
- data/app/mailers/ruby_llm/agents/application_mailer.rb +28 -0
- data/app/models/ruby_llm/agents/execution/analytics.rb +170 -20
- data/app/models/ruby_llm/agents/execution/scopes.rb +0 -31
- data/app/models/ruby_llm/agents/execution/workflow.rb +0 -129
- data/app/models/ruby_llm/agents/execution.rb +50 -14
- data/app/models/ruby_llm/agents/tenant/budgetable.rb +277 -0
- data/app/models/ruby_llm/agents/tenant/configurable.rb +135 -0
- data/app/models/ruby_llm/agents/tenant/trackable.rb +310 -0
- data/app/models/ruby_llm/agents/tenant.rb +146 -0
- data/app/models/ruby_llm/agents/tenant_budget.rb +12 -253
- data/app/services/ruby_llm/agents/agent_registry.rb +18 -12
- data/app/views/layouts/ruby_llm/agents/application.html.erb +72 -76
- data/app/views/ruby_llm/agents/agents/_agent.html.erb +0 -12
- data/app/views/ruby_llm/agents/agents/_sortable_header.html.erb +56 -0
- data/app/views/ruby_llm/agents/agents/_workflow.html.erb +5 -15
- data/app/views/ruby_llm/agents/agents/index.html.erb +271 -100
- data/app/views/ruby_llm/agents/agents/show.html.erb +1 -0
- data/app/views/ruby_llm/agents/alert_mailer/alert_notification.html.erb +107 -0
- data/app/views/ruby_llm/agents/alert_mailer/alert_notification.text.erb +18 -0
- data/app/views/ruby_llm/agents/api_configurations/show.html.erb +4 -1
- data/app/views/ruby_llm/agents/dashboard/_agent_comparison.html.erb +66 -359
- data/app/views/ruby_llm/agents/dashboard/_model_comparison.html.erb +56 -0
- data/app/views/ruby_llm/agents/dashboard/_model_cost_breakdown.html.erb +115 -0
- data/app/views/ruby_llm/agents/dashboard/_now_strip.html.erb +35 -60
- data/app/views/ruby_llm/agents/dashboard/_top_errors.html.erb +17 -6
- data/app/views/ruby_llm/agents/dashboard/index.html.erb +373 -72
- data/app/views/ruby_llm/agents/executions/_execution.html.erb +0 -1
- data/app/views/ruby_llm/agents/executions/_filters.html.erb +51 -39
- data/app/views/ruby_llm/agents/executions/_list.html.erb +53 -195
- data/app/views/ruby_llm/agents/executions/_workflow_summary.html.erb +5 -20
- data/app/views/ruby_llm/agents/executions/index.html.erb +7 -83
- data/app/views/ruby_llm/agents/executions/show.html.erb +10 -20
- data/app/views/ruby_llm/agents/shared/_agent_type_badge.html.erb +2 -1
- data/app/views/ruby_llm/agents/shared/_doc_link.html.erb +12 -0
- data/app/views/ruby_llm/agents/shared/_executions_table.html.erb +3 -15
- data/app/views/ruby_llm/agents/shared/_filter_dropdown.html.erb +1 -1
- data/app/views/ruby_llm/agents/shared/_select_dropdown.html.erb +1 -1
- data/app/views/ruby_llm/agents/shared/_sortable_header.html.erb +53 -0
- data/app/views/ruby_llm/agents/shared/_status_badge.html.erb +7 -0
- data/app/views/ruby_llm/agents/shared/_status_dot.html.erb +1 -1
- data/app/views/ruby_llm/agents/shared/_workflow_type_badge.html.erb +9 -35
- data/app/views/ruby_llm/agents/system_config/show.html.erb +4 -1
- data/app/views/ruby_llm/agents/tenants/index.html.erb +4 -1
- data/app/views/ruby_llm/agents/workflows/_step_performance.html.erb +7 -15
- data/app/views/ruby_llm/agents/workflows/_structure_dsl.html.erb +539 -0
- data/app/views/ruby_llm/agents/workflows/_workflow_diagram.html.erb +920 -0
- data/app/views/ruby_llm/agents/workflows/index.html.erb +179 -0
- data/app/views/ruby_llm/agents/workflows/show.html.erb +164 -139
- data/config/routes.rb +1 -1
- data/lib/generators/ruby_llm_agents/agent_generator.rb +6 -36
- data/lib/generators/ruby_llm_agents/background_remover_generator.rb +7 -37
- data/lib/generators/ruby_llm_agents/embedder_generator.rb +5 -38
- data/lib/generators/ruby_llm_agents/image_analyzer_generator.rb +7 -37
- data/lib/generators/ruby_llm_agents/image_editor_generator.rb +7 -37
- data/lib/generators/ruby_llm_agents/image_generator_generator.rb +8 -41
- data/lib/generators/ruby_llm_agents/image_pipeline_generator.rb +18 -46
- data/lib/generators/ruby_llm_agents/image_transformer_generator.rb +7 -37
- data/lib/generators/ruby_llm_agents/image_upscaler_generator.rb +7 -37
- data/lib/generators/ruby_llm_agents/image_variator_generator.rb +7 -37
- data/lib/generators/ruby_llm_agents/install_generator.rb +33 -56
- data/lib/generators/ruby_llm_agents/migrate_structure_generator.rb +480 -0
- data/lib/generators/ruby_llm_agents/multi_tenancy_generator.rb +42 -22
- data/lib/generators/ruby_llm_agents/restructure_generator.rb +2 -2
- data/lib/generators/ruby_llm_agents/speaker_generator.rb +8 -39
- data/lib/generators/ruby_llm_agents/templates/add_tenant_to_executions_migration.rb.tt +13 -2
- data/lib/generators/ruby_llm_agents/templates/agent.rb.tt +5 -8
- data/lib/generators/ruby_llm_agents/templates/application_agent.rb.tt +40 -42
- data/lib/generators/ruby_llm_agents/templates/application_background_remover.rb.tt +20 -22
- data/lib/generators/ruby_llm_agents/templates/application_embedder.rb.tt +24 -26
- data/lib/generators/ruby_llm_agents/templates/application_image_analyzer.rb.tt +20 -22
- data/lib/generators/ruby_llm_agents/templates/application_image_editor.rb.tt +19 -17
- data/lib/generators/ruby_llm_agents/templates/application_image_generator.rb.tt +31 -33
- data/lib/generators/ruby_llm_agents/templates/application_image_pipeline.rb.tt +125 -127
- data/lib/generators/ruby_llm_agents/templates/application_image_transformer.rb.tt +20 -18
- data/lib/generators/ruby_llm_agents/templates/application_image_upscaler.rb.tt +19 -17
- data/lib/generators/ruby_llm_agents/templates/application_image_variator.rb.tt +19 -17
- data/lib/generators/ruby_llm_agents/templates/application_speaker.rb.tt +38 -40
- data/lib/generators/ruby_llm_agents/templates/application_transcriber.rb.tt +42 -44
- data/lib/generators/ruby_llm_agents/templates/application_workflow.rb.tt +48 -0
- data/lib/generators/ruby_llm_agents/templates/background_remover.rb.tt +19 -21
- data/lib/generators/ruby_llm_agents/templates/create_tenant_budgets_migration.rb.tt +11 -0
- data/lib/generators/ruby_llm_agents/templates/create_tenants_migration.rb.tt +72 -0
- data/lib/generators/ruby_llm_agents/templates/embedder.rb.tt +19 -21
- data/lib/generators/ruby_llm_agents/templates/image_analyzer.rb.tt +20 -22
- data/lib/generators/ruby_llm_agents/templates/image_editor.rb.tt +15 -17
- data/lib/generators/ruby_llm_agents/templates/image_generator.rb.tt +25 -27
- data/lib/generators/ruby_llm_agents/templates/image_pipeline.rb.tt +19 -21
- data/lib/generators/ruby_llm_agents/templates/image_transformer.rb.tt +20 -22
- data/lib/generators/ruby_llm_agents/templates/image_upscaler.rb.tt +17 -19
- data/lib/generators/ruby_llm_agents/templates/image_variator.rb.tt +15 -17
- data/lib/generators/ruby_llm_agents/templates/rename_tenant_budgets_to_tenants_migration.rb.tt +34 -0
- data/lib/generators/ruby_llm_agents/templates/skills/AGENTS.md.tt +87 -24
- data/lib/generators/ruby_llm_agents/templates/skills/BACKGROUND_REMOVERS.md.tt +21 -27
- data/lib/generators/ruby_llm_agents/templates/skills/EMBEDDERS.md.tt +46 -54
- data/lib/generators/ruby_llm_agents/templates/skills/IMAGE_ANALYZERS.md.tt +31 -39
- data/lib/generators/ruby_llm_agents/templates/skills/IMAGE_EDITORS.md.tt +22 -28
- data/lib/generators/ruby_llm_agents/templates/skills/IMAGE_GENERATORS.md.tt +53 -63
- data/lib/generators/ruby_llm_agents/templates/skills/IMAGE_PIPELINES.md.tt +46 -56
- data/lib/generators/ruby_llm_agents/templates/skills/IMAGE_TRANSFORMERS.md.tt +23 -31
- data/lib/generators/ruby_llm_agents/templates/skills/IMAGE_UPSCALERS.md.tt +22 -30
- data/lib/generators/ruby_llm_agents/templates/skills/IMAGE_VARIATORS.md.tt +23 -31
- data/lib/generators/ruby_llm_agents/templates/skills/SPEAKERS.md.tt +38 -46
- data/lib/generators/ruby_llm_agents/templates/skills/TOOLS.md.tt +7 -7
- data/lib/generators/ruby_llm_agents/templates/skills/TRANSCRIBERS.md.tt +59 -71
- data/lib/generators/ruby_llm_agents/templates/skills/WORKFLOWS.md.tt +274 -23
- data/lib/generators/ruby_llm_agents/templates/speaker.rb.tt +29 -31
- data/lib/generators/ruby_llm_agents/templates/transcriber.rb.tt +28 -30
- data/lib/generators/ruby_llm_agents/transcriber_generator.rb +10 -43
- data/lib/generators/ruby_llm_agents/upgrade_generator.rb +26 -0
- data/lib/ruby_llm/agents/core/configuration.rb +55 -43
- data/lib/ruby_llm/agents/core/llm_tenant.rb +60 -60
- data/lib/ruby_llm/agents/core/version.rb +1 -1
- data/lib/ruby_llm/agents/infrastructure/alert_manager.rb +26 -0
- data/lib/ruby_llm/agents/infrastructure/budget/config_resolver.rb +4 -2
- data/lib/ruby_llm/agents/pipeline.rb +69 -0
- data/lib/ruby_llm/agents/workflow/approval.rb +205 -0
- data/lib/ruby_llm/agents/workflow/approval_store.rb +179 -0
- data/lib/ruby_llm/agents/workflow/dsl/executor.rb +467 -0
- data/lib/ruby_llm/agents/workflow/dsl/input_schema.rb +244 -0
- data/lib/ruby_llm/agents/workflow/dsl/iteration_executor.rb +289 -0
- data/lib/ruby_llm/agents/workflow/dsl/parallel_group.rb +107 -0
- data/lib/ruby_llm/agents/workflow/dsl/route_builder.rb +150 -0
- data/lib/ruby_llm/agents/workflow/dsl/schedule_helpers.rb +187 -0
- data/lib/ruby_llm/agents/workflow/dsl/step_config.rb +352 -0
- data/lib/ruby_llm/agents/workflow/dsl/step_executor.rb +415 -0
- data/lib/ruby_llm/agents/workflow/dsl/wait_config.rb +257 -0
- data/lib/ruby_llm/agents/workflow/dsl/wait_executor.rb +317 -0
- data/lib/ruby_llm/agents/workflow/dsl.rb +576 -0
- data/lib/ruby_llm/agents/workflow/instrumentation.rb +2 -7
- data/lib/ruby_llm/agents/workflow/notifiers/base.rb +117 -0
- data/lib/ruby_llm/agents/workflow/notifiers/email.rb +117 -0
- data/lib/ruby_llm/agents/workflow/notifiers/slack.rb +180 -0
- data/lib/ruby_llm/agents/workflow/notifiers/webhook.rb +121 -0
- data/lib/ruby_llm/agents/workflow/notifiers.rb +70 -0
- data/lib/ruby_llm/agents/workflow/orchestrator.rb +190 -23
- data/lib/ruby_llm/agents/workflow/result.rb +202 -0
- data/lib/ruby_llm/agents/workflow/throttle_manager.rb +206 -0
- data/lib/ruby_llm/agents/workflow/wait_result.rb +213 -0
- metadata +43 -6
- data/app/views/ruby_llm/agents/dashboard/_execution_item.html.erb +0 -66
- data/lib/ruby_llm/agents/workflow/parallel.rb +0 -299
- data/lib/ruby_llm/agents/workflow/pipeline.rb +0 -306
- data/lib/ruby_llm/agents/workflow/router.rb +0 -429
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# Migration to add
|
|
3
|
+
# Migration to add tenant columns to executions for multi-tenancy support
|
|
4
4
|
#
|
|
5
|
-
# This migration adds
|
|
5
|
+
# This migration adds tenant columns to track which tenant each execution
|
|
6
6
|
# belongs to, enabling:
|
|
7
7
|
# - Filtering executions by tenant
|
|
8
8
|
# - Tenant-scoped analytics and reporting
|
|
9
9
|
# - Per-tenant budget tracking and circuit breakers
|
|
10
|
+
# - Polymorphic association with tenant models (e.g., Organization, Account)
|
|
10
11
|
#
|
|
11
12
|
# Run with: rails db:migrate
|
|
12
13
|
class AddTenantIdToRubyLLMAgentsExecutions < ActiveRecord::Migration<%= migration_version %>
|
|
@@ -14,10 +15,20 @@ class AddTenantIdToRubyLLMAgentsExecutions < ActiveRecord::Migration<%= migratio
|
|
|
14
15
|
# Add tenant_id column (nullable for backward compatibility)
|
|
15
16
|
add_column :ruby_llm_agents_executions, :tenant_id, :string
|
|
16
17
|
|
|
18
|
+
# Polymorphic association to tenant model (for llm_tenant DSL)
|
|
19
|
+
# Uses string type for tenant_record_id to support both integer and UUID primary keys
|
|
20
|
+
add_column :ruby_llm_agents_executions, :tenant_record_type, :string
|
|
21
|
+
add_column :ruby_llm_agents_executions, :tenant_record_id, :string
|
|
22
|
+
|
|
17
23
|
# Add indexes for efficient tenant-scoped queries
|
|
18
24
|
add_index :ruby_llm_agents_executions, :tenant_id
|
|
19
25
|
add_index :ruby_llm_agents_executions, [:tenant_id, :created_at]
|
|
20
26
|
add_index :ruby_llm_agents_executions, [:tenant_id, :agent_type]
|
|
21
27
|
add_index :ruby_llm_agents_executions, [:tenant_id, :status]
|
|
28
|
+
|
|
29
|
+
# Index for polymorphic tenant record lookup
|
|
30
|
+
add_index :ruby_llm_agents_executions,
|
|
31
|
+
[:tenant_record_type, :tenant_record_id],
|
|
32
|
+
name: "index_executions_on_tenant_record"
|
|
22
33
|
end
|
|
23
34
|
end
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
module <%= @root_namespace %>
|
|
4
3
|
<%- if class_name.include?("::") -%>
|
|
5
4
|
<%- class_name.split("::")[0..-2].each_with_index do |mod, i| -%>
|
|
6
|
-
<%= " " *
|
|
5
|
+
<%= " " * i %>module <%= mod %>
|
|
7
6
|
<%- end -%>
|
|
8
|
-
<%= " " * class_name.split("::").length %>class <%= class_name.split("::").last %>Agent < ApplicationAgent
|
|
7
|
+
<%= " " * (class_name.split("::").length - 1) %>class <%= class_name.split("::").last %>Agent < ApplicationAgent
|
|
9
8
|
<%- else -%>
|
|
10
|
-
|
|
9
|
+
class <%= class_name %>Agent < ApplicationAgent
|
|
11
10
|
<%- end -%>
|
|
12
11
|
# ============================================
|
|
13
12
|
# Model Configuration
|
|
@@ -114,10 +113,8 @@ module <%= @root_namespace %>
|
|
|
114
113
|
# { query: params[:query], locale: I18n.locale }
|
|
115
114
|
# end
|
|
116
115
|
<%- if class_name.include?("::") -%>
|
|
117
|
-
<%- (class_name.split("::").length).times do |i| -%>
|
|
118
|
-
<%= " " * (class_name.split("::").length - i) %>end
|
|
116
|
+
<%- (class_name.split("::").length - 1).times do |i| -%>
|
|
117
|
+
<%= " " * (class_name.split("::").length - 1 - i) %>end
|
|
119
118
|
<%- end -%>
|
|
120
|
-
<%- else -%>
|
|
121
|
-
end
|
|
122
119
|
<%- end -%>
|
|
123
120
|
end
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
# that apply to all agents, or override them per-agent as needed.
|
|
7
7
|
#
|
|
8
8
|
# Example:
|
|
9
|
-
# class
|
|
9
|
+
# class MyAgent < ApplicationAgent
|
|
10
10
|
# param :query, required: true
|
|
11
11
|
#
|
|
12
12
|
# def user_prompt
|
|
@@ -15,57 +15,55 @@
|
|
|
15
15
|
# end
|
|
16
16
|
#
|
|
17
17
|
# Usage:
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
18
|
+
# MyAgent.call(query: "hello")
|
|
19
|
+
# MyAgent.call(query: "hello", dry_run: true) # Debug mode
|
|
20
|
+
# MyAgent.call(query: "hello", skip_cache: true) # Bypass cache
|
|
21
21
|
#
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
# These settings are inherited by all agents
|
|
22
|
+
class ApplicationAgent < RubyLLM::Agents::Base
|
|
23
|
+
# ============================================
|
|
24
|
+
# Shared Model Configuration
|
|
25
|
+
# ============================================
|
|
26
|
+
# These settings are inherited by all agents
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
# model "gemini-2.0-flash" # Default model for all agents
|
|
29
|
+
# temperature 0.0 # Default temperature (0.0 = deterministic)
|
|
30
|
+
# timeout 60 # Default timeout in seconds
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
# ============================================
|
|
33
|
+
# Shared Caching
|
|
34
|
+
# ============================================
|
|
36
35
|
|
|
37
|
-
|
|
36
|
+
# cache 1.hour # Enable caching for all agents (override per-agent if needed)
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
# ============================================
|
|
39
|
+
# Shared Reliability Settings
|
|
40
|
+
# ============================================
|
|
41
|
+
# Configure once here, all agents inherit these settings
|
|
43
42
|
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
# Automatic retries for all agents
|
|
44
|
+
# retries max: 2, backoff: :exponential, base: 0.4, max_delay: 3.0
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
# Shared fallback models
|
|
47
|
+
# fallback_models ["gpt-4o-mini", "claude-3-haiku"]
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
# Total timeout across retries/fallbacks
|
|
50
|
+
# total_timeout 30
|
|
52
51
|
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
# Circuit breaker (per agent-model pair)
|
|
53
|
+
# circuit_breaker errors: 5, within: 60, cooldown: 300
|
|
55
54
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
# ============================================
|
|
56
|
+
# Shared Helper Methods
|
|
57
|
+
# ============================================
|
|
58
|
+
# Define methods here that can be used by all agents
|
|
60
59
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
# Example: Common system prompt prefix
|
|
61
|
+
# def system_prompt_prefix
|
|
62
|
+
# "You are an AI assistant for #{Rails.application.class.module_parent_name}."
|
|
63
|
+
# end
|
|
65
64
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
end
|
|
65
|
+
# Example: Common metadata
|
|
66
|
+
# def execution_metadata
|
|
67
|
+
# { app_version: Rails.application.config.version }
|
|
68
|
+
# end
|
|
71
69
|
end
|
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
module
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
# alpha_matting false
|
|
24
|
-
end
|
|
3
|
+
module Images
|
|
4
|
+
# Base class for all background removers in the application
|
|
5
|
+
#
|
|
6
|
+
# Inherits from RubyLLM::Agents::BackgroundRemover and provides a common
|
|
7
|
+
# foundation for custom background removal classes.
|
|
8
|
+
#
|
|
9
|
+
# @example Creating a custom remover
|
|
10
|
+
# class ProductBackgroundRemover < ApplicationBackgroundRemover
|
|
11
|
+
# model "rembg"
|
|
12
|
+
# output_format :png
|
|
13
|
+
# refine_edges true
|
|
14
|
+
# alpha_matting true
|
|
15
|
+
# end
|
|
16
|
+
#
|
|
17
|
+
class ApplicationBackgroundRemover < RubyLLM::Agents::BackgroundRemover
|
|
18
|
+
# Default configuration (can be overridden in subclasses)
|
|
19
|
+
# model "rembg"
|
|
20
|
+
# output_format :png
|
|
21
|
+
# refine_edges false
|
|
22
|
+
# alpha_matting false
|
|
25
23
|
end
|
|
26
24
|
end
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
# that apply to all embedders, or override them per-embedder as needed.
|
|
7
7
|
#
|
|
8
8
|
# Example:
|
|
9
|
-
# class
|
|
9
|
+
# class Embedders::DocumentEmbedder < ApplicationEmbedder
|
|
10
10
|
# dimensions 512 # Reduce dimensions for storage efficiency
|
|
11
11
|
#
|
|
12
12
|
# def preprocess(text)
|
|
@@ -15,36 +15,34 @@
|
|
|
15
15
|
# end
|
|
16
16
|
#
|
|
17
17
|
# Usage:
|
|
18
|
-
#
|
|
19
|
-
#
|
|
18
|
+
# Embedders::DocumentEmbedder.call(text: "hello world")
|
|
19
|
+
# Embedders::DocumentEmbedder.call(texts: ["hello", "world"]) # Batch
|
|
20
20
|
#
|
|
21
|
-
module
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
# These settings are inherited by all embedders
|
|
21
|
+
module Embedders
|
|
22
|
+
class ApplicationEmbedder < RubyLLM::Agents::Embedder
|
|
23
|
+
# ============================================
|
|
24
|
+
# Shared Model Configuration
|
|
25
|
+
# ============================================
|
|
26
|
+
# These settings are inherited by all embedders
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
# model "text-embedding-3-small" # Default embedding model
|
|
29
|
+
# dimensions 1536 # Vector dimensions (nil = model default)
|
|
30
|
+
# batch_size 100 # Texts per API call for batch processing
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
# ============================================
|
|
33
|
+
# Shared Caching
|
|
34
|
+
# ============================================
|
|
35
|
+
# Same text always produces same embedding, so caching is very effective
|
|
37
36
|
|
|
38
|
-
|
|
37
|
+
# cache_for 1.week # Cache embeddings for a week
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
# ============================================
|
|
40
|
+
# Shared Preprocessing
|
|
41
|
+
# ============================================
|
|
42
|
+
# Override in subclass for custom preprocessing
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
end
|
|
44
|
+
# def preprocess(text)
|
|
45
|
+
# text.strip.gsub(/\s+/, ' ').truncate(8000)
|
|
46
|
+
# end
|
|
49
47
|
end
|
|
50
48
|
end
|
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
module
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
# detect_objects false
|
|
24
|
-
end
|
|
3
|
+
module Images
|
|
4
|
+
# Base class for all image analyzers in the application
|
|
5
|
+
#
|
|
6
|
+
# Inherits from RubyLLM::Agents::ImageAnalyzer and provides a common
|
|
7
|
+
# foundation for custom image analysis classes.
|
|
8
|
+
#
|
|
9
|
+
# @example Creating a custom analyzer
|
|
10
|
+
# class ProductAnalyzer < ApplicationImageAnalyzer
|
|
11
|
+
# model "gpt-4o"
|
|
12
|
+
# analysis_type :detailed
|
|
13
|
+
# extract_colors true
|
|
14
|
+
# detect_objects true
|
|
15
|
+
# end
|
|
16
|
+
#
|
|
17
|
+
class ApplicationImageAnalyzer < RubyLLM::Agents::ImageAnalyzer
|
|
18
|
+
# Default configuration (can be overridden in subclasses)
|
|
19
|
+
# model "gpt-4o"
|
|
20
|
+
# analysis_type :detailed
|
|
21
|
+
# extract_colors false
|
|
22
|
+
# detect_objects false
|
|
25
23
|
end
|
|
26
24
|
end
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
3
|
+
module Images
|
|
4
|
+
# Base class for all image editors in the application
|
|
5
|
+
#
|
|
6
|
+
# Inherits from RubyLLM::Agents::ImageEditor and provides a common
|
|
7
|
+
# foundation for custom image editing classes.
|
|
8
|
+
#
|
|
9
|
+
# @example Creating a custom editor
|
|
10
|
+
# class BackgroundEditor < ApplicationImageEditor
|
|
11
|
+
# model "gpt-image-1"
|
|
12
|
+
# size "1024x1024"
|
|
13
|
+
# content_policy :strict
|
|
14
|
+
# end
|
|
15
|
+
#
|
|
16
|
+
class ApplicationImageEditor < RubyLLM::Agents::ImageEditor
|
|
17
|
+
# Default configuration (can be overridden in subclasses)
|
|
18
|
+
# model "gpt-image-1"
|
|
19
|
+
# size "1024x1024"
|
|
20
|
+
# content_policy :standard
|
|
21
|
+
end
|
|
20
22
|
end
|
|
@@ -1,38 +1,36 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
module
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
include RubyLLM::Agents::ImageGenerator::ActiveStorageSupport
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
# Default configuration (can be overridden in subclasses)
|
|
31
|
-
# model "gpt-image-1"
|
|
32
|
-
# size "1024x1024"
|
|
33
|
-
# quality "standard"
|
|
34
|
-
# style "vivid"
|
|
35
|
-
# content_policy :standard
|
|
3
|
+
module Images
|
|
4
|
+
# Base class for all image generators in the application
|
|
5
|
+
#
|
|
6
|
+
# Inherits from RubyLLM::Agents::ImageGenerator and provides a common
|
|
7
|
+
# foundation for custom image generation classes.
|
|
8
|
+
#
|
|
9
|
+
# @example Creating a custom generator
|
|
10
|
+
# class LogoGenerator < ApplicationImageGenerator
|
|
11
|
+
# model "gpt-image-1"
|
|
12
|
+
# size "1024x1024"
|
|
13
|
+
# quality "hd"
|
|
14
|
+
# style "vivid"
|
|
15
|
+
# content_policy :strict
|
|
16
|
+
#
|
|
17
|
+
# template "Professional logo design for {prompt}, minimalist, vector style"
|
|
18
|
+
# end
|
|
19
|
+
#
|
|
20
|
+
# Usage:
|
|
21
|
+
# Images::LogoGenerator.call(prompt: "Company logo")
|
|
22
|
+
#
|
|
23
|
+
class ApplicationImageGenerator < RubyLLM::Agents::ImageGenerator
|
|
24
|
+
# Include ActiveStorage support if available
|
|
25
|
+
if defined?(ActiveStorage)
|
|
26
|
+
include RubyLLM::Agents::ImageGenerator::ActiveStorageSupport
|
|
36
27
|
end
|
|
28
|
+
|
|
29
|
+
# Default configuration (can be overridden in subclasses)
|
|
30
|
+
# model "gpt-image-1"
|
|
31
|
+
# size "1024x1024"
|
|
32
|
+
# quality "standard"
|
|
33
|
+
# style "vivid"
|
|
34
|
+
# content_policy :standard
|
|
37
35
|
end
|
|
38
36
|
end
|