ruby_llm-agents 0.5.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +189 -31
  3. data/app/controllers/ruby_llm/agents/agents_controller.rb +136 -16
  4. data/app/controllers/ruby_llm/agents/dashboard_controller.rb +29 -9
  5. data/app/controllers/ruby_llm/agents/workflows_controller.rb +355 -0
  6. data/app/helpers/ruby_llm/agents/application_helper.rb +25 -0
  7. data/app/models/ruby_llm/agents/execution.rb +3 -0
  8. data/app/models/ruby_llm/agents/tenant_budget.rb +58 -15
  9. data/app/services/ruby_llm/agents/agent_registry.rb +51 -12
  10. data/app/views/layouts/ruby_llm/agents/application.html.erb +2 -29
  11. data/app/views/ruby_llm/agents/agents/_agent.html.erb +13 -1
  12. data/app/views/ruby_llm/agents/agents/_config_agent.html.erb +235 -0
  13. data/app/views/ruby_llm/agents/agents/_config_embedder.html.erb +70 -0
  14. data/app/views/ruby_llm/agents/agents/_config_image_generator.html.erb +152 -0
  15. data/app/views/ruby_llm/agents/agents/_config_moderator.html.erb +63 -0
  16. data/app/views/ruby_llm/agents/agents/_config_speaker.html.erb +108 -0
  17. data/app/views/ruby_llm/agents/agents/_config_transcriber.html.erb +91 -0
  18. data/app/views/ruby_llm/agents/agents/_workflow.html.erb +1 -1
  19. data/app/views/ruby_llm/agents/agents/index.html.erb +74 -9
  20. data/app/views/ruby_llm/agents/agents/show.html.erb +18 -378
  21. data/app/views/ruby_llm/agents/dashboard/_agent_comparison.html.erb +269 -15
  22. data/app/views/ruby_llm/agents/executions/show.html.erb +16 -0
  23. data/app/views/ruby_llm/agents/shared/_agent_type_badge.html.erb +93 -0
  24. data/app/views/ruby_llm/agents/workflows/_step_performance.html.erb +236 -0
  25. data/app/views/ruby_llm/agents/workflows/_structure_parallel.html.erb +76 -0
  26. data/app/views/ruby_llm/agents/workflows/_structure_pipeline.html.erb +74 -0
  27. data/app/views/ruby_llm/agents/workflows/_structure_router.html.erb +108 -0
  28. data/app/views/ruby_llm/agents/workflows/show.html.erb +442 -0
  29. data/config/routes.rb +1 -0
  30. data/lib/generators/ruby_llm_agents/agent_generator.rb +56 -7
  31. data/lib/generators/ruby_llm_agents/background_remover_generator.rb +110 -0
  32. data/lib/generators/ruby_llm_agents/embedder_generator.rb +107 -0
  33. data/lib/generators/ruby_llm_agents/image_analyzer_generator.rb +115 -0
  34. data/lib/generators/ruby_llm_agents/image_editor_generator.rb +108 -0
  35. data/lib/generators/ruby_llm_agents/image_generator_generator.rb +116 -0
  36. data/lib/generators/ruby_llm_agents/image_pipeline_generator.rb +178 -0
  37. data/lib/generators/ruby_llm_agents/image_transformer_generator.rb +109 -0
  38. data/lib/generators/ruby_llm_agents/image_upscaler_generator.rb +103 -0
  39. data/lib/generators/ruby_llm_agents/image_variator_generator.rb +102 -0
  40. data/lib/generators/ruby_llm_agents/install_generator.rb +76 -4
  41. data/lib/generators/ruby_llm_agents/restructure_generator.rb +292 -0
  42. data/lib/generators/ruby_llm_agents/speaker_generator.rb +121 -0
  43. data/lib/generators/ruby_llm_agents/templates/add_execution_type_migration.rb.tt +8 -0
  44. data/lib/generators/ruby_llm_agents/templates/agent.rb.tt +99 -84
  45. data/lib/generators/ruby_llm_agents/templates/application_agent.rb.tt +42 -40
  46. data/lib/generators/ruby_llm_agents/templates/application_background_remover.rb.tt +26 -0
  47. data/lib/generators/ruby_llm_agents/templates/application_embedder.rb.tt +50 -0
  48. data/lib/generators/ruby_llm_agents/templates/application_image_analyzer.rb.tt +26 -0
  49. data/lib/generators/ruby_llm_agents/templates/application_image_editor.rb.tt +20 -0
  50. data/lib/generators/ruby_llm_agents/templates/application_image_generator.rb.tt +38 -0
  51. data/lib/generators/ruby_llm_agents/templates/application_image_pipeline.rb.tt +139 -0
  52. data/lib/generators/ruby_llm_agents/templates/application_image_transformer.rb.tt +21 -0
  53. data/lib/generators/ruby_llm_agents/templates/application_image_upscaler.rb.tt +20 -0
  54. data/lib/generators/ruby_llm_agents/templates/application_image_variator.rb.tt +20 -0
  55. data/lib/generators/ruby_llm_agents/templates/application_speaker.rb.tt +49 -0
  56. data/lib/generators/ruby_llm_agents/templates/application_transcriber.rb.tt +53 -0
  57. data/lib/generators/ruby_llm_agents/templates/background_remover.rb.tt +44 -0
  58. data/lib/generators/ruby_llm_agents/templates/embedder.rb.tt +41 -0
  59. data/lib/generators/ruby_llm_agents/templates/image_analyzer.rb.tt +45 -0
  60. data/lib/generators/ruby_llm_agents/templates/image_editor.rb.tt +35 -0
  61. data/lib/generators/ruby_llm_agents/templates/image_generator.rb.tt +47 -0
  62. data/lib/generators/ruby_llm_agents/templates/image_pipeline.rb.tt +50 -0
  63. data/lib/generators/ruby_llm_agents/templates/image_transformer.rb.tt +44 -0
  64. data/lib/generators/ruby_llm_agents/templates/image_upscaler.rb.tt +38 -0
  65. data/lib/generators/ruby_llm_agents/templates/image_variator.rb.tt +33 -0
  66. data/lib/generators/ruby_llm_agents/templates/skills/AGENTS.md.tt +228 -0
  67. data/lib/generators/ruby_llm_agents/templates/skills/BACKGROUND_REMOVERS.md.tt +131 -0
  68. data/lib/generators/ruby_llm_agents/templates/skills/EMBEDDERS.md.tt +255 -0
  69. data/lib/generators/ruby_llm_agents/templates/skills/IMAGE_ANALYZERS.md.tt +120 -0
  70. data/lib/generators/ruby_llm_agents/templates/skills/IMAGE_EDITORS.md.tt +102 -0
  71. data/lib/generators/ruby_llm_agents/templates/skills/IMAGE_GENERATORS.md.tt +282 -0
  72. data/lib/generators/ruby_llm_agents/templates/skills/IMAGE_PIPELINES.md.tt +228 -0
  73. data/lib/generators/ruby_llm_agents/templates/skills/IMAGE_TRANSFORMERS.md.tt +120 -0
  74. data/lib/generators/ruby_llm_agents/templates/skills/IMAGE_UPSCALERS.md.tt +110 -0
  75. data/lib/generators/ruby_llm_agents/templates/skills/IMAGE_VARIATORS.md.tt +120 -0
  76. data/lib/generators/ruby_llm_agents/templates/skills/SPEAKERS.md.tt +212 -0
  77. data/lib/generators/ruby_llm_agents/templates/skills/TOOLS.md.tt +227 -0
  78. data/lib/generators/ruby_llm_agents/templates/skills/TRANSCRIBERS.md.tt +251 -0
  79. data/lib/generators/ruby_llm_agents/templates/skills/WORKFLOWS.md.tt +300 -0
  80. data/lib/generators/ruby_llm_agents/templates/speaker.rb.tt +56 -0
  81. data/lib/generators/ruby_llm_agents/templates/transcriber.rb.tt +51 -0
  82. data/lib/generators/ruby_llm_agents/transcriber_generator.rb +107 -0
  83. data/lib/generators/ruby_llm_agents/upgrade_generator.rb +152 -1
  84. data/lib/ruby_llm/agents/audio/speaker.rb +553 -0
  85. data/lib/ruby_llm/agents/audio/transcriber.rb +669 -0
  86. data/lib/ruby_llm/agents/base_agent.rb +675 -0
  87. data/lib/ruby_llm/agents/core/base/moderation_dsl.rb +181 -0
  88. data/lib/ruby_llm/agents/core/base/moderation_execution.rb +274 -0
  89. data/lib/ruby_llm/agents/core/base.rb +135 -0
  90. data/lib/ruby_llm/agents/core/configuration.rb +981 -0
  91. data/lib/ruby_llm/agents/core/errors.rb +150 -0
  92. data/lib/ruby_llm/agents/{instrumentation.rb → core/instrumentation.rb} +22 -1
  93. data/lib/ruby_llm/agents/core/llm_tenant.rb +358 -0
  94. data/lib/ruby_llm/agents/{version.rb → core/version.rb} +1 -1
  95. data/lib/ruby_llm/agents/dsl/base.rb +110 -0
  96. data/lib/ruby_llm/agents/dsl/caching.rb +142 -0
  97. data/lib/ruby_llm/agents/dsl/reliability.rb +307 -0
  98. data/lib/ruby_llm/agents/dsl.rb +41 -0
  99. data/lib/ruby_llm/agents/image/analyzer/dsl.rb +130 -0
  100. data/lib/ruby_llm/agents/image/analyzer/execution.rb +402 -0
  101. data/lib/ruby_llm/agents/image/analyzer.rb +90 -0
  102. data/lib/ruby_llm/agents/image/background_remover/dsl.rb +154 -0
  103. data/lib/ruby_llm/agents/image/background_remover/execution.rb +240 -0
  104. data/lib/ruby_llm/agents/image/background_remover.rb +89 -0
  105. data/lib/ruby_llm/agents/image/concerns/image_operation_dsl.rb +91 -0
  106. data/lib/ruby_llm/agents/image/concerns/image_operation_execution.rb +165 -0
  107. data/lib/ruby_llm/agents/image/editor/dsl.rb +56 -0
  108. data/lib/ruby_llm/agents/image/editor/execution.rb +207 -0
  109. data/lib/ruby_llm/agents/image/editor.rb +92 -0
  110. data/lib/ruby_llm/agents/image/generator/active_storage_support.rb +127 -0
  111. data/lib/ruby_llm/agents/image/generator/content_policy.rb +95 -0
  112. data/lib/ruby_llm/agents/image/generator/pricing.rb +353 -0
  113. data/lib/ruby_llm/agents/image/generator/templates.rb +124 -0
  114. data/lib/ruby_llm/agents/image/generator.rb +455 -0
  115. data/lib/ruby_llm/agents/image/pipeline/dsl.rb +213 -0
  116. data/lib/ruby_llm/agents/image/pipeline/execution.rb +382 -0
  117. data/lib/ruby_llm/agents/image/pipeline.rb +97 -0
  118. data/lib/ruby_llm/agents/image/transformer/dsl.rb +148 -0
  119. data/lib/ruby_llm/agents/image/transformer/execution.rb +223 -0
  120. data/lib/ruby_llm/agents/image/transformer.rb +95 -0
  121. data/lib/ruby_llm/agents/image/upscaler/dsl.rb +83 -0
  122. data/lib/ruby_llm/agents/image/upscaler/execution.rb +219 -0
  123. data/lib/ruby_llm/agents/image/upscaler.rb +81 -0
  124. data/lib/ruby_llm/agents/image/variator/dsl.rb +62 -0
  125. data/lib/ruby_llm/agents/image/variator/execution.rb +189 -0
  126. data/lib/ruby_llm/agents/image/variator.rb +80 -0
  127. data/lib/ruby_llm/agents/{alert_manager.rb → infrastructure/alert_manager.rb} +17 -22
  128. data/lib/ruby_llm/agents/infrastructure/budget/budget_query.rb +145 -0
  129. data/lib/ruby_llm/agents/infrastructure/budget/config_resolver.rb +149 -0
  130. data/lib/ruby_llm/agents/infrastructure/budget/forecaster.rb +68 -0
  131. data/lib/ruby_llm/agents/infrastructure/budget/spend_recorder.rb +279 -0
  132. data/lib/ruby_llm/agents/infrastructure/budget_tracker.rb +275 -0
  133. data/lib/ruby_llm/agents/{execution_logger_job.rb → infrastructure/execution_logger_job.rb} +17 -1
  134. data/lib/ruby_llm/agents/{reliability → infrastructure/reliability}/executor.rb +2 -1
  135. data/lib/ruby_llm/agents/{reliability → infrastructure/reliability}/retry_strategy.rb +9 -3
  136. data/lib/ruby_llm/agents/{reliability.rb → infrastructure/reliability.rb} +11 -21
  137. data/lib/ruby_llm/agents/pipeline/builder.rb +215 -0
  138. data/lib/ruby_llm/agents/pipeline/context.rb +255 -0
  139. data/lib/ruby_llm/agents/pipeline/executor.rb +86 -0
  140. data/lib/ruby_llm/agents/pipeline/middleware/base.rb +124 -0
  141. data/lib/ruby_llm/agents/pipeline/middleware/budget.rb +95 -0
  142. data/lib/ruby_llm/agents/pipeline/middleware/cache.rb +171 -0
  143. data/lib/ruby_llm/agents/pipeline/middleware/instrumentation.rb +415 -0
  144. data/lib/ruby_llm/agents/pipeline/middleware/reliability.rb +276 -0
  145. data/lib/ruby_llm/agents/pipeline/middleware/tenant.rb +196 -0
  146. data/lib/ruby_llm/agents/pipeline.rb +68 -0
  147. data/lib/ruby_llm/agents/{engine.rb → rails/engine.rb} +79 -11
  148. data/lib/ruby_llm/agents/results/background_removal_result.rb +286 -0
  149. data/lib/ruby_llm/agents/{result.rb → results/base.rb} +73 -1
  150. data/lib/ruby_llm/agents/results/embedding_result.rb +243 -0
  151. data/lib/ruby_llm/agents/results/image_analysis_result.rb +314 -0
  152. data/lib/ruby_llm/agents/results/image_edit_result.rb +250 -0
  153. data/lib/ruby_llm/agents/results/image_generation_result.rb +346 -0
  154. data/lib/ruby_llm/agents/results/image_pipeline_result.rb +399 -0
  155. data/lib/ruby_llm/agents/results/image_transform_result.rb +251 -0
  156. data/lib/ruby_llm/agents/results/image_upscale_result.rb +255 -0
  157. data/lib/ruby_llm/agents/results/image_variation_result.rb +237 -0
  158. data/lib/ruby_llm/agents/results/moderation_result.rb +158 -0
  159. data/lib/ruby_llm/agents/results/speech_result.rb +338 -0
  160. data/lib/ruby_llm/agents/results/transcription_result.rb +408 -0
  161. data/lib/ruby_llm/agents/text/embedder.rb +444 -0
  162. data/lib/ruby_llm/agents/text/moderator.rb +237 -0
  163. data/lib/ruby_llm/agents/workflow/async.rb +220 -0
  164. data/lib/ruby_llm/agents/workflow/async_executor.rb +156 -0
  165. data/lib/ruby_llm/agents/{workflow.rb → workflow/orchestrator.rb} +6 -5
  166. data/lib/ruby_llm/agents/workflow/parallel.rb +34 -17
  167. data/lib/ruby_llm/agents/workflow/thread_pool.rb +185 -0
  168. data/lib/ruby_llm/agents.rb +86 -20
  169. metadata +172 -34
  170. data/lib/ruby_llm/agents/base/caching.rb +0 -40
  171. data/lib/ruby_llm/agents/base/cost_calculation.rb +0 -105
  172. data/lib/ruby_llm/agents/base/dsl.rb +0 -324
  173. data/lib/ruby_llm/agents/base/execution.rb +0 -366
  174. data/lib/ruby_llm/agents/base/reliability_dsl.rb +0 -82
  175. data/lib/ruby_llm/agents/base/reliability_execution.rb +0 -136
  176. data/lib/ruby_llm/agents/base/response_building.rb +0 -86
  177. data/lib/ruby_llm/agents/base/tool_tracking.rb +0 -57
  178. data/lib/ruby_llm/agents/base.rb +0 -210
  179. data/lib/ruby_llm/agents/budget_tracker.rb +0 -733
  180. data/lib/ruby_llm/agents/configuration.rb +0 -394
  181. /data/lib/ruby_llm/agents/{deprecations.rb → core/deprecations.rb} +0 -0
  182. /data/lib/ruby_llm/agents/{inflections.rb → core/inflections.rb} +0 -0
  183. /data/lib/ruby_llm/agents/{resolved_config.rb → core/resolved_config.rb} +0 -0
  184. /data/lib/ruby_llm/agents/{attempt_tracker.rb → infrastructure/attempt_tracker.rb} +0 -0
  185. /data/lib/ruby_llm/agents/{cache_helper.rb → infrastructure/cache_helper.rb} +0 -0
  186. /data/lib/ruby_llm/agents/{circuit_breaker.rb → infrastructure/circuit_breaker.rb} +0 -0
  187. /data/lib/ruby_llm/agents/{redactor.rb → infrastructure/redactor.rb} +0 -0
  188. /data/lib/ruby_llm/agents/{reliability → infrastructure/reliability}/breaker_manager.rb +0 -0
  189. /data/lib/ruby_llm/agents/{reliability → infrastructure/reliability}/execution_constraints.rb +0 -0
  190. /data/lib/ruby_llm/agents/{reliability → infrastructure/reliability}/fallback_routing.rb +0 -0
