Class: Clacky::Media::Generator
- Inherits:
-
Object
- Object
- Clacky::Media::Generator
- Defined in:
- lib/clacky/media/generator.rb
Overview
Top-level dispatcher: takes an AgentConfig and a request, picks the right provider class based on the configured image model’s base_url, and delegates.
Adding a new modality (video / audio) means:
1. add a generate_<modality> method here that resolves the correct
type=<modality> entry and class
2. add a provider class under lib/clacky/media/ implementing the call
Constant Summary collapse
- GOOGLE_NATIVE_HOSTS =
Hosts that speak the native Google AI Studio API instead of an OpenAI-compatible facade. Matched as a substring against the configured base_url so any regional / staging variant is caught.
[ "generativelanguage.googleapis.com", "aiplatform.googleapis.com" ].freeze
- DASHSCOPE_NATIVE_HOSTS =
Hosts that speak Alibaba’s native DashScope (Qwen-Image) API instead of an OpenAI-compatible facade. Matched as a substring so every regional variant (dashscope / dashscope-intl / dashscope-us, and the Singapore *.maas.aliyuncs.com workspace hosts) is caught. Third-party aggregators (SiliconFlow, OpenRouter, …) that re-expose qwen-image behind an OpenAI-compatible endpoint are NOT under aliyuncs.com, so they correctly keep going through OpenAICompat.
[ "aliyuncs.com" ].freeze
Instance Method Summary collapse
-
#audio_model_entry ⇒ Hash?
The type=audio model entry, or nil if not configured.
- #generate_image(prompt:, aspect_ratio: "landscape", output_dir: nil, **kwargs) ⇒ Object
- #generate_speech(input:, voice: nil, output_dir: nil, **kwargs) ⇒ Object
- #generate_video(prompt:, aspect_ratio: "landscape", duration_seconds: nil, output_dir: nil, **kwargs) ⇒ Object
-
#image_model_entry ⇒ Hash?
The type=image model entry, or nil if not configured.
-
#initialize(agent_config) ⇒ Generator
constructor
A new instance of Generator.
-
#video_model_entry ⇒ Hash?
The type=video model entry, or nil if not configured.
Constructor Details
#initialize(agent_config) ⇒ Generator
Returns a new instance of Generator.
38 39 40 |
# File 'lib/clacky/media/generator.rb', line 38 def initialize(agent_config) @agent_config = agent_config end |
Instance Method Details
#audio_model_entry ⇒ Hash?
Returns the type=audio model entry, or nil if not configured.
53 54 55 |
# File 'lib/clacky/media/generator.rb', line 53 def audio_model_entry @agent_config.find_model_by_type("audio") end |
#generate_image(prompt:, aspect_ratio: "landscape", output_dir: nil, **kwargs) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/clacky/media/generator.rb', line 57 def generate_image(prompt:, aspect_ratio: "landscape", output_dir: nil, **kwargs) entry = image_model_entry if entry.nil? return { "success" => false, "image" => nil, "error" => "No image model configured. Add a model with type=image in settings.", "error_type" => "not_configured", "provider" => "", "model" => "", "prompt" => prompt } end provider = build_provider_for(entry) provider.generate_image( prompt: prompt, aspect_ratio: aspect_ratio, output_dir: output_dir, **kwargs ) end |
#generate_speech(input:, voice: nil, output_dir: nil, **kwargs) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/clacky/media/generator.rb', line 104 def generate_speech(input:, voice: nil, output_dir: nil, **kwargs) entry = audio_model_entry if entry.nil? return { "success" => false, "audio" => nil, "error" => "No audio model configured. Add a model with type=audio in settings.", "error_type" => "not_configured", "provider" => "", "model" => "", "input" => input } end provider = build_provider_for(entry) provider.generate_speech( input: input, voice: voice, output_dir: output_dir, **kwargs ) end |
#generate_video(prompt:, aspect_ratio: "landscape", duration_seconds: nil, output_dir: nil, **kwargs) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/clacky/media/generator.rb', line 80 def generate_video(prompt:, aspect_ratio: "landscape", duration_seconds: nil, output_dir: nil, **kwargs) entry = video_model_entry if entry.nil? return { "success" => false, "video" => nil, "error" => "No video model configured. Add a model with type=video in settings.", "error_type" => "not_configured", "provider" => "", "model" => "", "prompt" => prompt } end provider = build_provider_for(entry) provider.generate_video( prompt: prompt, aspect_ratio: aspect_ratio, duration_seconds: duration_seconds, output_dir: output_dir, **kwargs ) end |
#image_model_entry ⇒ Hash?
Returns the type=image model entry, or nil if not configured.
43 44 45 |
# File 'lib/clacky/media/generator.rb', line 43 def image_model_entry @agent_config.find_model_by_type("image") end |
#video_model_entry ⇒ Hash?
Returns the type=video model entry, or nil if not configured.
48 49 50 |
# File 'lib/clacky/media/generator.rb', line 48 def video_model_entry @agent_config.find_model_by_type("video") end |