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,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Images Generators
|
|
2
2
|
|
|
3
3
|
This directory contains image generation services. All generators inherit from `ApplicationImageGenerator`.
|
|
4
4
|
|
|
@@ -13,15 +13,13 @@ rails generate ruby_llm_agents:image_generator Product --quality hd --style vivi
|
|
|
13
13
|
|
|
14
14
|
Or create manually:
|
|
15
15
|
```ruby
|
|
16
|
-
module
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
content_policy :standard
|
|
24
|
-
end
|
|
16
|
+
module Images
|
|
17
|
+
class LogoGenerator < ApplicationImageGenerator
|
|
18
|
+
model "gpt-image-1"
|
|
19
|
+
size "1024x1024"
|
|
20
|
+
quality "hd"
|
|
21
|
+
style "vivid"
|
|
22
|
+
content_policy :standard
|
|
25
23
|
end
|
|
26
24
|
end
|
|
27
25
|
```
|
|
@@ -100,7 +98,7 @@ end
|
|
|
100
98
|
### Basic Generation
|
|
101
99
|
|
|
102
100
|
```ruby
|
|
103
|
-
result =
|
|
101
|
+
result = Images::LogoGenerator.call(prompt: "Tech startup logo")
|
|
104
102
|
|
|
105
103
|
result.url # Temporary URL to generated image
|
|
106
104
|
result.image_data # Binary image data
|
|
@@ -111,14 +109,14 @@ result.total_cost # Cost in USD
|
|
|
111
109
|
### Save to File
|
|
112
110
|
|
|
113
111
|
```ruby
|
|
114
|
-
result =
|
|
112
|
+
result = Images::LogoGenerator.call(prompt: "Company logo")
|
|
115
113
|
result.save("logo.png")
|
|
116
114
|
```
|
|
117
115
|
|
|
118
116
|
### Generate Multiple Images
|
|
119
117
|
|
|
120
118
|
```ruby
|
|
121
|
-
result =
|
|
119
|
+
result = Images::LogoGenerator.call(
|
|
122
120
|
prompt: "Product photography",
|
|
123
121
|
count: 4
|
|
124
122
|
)
|
|
@@ -130,7 +128,7 @@ result.images # Array of image data
|
|
|
130
128
|
### Override Settings at Runtime
|
|
131
129
|
|
|
132
130
|
```ruby
|
|
133
|
-
result =
|
|
131
|
+
result = Images::LogoGenerator.call(
|
|
134
132
|
prompt: "High quality portrait",
|
|
135
133
|
quality: "hd",
|
|
136
134
|
size: "1792x1024",
|
|
@@ -143,7 +141,7 @@ result = <%= @root_namespace %>::Image::LogoGenerator.call(
|
|
|
143
141
|
If ActiveStorage is available:
|
|
144
142
|
|
|
145
143
|
```ruby
|
|
146
|
-
result =
|
|
144
|
+
result = Images::ProductGenerator.call(prompt: "Product shot")
|
|
147
145
|
|
|
148
146
|
# Attach to a model
|
|
149
147
|
product.images.attach(
|
|
@@ -158,19 +156,17 @@ product.images.attach(
|
|
|
158
156
|
### Product Photography
|
|
159
157
|
|
|
160
158
|
```ruby
|
|
161
|
-
module
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
negative_prompt "text, watermark, blurry, low quality"
|
|
173
|
-
end
|
|
159
|
+
module Images
|
|
160
|
+
class ProductGenerator < ApplicationImageGenerator
|
|
161
|
+
model "gpt-image-1"
|
|
162
|
+
size "1024x1024"
|
|
163
|
+
quality "hd"
|
|
164
|
+
style "natural"
|
|
165
|
+
|
|
166
|
+
template "Professional product photography of {prompt}, " \
|
|
167
|
+
"white background, studio lighting, e-commerce style"
|
|
168
|
+
|
|
169
|
+
negative_prompt "text, watermark, blurry, low quality"
|
|
174
170
|
end
|
|
175
171
|
end
|
|
176
172
|
```
|
|
@@ -178,17 +174,15 @@ end
|
|
|
178
174
|
### Marketing Banners
|
|
179
175
|
|
|
180
176
|
```ruby
|
|
181
|
-
module
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
"eye-catching design, professional"
|
|
191
|
-
end
|
|
177
|
+
module Images
|
|
178
|
+
class BannerGenerator < ApplicationImageGenerator
|
|
179
|
+
model "gpt-image-1"
|
|
180
|
+
size "1792x1024" # Landscape
|
|
181
|
+
quality "hd"
|
|
182
|
+
style "vivid"
|
|
183
|
+
|
|
184
|
+
template "Marketing banner for {prompt}, bold colors, " \
|
|
185
|
+
"eye-catching design, professional"
|
|
192
186
|
end
|
|
193
187
|
end
|
|
194
188
|
```
|
|
@@ -196,18 +190,16 @@ end
|
|
|
196
190
|
### Avatar Generation
|
|
197
191
|
|
|
198
192
|
```ruby
|
|
199
|
-
module
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
"professional, approachable, colorful"
|
|
210
|
-
end
|
|
193
|
+
module Images
|
|
194
|
+
class AvatarGenerator < ApplicationImageGenerator
|
|
195
|
+
model "gpt-image-1"
|
|
196
|
+
size "512x512"
|
|
197
|
+
quality "standard"
|
|
198
|
+
style "vivid"
|
|
199
|
+
content_policy :strict
|
|
200
|
+
|
|
201
|
+
template "Friendly cartoon avatar of {prompt}, " \
|
|
202
|
+
"professional, approachable, colorful"
|
|
211
203
|
end
|
|
212
204
|
end
|
|
213
205
|
```
|
|
@@ -215,26 +207,24 @@ end
|
|
|
215
207
|
### Social Media Graphics
|
|
216
208
|
|
|
217
209
|
```ruby
|
|
218
|
-
module
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
"#{prompt}, social media post, engaging, modern design"
|
|
226
|
-
end
|
|
210
|
+
module Images
|
|
211
|
+
class SocialGenerator < ApplicationImageGenerator
|
|
212
|
+
model "gpt-image-1"
|
|
213
|
+
quality "standard"
|
|
214
|
+
|
|
215
|
+
def preprocess_prompt(prompt)
|
|
216
|
+
"#{prompt}, social media post, engaging, modern design"
|
|
227
217
|
end
|
|
228
218
|
end
|
|
229
219
|
end
|
|
230
220
|
|
|
231
221
|
# Usage with different sizes
|
|
232
|
-
|
|
222
|
+
Images::SocialGenerator.call(
|
|
233
223
|
prompt: "Tech announcement",
|
|
234
224
|
size: "1024x1024" # Instagram
|
|
235
225
|
)
|
|
236
226
|
|
|
237
|
-
|
|
227
|
+
Images::SocialGenerator.call(
|
|
238
228
|
prompt: "Tech announcement",
|
|
239
229
|
size: "1792x1024" # Twitter/LinkedIn
|
|
240
230
|
)
|
|
@@ -243,7 +233,7 @@ end
|
|
|
243
233
|
## Testing Generators
|
|
244
234
|
|
|
245
235
|
```ruby
|
|
246
|
-
RSpec.describe
|
|
236
|
+
RSpec.describe Images::LogoGenerator do
|
|
247
237
|
describe ".call" do
|
|
248
238
|
it "generates an image" do
|
|
249
239
|
result = described_class.call(prompt: "Test logo")
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Images Pipelines
|
|
2
2
|
|
|
3
3
|
This directory contains multi-step image processing pipelines. All pipelines inherit from `ApplicationImagePipeline`.
|
|
4
4
|
|
|
@@ -12,13 +12,11 @@ rails generate ruby_llm_agents:image_pipeline Product --steps generate,upscale,r
|
|
|
12
12
|
|
|
13
13
|
Or create manually:
|
|
14
14
|
```ruby
|
|
15
|
-
module
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
step :remove_bg, remover: BackgroundRemover
|
|
21
|
-
end
|
|
15
|
+
module Images
|
|
16
|
+
class ProductPipeline < ApplicationImagePipeline
|
|
17
|
+
step :generate, generator: ProductGenerator
|
|
18
|
+
step :upscale, upscaler: PhotoUpscaler, scale: 2
|
|
19
|
+
step :remove_bg, remover: BackgroundRemover
|
|
22
20
|
end
|
|
23
21
|
end
|
|
24
22
|
```
|
|
@@ -77,7 +75,7 @@ cache_for 1.hour # Cache pipeline results
|
|
|
77
75
|
### Basic Execution
|
|
78
76
|
|
|
79
77
|
```ruby
|
|
80
|
-
result =
|
|
78
|
+
result = Images::ProductPipeline.call(prompt: "Laptop on desk")
|
|
81
79
|
|
|
82
80
|
result.success? # All steps succeeded
|
|
83
81
|
result.final_image # Final processed image
|
|
@@ -89,7 +87,7 @@ result.duration_ms # Total pipeline duration
|
|
|
89
87
|
### Access Individual Steps
|
|
90
88
|
|
|
91
89
|
```ruby
|
|
92
|
-
result =
|
|
90
|
+
result = Images::ProductPipeline.call(prompt: "Product photo")
|
|
93
91
|
|
|
94
92
|
result.step(:generate) # Generation step result
|
|
95
93
|
result.step(:upscale) # Upscale step result
|
|
@@ -100,25 +98,23 @@ result.step_count # Total number of steps
|
|
|
100
98
|
### Save Result
|
|
101
99
|
|
|
102
100
|
```ruby
|
|
103
|
-
result =
|
|
101
|
+
result = Images::ProductPipeline.call(prompt: "...")
|
|
104
102
|
result.save("final_output.png")
|
|
105
103
|
```
|
|
106
104
|
|
|
107
105
|
### Conditional Execution
|
|
108
106
|
|
|
109
107
|
```ruby
|
|
110
|
-
module
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
step :remove_bg, remover: BackgroundRemover, if: ->(ctx) { ctx[:transparent] }
|
|
116
|
-
end
|
|
108
|
+
module Images
|
|
109
|
+
class SmartPipeline < ApplicationImagePipeline
|
|
110
|
+
step :generate, generator: ProductGenerator
|
|
111
|
+
step :upscale, upscaler: PhotoUpscaler, if: ->(ctx) { ctx[:hd] }
|
|
112
|
+
step :remove_bg, remover: BackgroundRemover, if: ->(ctx) { ctx[:transparent] }
|
|
117
113
|
end
|
|
118
114
|
end
|
|
119
115
|
|
|
120
116
|
# Call with options
|
|
121
|
-
result =
|
|
117
|
+
result = Images::SmartPipeline.call(
|
|
122
118
|
prompt: "Product photo",
|
|
123
119
|
hd: true,
|
|
124
120
|
transparent: false
|
|
@@ -130,26 +126,24 @@ result = <%= @root_namespace %>::Image::SmartPipeline.call(
|
|
|
130
126
|
### E-commerce Product Pipeline
|
|
131
127
|
|
|
132
128
|
```ruby
|
|
133
|
-
module
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
version "1.0"
|
|
129
|
+
module Images
|
|
130
|
+
class EcommercePipeline < ApplicationImagePipeline
|
|
131
|
+
description "Generate and process product images"
|
|
132
|
+
version "1.0"
|
|
138
133
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
134
|
+
step :generate, generator: ProductGenerator
|
|
135
|
+
step :upscale, upscaler: PhotoUpscaler, scale: 2
|
|
136
|
+
step :remove_bg, remover: BackgroundRemover
|
|
137
|
+
step :analyze, analyzer: ProductAnalyzer
|
|
143
138
|
|
|
144
|
-
|
|
139
|
+
cache_for 1.day
|
|
145
140
|
|
|
146
|
-
|
|
141
|
+
after_pipeline :log_completion
|
|
147
142
|
|
|
148
|
-
|
|
143
|
+
private
|
|
149
144
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
end
|
|
145
|
+
def log_completion(result)
|
|
146
|
+
Rails.logger.info("Pipeline completed: cost=#{result.total_cost}")
|
|
153
147
|
end
|
|
154
148
|
end
|
|
155
149
|
end
|
|
@@ -158,45 +152,41 @@ end
|
|
|
158
152
|
### Marketing Asset Pipeline
|
|
159
153
|
|
|
160
154
|
```ruby
|
|
161
|
-
module
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
stop_on_error false # Continue even if transform fails
|
|
169
|
-
end
|
|
155
|
+
module Images
|
|
156
|
+
class MarketingPipeline < ApplicationImagePipeline
|
|
157
|
+
step :generate, generator: MarketingGenerator, quality: "hd"
|
|
158
|
+
step :transform, transformer: BrandStyleTransformer, strength: 0.3
|
|
159
|
+
step :variations, variator: DesignVariator, count: 4
|
|
160
|
+
|
|
161
|
+
stop_on_error false # Continue even if transform fails
|
|
170
162
|
end
|
|
171
163
|
end
|
|
172
164
|
|
|
173
|
-
result =
|
|
165
|
+
result = Images::MarketingPipeline.call(prompt: "Sale banner")
|
|
174
166
|
result.step(:variations).images # Get all variations
|
|
175
167
|
```
|
|
176
168
|
|
|
177
169
|
### Photo Enhancement Pipeline
|
|
178
170
|
|
|
179
171
|
```ruby
|
|
180
|
-
module
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
step :analyze, analyzer: QualityAnalyzer
|
|
172
|
+
module Images
|
|
173
|
+
class EnhancementPipeline < ApplicationImagePipeline
|
|
174
|
+
step :upscale, upscaler: PhotoUpscaler, scale: 2
|
|
175
|
+
step :enhance, transformer: EnhancementTransformer, strength: 0.2
|
|
176
|
+
step :analyze, analyzer: QualityAnalyzer
|
|
186
177
|
|
|
187
|
-
|
|
178
|
+
before_pipeline :validate_image_format
|
|
188
179
|
|
|
189
|
-
|
|
180
|
+
private
|
|
190
181
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
end
|
|
182
|
+
def validate_image_format
|
|
183
|
+
raise ArgumentError, "Image required" unless context[:image]
|
|
194
184
|
end
|
|
195
185
|
end
|
|
196
186
|
end
|
|
197
187
|
|
|
198
188
|
# Process existing image
|
|
199
|
-
result =
|
|
189
|
+
result = Images::EnhancementPipeline.call(image: "photo.jpg")
|
|
200
190
|
```
|
|
201
191
|
|
|
202
192
|
## Result Methods
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Images Transformers
|
|
2
2
|
|
|
3
3
|
This directory contains image transformation services (style transfer, img2img). All transformers inherit from `ApplicationImageTransformer`.
|
|
4
4
|
|
|
@@ -12,13 +12,11 @@ rails generate ruby_llm_agents:image_transformer Style --strength 0.8
|
|
|
12
12
|
|
|
13
13
|
Or create manually:
|
|
14
14
|
```ruby
|
|
15
|
-
module
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
size "1024x1024"
|
|
21
|
-
end
|
|
15
|
+
module Images
|
|
16
|
+
class StyleTransformer < ApplicationImageTransformer
|
|
17
|
+
model "gpt-image-1"
|
|
18
|
+
strength 0.7
|
|
19
|
+
size "1024x1024"
|
|
22
20
|
end
|
|
23
21
|
end
|
|
24
22
|
```
|
|
@@ -40,7 +38,7 @@ end
|
|
|
40
38
|
## Using Transformers
|
|
41
39
|
|
|
42
40
|
```ruby
|
|
43
|
-
result =
|
|
41
|
+
result = Images::StyleTransformer.call(
|
|
44
42
|
image: "photo.jpg",
|
|
45
43
|
prompt: "Oil painting style, impressionist"
|
|
46
44
|
)
|
|
@@ -53,7 +51,7 @@ result.save("transformed.png")
|
|
|
53
51
|
### Override Strength
|
|
54
52
|
|
|
55
53
|
```ruby
|
|
56
|
-
result =
|
|
54
|
+
result = Images::StyleTransformer.call(
|
|
57
55
|
image: "photo.jpg",
|
|
58
56
|
prompt: "Watercolor painting",
|
|
59
57
|
strength: 0.5 # More subtle
|
|
@@ -65,18 +63,16 @@ result = <%= @root_namespace %>::Image::StyleTransformer.call(
|
|
|
65
63
|
### Artistic Style Transfer
|
|
66
64
|
|
|
67
65
|
```ruby
|
|
68
|
-
module
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
strength 0.8
|
|
66
|
+
module Images
|
|
67
|
+
class ArtisticTransformer < ApplicationImageTransformer
|
|
68
|
+
strength 0.8
|
|
72
69
|
|
|
73
|
-
|
|
74
|
-
end
|
|
70
|
+
template "{prompt} style, artistic rendering, high quality"
|
|
75
71
|
end
|
|
76
72
|
end
|
|
77
73
|
|
|
78
74
|
# Usage
|
|
79
|
-
|
|
75
|
+
Images::ArtisticTransformer.call(
|
|
80
76
|
image: "photo.jpg",
|
|
81
77
|
prompt: "Van Gogh starry night"
|
|
82
78
|
)
|
|
@@ -85,14 +81,12 @@ end
|
|
|
85
81
|
### Photo Enhancement
|
|
86
82
|
|
|
87
83
|
```ruby
|
|
88
|
-
module
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
"Enhanced lighting, improved colors, professional photography"
|
|
95
|
-
end
|
|
84
|
+
module Images
|
|
85
|
+
class EnhancementTransformer < ApplicationImageTransformer
|
|
86
|
+
strength 0.3 # Subtle enhancement
|
|
87
|
+
|
|
88
|
+
def default_prompt
|
|
89
|
+
"Enhanced lighting, improved colors, professional photography"
|
|
96
90
|
end
|
|
97
91
|
end
|
|
98
92
|
end
|
|
@@ -101,13 +95,11 @@ end
|
|
|
101
95
|
### Sketch to Photo
|
|
102
96
|
|
|
103
97
|
```ruby
|
|
104
|
-
module
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
strength 0.9
|
|
98
|
+
module Images
|
|
99
|
+
class SketchToPhotoTransformer < ApplicationImageTransformer
|
|
100
|
+
strength 0.9
|
|
108
101
|
|
|
109
|
-
|
|
110
|
-
end
|
|
102
|
+
template "Photorealistic version of this sketch: {prompt}"
|
|
111
103
|
end
|
|
112
104
|
end
|
|
113
105
|
```
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Images Upscalers
|
|
2
2
|
|
|
3
3
|
This directory contains image upscaling services. All upscalers inherit from `ApplicationImageUpscaler`.
|
|
4
4
|
|
|
@@ -12,13 +12,11 @@ rails generate ruby_llm_agents:image_upscaler Photo --scale 4
|
|
|
12
12
|
|
|
13
13
|
Or create manually:
|
|
14
14
|
```ruby
|
|
15
|
-
module
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
denoise true
|
|
21
|
-
end
|
|
15
|
+
module Images
|
|
16
|
+
class PhotoUpscaler < ApplicationImageUpscaler
|
|
17
|
+
model "esrgan"
|
|
18
|
+
scale 4
|
|
19
|
+
denoise true
|
|
22
20
|
end
|
|
23
21
|
end
|
|
24
22
|
```
|
|
@@ -40,7 +38,7 @@ end
|
|
|
40
38
|
## Using Upscalers
|
|
41
39
|
|
|
42
40
|
```ruby
|
|
43
|
-
result =
|
|
41
|
+
result = Images::PhotoUpscaler.call(image: "small.jpg")
|
|
44
42
|
|
|
45
43
|
result.url # Upscaled image URL
|
|
46
44
|
result.image_data # Binary data
|
|
@@ -52,7 +50,7 @@ result.save("large.png")
|
|
|
52
50
|
### Override Scale
|
|
53
51
|
|
|
54
52
|
```ruby
|
|
55
|
-
result =
|
|
53
|
+
result = Images::PhotoUpscaler.call(
|
|
56
54
|
image: "thumbnail.jpg",
|
|
57
55
|
scale: 2 # Just double it
|
|
58
56
|
)
|
|
@@ -63,13 +61,11 @@ result = <%= @root_namespace %>::Image::PhotoUpscaler.call(
|
|
|
63
61
|
### Thumbnail Enhancement
|
|
64
62
|
|
|
65
63
|
```ruby
|
|
66
|
-
module
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
sharpen true
|
|
72
|
-
end
|
|
64
|
+
module Images
|
|
65
|
+
class ThumbnailUpscaler < ApplicationImageUpscaler
|
|
66
|
+
scale 4
|
|
67
|
+
denoise true
|
|
68
|
+
sharpen true
|
|
73
69
|
end
|
|
74
70
|
end
|
|
75
71
|
```
|
|
@@ -77,12 +73,10 @@ end
|
|
|
77
73
|
### Print Preparation
|
|
78
74
|
|
|
79
75
|
```ruby
|
|
80
|
-
module
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
denoise false # Preserve original detail
|
|
85
|
-
end
|
|
76
|
+
module Images
|
|
77
|
+
class PrintUpscaler < ApplicationImageUpscaler
|
|
78
|
+
scale 4
|
|
79
|
+
denoise false # Preserve original detail
|
|
86
80
|
end
|
|
87
81
|
end
|
|
88
82
|
```
|
|
@@ -90,13 +84,11 @@ end
|
|
|
90
84
|
### Avatar Enhancement
|
|
91
85
|
|
|
92
86
|
```ruby
|
|
93
|
-
module
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
sharpen true
|
|
99
|
-
end
|
|
87
|
+
module Images
|
|
88
|
+
class AvatarUpscaler < ApplicationImageUpscaler
|
|
89
|
+
scale 2 # Modest upscale
|
|
90
|
+
denoise true
|
|
91
|
+
sharpen true
|
|
100
92
|
end
|
|
101
93
|
end
|
|
102
94
|
```
|