@@ -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 MyAgent < ApplicationAgent
9
+ # class <%= @root_namespace %>::MyAgent < ApplicationAgent
10
10
  # param :query, required: true
11
11
  #
12
12
  # def user_prompt
@@ -15,55 +15,57 @@
15
15
  # end
16
16
  #
17
17
  # Usage:
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
18
+ # <%= @root_namespace %>::MyAgent.call(query: "hello")
19
+ # <%= @root_namespace %>::MyAgent.call(query: "hello", dry_run: true) # Debug mode
20
+ # <%= @root_namespace %>::MyAgent.call(query: "hello", skip_cache: true) # Bypass cache
21
21
  #
22
- class ApplicationAgent < RubyLLM::Agents::Base
23
- # ============================================
24
- # Shared Model Configuration
25
- # ============================================
26
- # These settings are inherited by all agents
22
+ module <%= @root_namespace %>
23
+ class ApplicationAgent < RubyLLM::Agents::Base
24
+ # ============================================
25
+ # Shared Model Configuration
26
+ # ============================================
27
+ # These settings are inherited by all agents
27
28
 
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
29
+ # model "gemini-2.0-flash" # Default model for all agents
30
+ # temperature 0.0 # Default temperature (0.0 = deterministic)
31
+ # timeout 60 # Default timeout in seconds
31
32
 
