Class: ActiveHarness::Providers::Images::OpenAI
- Defined in:
- lib/active_harness/providers/images/openai.rb
Constant Summary collapse
- ENDPOINT =
"https://api.openai.com/v1/images/generations"
Constants inherited from Base
Base::HTTP, Base::STREAMING_HTTP
Instance Method Summary collapse
Instance Method Details
#call(model:, prompt:, size: "1024x1024", quality: nil, **_) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/active_harness/providers/images/openai.rb', line 13 def call(model:, prompt:, size: "1024x1024", quality: nil, **_) headers = { "Content-Type" => "application/json", "Authorization" => "Bearer #{api_key}" } raw = post_json(URI(ENDPOINT), headers: headers, body: build_payload(model, prompt, size, quality), timeout: 60) data = parse!(raw) handle_error!(data) b64 = data.dig("data", 0, "b64_json") raise Errors::ProviderError, "No image data in response" unless b64 { content: b64, provider: :openai, model: model, usage: nil } end |