32
- # ============================================
33
- # Shared Caching
34
- # ============================================
33
+ # ============================================
34
+ # Shared Caching
35
+ # ============================================
35
36
 
36
- # cache 1.hour # Enable caching for all agents (override per-agent if needed)
37
+ # cache 1.hour # Enable caching for all agents (override per-agent if needed)
37
38
 
38
- # ============================================
39
- # Shared Reliability Settings
40
- # ============================================
41
- # Configure once here, all agents inherit these settings
39
+ # ============================================
40
+ # Shared Reliability Settings
41
+ # ============================================
42
+ # Configure once here, all agents inherit these settings
42
43
 
43
- # Automatic retries for all agents
44
- # retries max: 2, backoff: :exponential, base: 0.4, max_delay: 3.0
44
+ # Automatic retries for all agents
45
+ # retries max: 2, backoff: :exponential, base: 0.4, max_delay: 3.0
45
46
 
46
- # Shared fallback models
47
- # fallback_models ["gpt-4o-mini", "claude-3-haiku"]
47
+ # Shared fallback models
48
+ # fallback_models ["gpt-4o-mini", "claude-3-haiku"]
48
49
 
49
- # Total timeout across retries/fallbacks
50
- # total_timeout 30
50
+ # Total timeout across retries/fallbacks
51
+ # total_timeout 30
51
52
 
52
- # Circuit breaker (per agent-model pair)
53
- # circuit_breaker errors: 5, within: 60, cooldown: 300
53
+ # Circuit breaker (per agent-model pair)
54
+ # circuit_breaker errors: 5, within: 60, cooldown: 300
54
55
 
55
- # ============================================
56
- # Shared Helper Methods
57
- # ============================================
58
- # Define methods here that can be used by all agents
56
+ # ============================================
57
+ # Shared Helper Methods
58
+ # ============================================
59
+ # Define methods here that can be used by all agents
59
60
 
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
61
+ # Example: Common system prompt prefix
62
+ # def system_prompt_prefix
63
+ # "You are an AI assistant for #{Rails.application.class.module_parent_name}."
64
+ # end
64
65
 
65
- # Example: Common metadata
66
- # def execution_metadata
67
- # { app_version: Rails.application.config.version }
68
- # end
66
+ # Example: Common metadata
67
+ # def execution_metadata
68
+ # { app_version: Rails.application.config.version }
69
+ # end
70
+ end
69
71
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module <%= @root_namespace %>
4
+ module Image
5
+ # Base class for all background removers in the application
6
+ #
7
+ # Inherits from RubyLLM::Agents::BackgroundRemover and provides a common
8
+ # foundation for custom background removal classes.
9
+ #
10
+ # @example Creating a custom remover
11
+ # class ProductBackgroundRemover < ApplicationBackgroundRemover
12
+ # model "rembg"
13
+ # output_format :png
14
+ # refine_edges true
15
+ # alpha_matting true
16
+ # end
17
+ #
18
+ class ApplicationBackgroundRemover < RubyLLM::Agents::BackgroundRemover
19
+ # Default configuration (can be overridden in subclasses)
20
+ # model "rembg"
21
+ # output_format :png
22
+ # refine_edges false
23
+ # alpha_matting false
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ApplicationEmbedder - Base class for all embedders in this application
4
+ #
5
+ # All embedders inherit from this class. Configure shared settings here
6
+ # that apply to all embedders, or override them per-embedder as needed.
7
+ #
8
+ # Example:
9
+ # class <%= @text_namespace %>::DocumentEmbedder < ApplicationEmbedder
10
+ # dimensions 512 # Reduce dimensions for storage efficiency
11
+ #
12
+ # def preprocess(text)
13
+ # text.strip.downcase
14
+ # end
15
+ # end
16
+ #
17
+ # Usage:
18
+ # <%= @text_namespace %>::DocumentEmbedder.call(text: "hello world")
19
+ # <%= @text_namespace %>::DocumentEmbedder.call(texts: ["hello", "world"]) # Batch
20
+ #
21
+ module <%= @root_namespace %>
22
+ module Text
23
+ class ApplicationEmbedder < RubyLLM::Agents::Embedder
24
+ # ============================================
25
+ # Shared Model Configuration
26
+ # ============================================
27
+ # These settings are inherited by all embedders
28
+
29
+ # model "text-embedding-3-small" # Default embedding model
30
+ # dimensions 1536 # Vector dimensions (nil = model default)
31
+ # batch_size 100 # Texts per API call for batch processing
32
+
33
+ # ============================================
34
+ # Shared Caching
35
+ # ============================================
36
+ # Same text always produces same embedding, so caching is very effective
37
+
38
+ # cache_for 1.week # Cache embeddings for a week
39
+
40
+ # ============================================
41
+ # Shared Preprocessing
42
+ # ============================================
43
+ # Override in subclass for custom preprocessing
44
+
45
+ # def preprocess(text)
46
+ # text.strip.gsub(/\s+/, ' ').truncate(8000)
47
+ # end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module <%= @root_namespace %>
4
+ module Image
5
+ # Base class for all image analyzers in the application
6
+ #
7
+ # Inherits from RubyLLM::Agents::ImageAnalyzer and provides a common
8
+ # foundation for custom image analysis classes.
9
+ #
10
+ # @example Creating a custom analyzer
11
+ # class ProductAnalyzer < ApplicationImageAnalyzer
12
+ # model "gpt-4o"
13
+ # analysis_type :detailed
14
+ # extract_colors true
15
+ # detect_objects true
16
+ # end
17
+ #
18
+ class ApplicationImageAnalyzer < RubyLLM::Agents::ImageAnalyzer
19
+ # Default configuration (can be overridden in subclasses)
20
+ # model "gpt-4o"
21
+ # analysis_type :detailed
22
+ # extract_colors false
23
+ # detect_objects false
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Base class for all image editors in the application
4
+ #
5
+ # Inherits from RubyLLM::Agents::ImageEditor and provides a common
6
+ # foundation for custom image editing classes.
7
+ #
8
+ # @example Creating a custom editor
9
+ # class BackgroundEditor < ApplicationImageEditor
10
+ # model "gpt-image-1"
11
+ # size "1024x1024"
12
+ # content_policy :strict
13
+ # end
14
+ #
15
+ class ApplicationImageEditor < RubyLLM::Agents::ImageEditor
16
+ # Default configuration (can be overridden in subclasses)
17
+ # model "gpt-image-1"
18
+ # size "1024x1024"
19
+ # content_policy :standard
20
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module <%= @root_namespace %>
4
+ module Image
5
+ # Base class for all image generators in the application
6
+ #
7
+ # Inherits from RubyLLM::Agents::ImageGenerator and provides a common
8
+ # foundation for custom image generation classes.
9
+ #
10
+ # @example Creating a custom generator
11
+ # class LogoGenerator < ApplicationImageGenerator
12
+ # model "gpt-image-1"
13
+ # size "1024x1024"
14
+ # quality "hd"
15
+ # style "vivid"
16
+ # content_policy :strict
17
+ #
18
+ # template "Professional logo design for {prompt}, minimalist, vector style"
19
+ # end
20
+ #
21
+ # Usage:
22
+ # <%= @root_namespace %>::Image::LogoGenerator.call(prompt: "Company logo")
23
+ #
24
+ class ApplicationImageGenerator < RubyLLM::Agents::ImageGenerator
25
+ # Include ActiveStorage support if available
26
+ if defined?(ActiveStorage)
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
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,139 @@
1
+ # frozen_string_literal: true
2
+
3
+ module <%= @root_namespace %>
4
+ module Image
5
+ # ApplicationImagePipeline - Base class for all image pipelines in this application
6
+ #
7
+ # All image pipelines inherit from this class. Configure shared settings here
8
+ # that apply to all pipelines, or override them per-pipeline as needed.
9
+ #
10
+ # ============================================================================
11
+ # IMAGE PIPELINE DSL REFERENCE
12
+ # ============================================================================
13
+ #
14
+ # STEP DEFINITION:
15
+ # ----------------
16
+ # step :name, generator: MyGenerator # Text-to-image generation
17
+ # step :name, upscaler: MyUpscaler # Resolution enhancement
18
+ # step :name, transformer: MyTransformer # Style transfer / img2img
19
+ # step :name, editor: MyEditor # Inpainting / editing
20
+ # step :name, variator: MyVariator # Generate variations
21
+ # step :name, analyzer: MyAnalyzer # Image analysis (non-image output)
22
+ # step :name, remover: MyRemover # Background removal
23
+ #
24
+ # CONDITIONAL STEPS:
25
+ # ------------------
26
+ # step :upscale, upscaler: MyUpscaler, if: ->(ctx) { ctx[:high_quality] }
27
+ # step :remove_bg, remover: MyRemover, unless: ->(ctx) { ctx[:keep_background] }
28
+ #
29
+ # STEP OPTIONS:
30
+ # -------------
31
+ # step :upscale, upscaler: PhotoUpscaler, scale: 4
32
+ # step :transform, transformer: StyleTransformer, strength: 0.8
33
+ #
34
+ # CALLBACKS:
35
+ # ----------
36
+ # before_pipeline :validate_inputs
37
+ # after_pipeline :add_watermark
38
+ # after_pipeline { |result| notify_completion(result) }
39
+ #
40
+ # ERROR HANDLING:
41
+ # ---------------
42
+ # stop_on_error true # Stop pipeline on first error (default)
43
+ # stop_on_error false # Continue even if a step fails
44
+ #
45
+ # CACHING:
46
+ # --------
47
+ # cache_for 1.hour # Cache pipeline results
48
+ #
49
+ # METADATA:
50
+ # ---------
51
+ # version "1.0" # Version identifier (affects cache key)
52
+ # description "My pipeline" # Human-readable description
53
+ #
54
+ # ============================================================================
55
+ # USAGE EXAMPLES
56
+ # ============================================================================
57
+ #
58
+ # # Simple pipeline
59
+ # class ProductPipeline < ApplicationImagePipeline
60
+ # step :generate, generator: ProductGenerator
61
+ # step :upscale, upscaler: PhotoUpscaler, scale: 2
62
+ # end
63
+ #
64
+ # result = ProductPipeline.call(prompt: "Laptop on desk")
65
+ # result.final_image # => URL or data of processed image
66
+ # result.total_cost # => Combined cost of all steps
67
+ #
68
+ # # Pipeline with analysis
69
+ # class AnalysisPipeline < ApplicationImagePipeline
70
+ # step :generate, generator: ProductGenerator
71
+ # step :analyze, analyzer: ContentAnalyzer
72
+ # end
73
+ #
74
+ # result = AnalysisPipeline.call(prompt: "Product photo")
75
+ # result.analysis # => ImageAnalysisResult
76
+ #
77
+ # # Conditional pipeline
78
+ # class SmartPipeline < ApplicationImagePipeline
79
+ # step :generate, generator: ProductGenerator
80
+ # step :upscale, upscaler: PhotoUpscaler, if: ->(ctx) { ctx[:hd] }
81
+ # step :remove_background, remover: BackgroundRemover, if: ->(ctx) { ctx[:transparent] }
82
+ # end
83
+ #
84
+ # result = SmartPipeline.call(prompt: "...", hd: true, transparent: false)
85
+ #
86
+ # ============================================================================
87
+ # RESULT ACCESS
88
+ # ============================================================================
89
+ #
90
+ # result.success? # All steps succeeded
91
+ # result.partial? # Some steps succeeded, some failed
92
+ # result.error? # Pipeline failed
93
+ #
94
+ # result.step(:generate) # Access specific step result
95
+ # result.steps # Array of all step results
96
+ # result.step_count # Total number of steps
97
+ #
98
+ # result.final_image # Final processed image (URL or data)
99
+ # result.url # Final image URL
100
+ # result.to_blob # Final image binary data
101
+ # result.save("output.png") # Save final image to file
102
+ #
103
+ # result.total_cost # Combined cost of all steps
104
+ # result.duration_ms # Total pipeline duration
105
+ #
106
+ class ApplicationImagePipeline < RubyLLM::Agents::ImagePipeline
107
+ # ============================================
108
+ # Shared Pipeline Configuration
109
+ # ============================================
110
+ # These settings are inherited by all pipelines
111
+
112
+ # stop_on_error true # Stop on first step failure
113
+
114
+ # ============================================
115
+ # Shared Caching
116
+ # ============================================
117
+
118
+ # cache_for 30.minutes # Enable caching for all pipelines
119
+
120
+ # ============================================
121
+ # Shared Callbacks
122
+ # ============================================
123
+ # Define methods here that can be used by all pipelines
124
+
125
+ # before_pipeline :validate_tenant
126
+ # after_pipeline :log_completion
127
+
128
+ # private
129
+
130
+ # def validate_tenant
131
+ # raise ArgumentError, "Tenant required" unless context[:tenant]
132
+ # end
133
+
134
+ # def log_completion(result)
135
+ # Rails.logger.info("Pipeline completed: #{result.success?}")
136
+ # end
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Base class for all image transformers in the application
4
+ #
5
+ # Inherits from RubyLLM::Agents::ImageTransformer and provides a common
6
+ # foundation for custom image transformation classes.
7
+ #
8
+ # @example Creating a custom transformer
9
+ # class AnimeTransformer < ApplicationImageTransformer
10
+ # model "sdxl"
11
+ # strength 0.8
12
+ # template "anime style, studio ghibli, {prompt}"
13
+ # end
14
+ #
15
+ class ApplicationImageTransformer < RubyLLM::Agents::ImageTransformer
16
+ # Default configuration (can be overridden in subclasses)
17
+ # model "sdxl"
18
+ # size "1024x1024"
19
+ # strength 0.75
20
+ # preserve_composition true
21
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Base class for all image upscalers in the application
4
+ #
5
+ # Inherits from RubyLLM::Agents::ImageUpscaler and provides a common
6
+ # foundation for custom image upscaling classes.
7
+ #
8
+ # @example Creating a custom upscaler
9
+ # class PhotoUpscaler < ApplicationImageUpscaler
10
+ # model "real-esrgan"
11
+ # scale 4
12
+ # face_enhance true
13
+ # end
14
+ #
15
+ class ApplicationImageUpscaler < RubyLLM::Agents::ImageUpscaler
16
+ # Default configuration (can be overridden in subclasses)
17
+ # model "real-esrgan"
18
+ # scale 4
19
+ # face_enhance false
20
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Base class for all image variators in the application
4
+ #
5
+ # Inherits from RubyLLM::Agents::ImageVariator and provides a common
6
+ # foundation for custom image variation classes.
7
+ #
8
+ # @example Creating a custom variator
9
+ # class LogoVariator < ApplicationImageVariator
10
+ # model "gpt-image-1"
11
+ # size "1024x1024"
12
+ # variation_strength 0.3
13
+ # end
14
+ #
15
+ class ApplicationImageVariator < RubyLLM::Agents::ImageVariator
16
+ # Default configuration (can be overridden in subclasses)
17
+ # model "gpt-image-1"
18
+ # size "1024x1024"
19
+ # variation_strength 0.5
20
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module <%= @root_namespace %>
4
+ module Audio
5
+ # ApplicationSpeaker - Base class for all speakers in this application
6
+ #
7
+ # All speakers inherit from this class. Configure shared settings here
8
+ # that apply to all speakers, or override them per-speaker as needed.
9
+ #
10
+ # Example:
11
+ # class NarratorSpeaker < ApplicationSpeaker
12
+ # voice "nova"
13
+ # speed 1.1
14
+ # end
15
+ #
16
+ # Usage:
17
+ # <%= @root_namespace %>::Audio::NarratorSpeaker.call(text: "Hello world")
18
+ #
19
+ class ApplicationSpeaker < RubyLLM::Agents::Speaker
20
+ # ============================================
21
+ # Shared Provider Configuration
22
+ # ============================================
23
+ # These settings are inherited by all speakers
24
+
25
+ # provider :openai # TTS provider (:openai, :elevenlabs)
26
+ # model "tts-1" # TTS model
27
+ # voice "nova" # Default voice
28
+ # speed 1.0 # Speech speed (0.25-4.0 for OpenAI)
29
+ # output_format :mp3 # Output format (:mp3, :wav, :ogg, :flac)
30
+
31
+ # ============================================
32
+ # Shared Caching
33
+ # ============================================
34
+ # Same text with same settings produces same audio, so caching is effective
35
+
36
+ # cache_for 7.days # Cache generated audio for a week
37
+
38
+ # ============================================
39
+ # Shared Pronunciation Lexicon
40
+ # ============================================
41
+ # Define custom pronunciations for technical terms
42
+
43
+ # lexicon do
44
+ # pronounce 'RubyLLM', 'ruby L L M'
45
+ # pronounce 'PostgreSQL', 'post-gres-Q-L'
46
+ # end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module <%= @root_namespace %>
4
+ module Audio
5
+ # ApplicationTranscriber - Base class for all transcribers in this application
6
+ #
7
+ # All transcribers inherit from this class. Configure shared settings here
8
+ # that apply to all transcribers, or override them per-transcriber as needed.
9
+ #
10
+ # Example:
11
+ # class MeetingTranscriber < ApplicationTranscriber
12
+ # language "en"
13
+ #
14
+ # def prompt
15
+ # "Business meeting discussion about quarterly results"
16
+ # end
17
+ # end
18
+ #
19
+ # Usage:
20
+ # <%= @root_namespace %>::Audio::MeetingTranscriber.call(audio: "meeting.mp3")
21
+ #
22
+ class ApplicationTranscriber < RubyLLM::Agents::Transcriber
23
+ # ============================================
24
+ # Shared Model Configuration
25
+ # ============================================
26
+ # These settings are inherited by all transcribers
27
+
28
+ # model "whisper-1" # Default transcription model
29
+ # language "en" # Default language (nil = auto-detect)
30
+ # output_format :text # Output format (:text, :srt, :vtt, :json)
31
+ # include_timestamps :segment # Timestamp granularity (:none, :segment, :word)
32
+
33
+ # ============================================
34
+ # Shared Caching
35
+ # ============================================
36
+ # Same audio always produces same transcription, so caching is effective
37
+
38
+ # cache_for 30.days # Cache transcriptions for 30 days
39
+
40
+ # ============================================
41
+ # Shared Post-processing
42
+ # ============================================
43
+ # Override in subclass for custom text cleanup
44
+
45
+ # def postprocess_text(text)
46
+ # text
47
+ # .gsub(/\bum\b/i, '') # Remove filler words
48
+ # .gsub(/\buh\b/i, '')
49
+ # .squeeze(' ') # Remove extra spaces
50
+ # end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module <%= @root_namespace %>
4
+ module Image
5
+ <%- if class_name.include?("::") -%>
6
+ <%- class_name.split("::")[0..-2].each_with_index do |mod, i| -%>
7
+ <%= " " * (i + 2) %>module <%= mod %>
8
+ <%- end -%>
9
+ <%= " " * (class_name.split("::").length + 1) %>class <%= class_name.split("::").last %>BackgroundRemover < ApplicationBackgroundRemover
10
+ <%- else -%>
11
+ class <%= class_name %>BackgroundRemover < ApplicationBackgroundRemover
12
+ <%- end -%>
13
+ # Model configuration
14
+ model "<%= options[:model] %>"
15
+ output_format :<%= options[:output_format] %>
16
+ <% if options[:refine_edges] -%>
17
+ refine_edges true
18
+ <% end -%>
19
+ <% if options[:alpha_matting] -%>
20
+ alpha_matting true
21
+ <% end -%>
22
+ <% if options[:return_mask] -%>
23
+ return_mask true
24
+ <% end -%>
25
+ <% if options[:cache] -%>
26
+
27
+ # Caching
28
+ cache_for <%= options[:cache] %>
29
+ <% end -%>
30
+
31
+ # Optional: Edge threshold
32
+ # edge_threshold 0.5
33
+
34
+ # Optional: Description
35
+ # description "Removes backgrounds from <%= class_name.downcase %> images"
36
+ <%- if class_name.include?("::") -%>
37
+ <%- (class_name.split("::").length + 1).times do |i| -%>
38
+ <%= " " * (class_name.split("::").length + 1 - i) %>end
39
+ <%- end -%>
40
+ <%- else -%>
41
+ end
42
+ <%- end -%>
43
+ end
44
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module <%= @root_namespace %>
4
+ module Text
5
+ <%- if class_name.include?("::") -%>
6
+ <%- class_name.split("::")[0..-2].each_with_index do |mod, i| -%>
7
+ <%= " " * (i + 2) %>module <%= mod %>
8
+ <%- end -%>
9
+ <%= " " * (class_name.split("::").length + 1) %>class <%= class_name.split("::").last %>Embedder < ApplicationEmbedder
10
+ <%- else -%>
11
+ class <%= class_name %>Embedder < ApplicationEmbedder
12
+ <%- end -%>
13
+ # Model configuration
14
+ model "<%= options[:model] %>"
15
+ <% if options[:dimensions] -%>
16
+ dimensions <%= options[:dimensions] %>
17
+ <% end -%>
18
+ <% if options[:batch_size] != 100 -%>
19
+ batch_size <%= options[:batch_size] %>
20
+ <% end -%>
21
+ <% if options[:cache] -%>
22
+
23
+ # Caching
24
+ cache_for <%= options[:cache] %>
25
+ <% end -%>
26
+
27
+ # Optional: Custom preprocessing
28
+ # Override this method to normalize/clean text before embedding
29
+ #
30
+ # def preprocess(text)
31
+ # text.strip.downcase.gsub(/\s+/, ' ')
32
+ # end
33
+ <%- if class_name.include?("::") -%>
34
+ <%- (class_name.split("::").length + 1).times do |i| -%>
35
+ <%= " " * (class_name.split("::").length + 1 - i) %>end
36
+ <%- end -%>
37
+ <%- else -%>
38
+ end
39
+ <%- end -%>
40
+ end
41
+ end