Stability, BFL, Runway, Luma, Replicate, fal, Ideogram, Recraft, Leonardo, MiniMax, Kling, Higgsfield: call tables checked against vendor specs/SDKs, ImageGenerator/VideoGenerator seam with capped polling, /ai/media demo. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
68 lines
3.0 KiB
C++
68 lines
3.0 KiB
C++
#pragma once
|
|
|
|
// Stability AI: v2beta Stable Image (generate, edit, upscale, control), 3D,
|
|
// Stable Audio, and the v1 engines / account surface. Every v2beta call is
|
|
// multipart/form-data; we always ask for JSON (base64 images) so errors and
|
|
// results parse the same way.
|
|
|
|
#include "vendors/media/common/client_factory.h"
|
|
#include "vendors/media/common/job.h"
|
|
#include "vendors/media/common/media_service.h"
|
|
#include "vendors/media/stability/calls.h"
|
|
|
|
namespace molo::media {
|
|
|
|
class StabilityClient : public MediaService {
|
|
public:
|
|
static constexpr const char* kHost = "https://api.stability.ai";
|
|
static constexpr const char* kKeyEnv = "STABILITY_API_KEY";
|
|
|
|
explicit StabilityClient(std::shared_ptr<llm::ApiClient> client)
|
|
: MediaService(std::move(client), StabilityCalls::table()) {}
|
|
static llm::ApiClientConfig config() { return ClientFactory::bearer("stability", kHost, kKeyEnv); }
|
|
static std::shared_ptr<StabilityClient> from_env() {
|
|
return std::make_shared<StabilityClient>(ClientFactory::real(config(), ClientFactory::env({kKeyEnv})));
|
|
}
|
|
static std::shared_ptr<StabilityClient> with(std::unique_ptr<clients::Transport> t, const std::string& key) {
|
|
return std::make_shared<StabilityClient>(ClientFactory::with(std::move(t), config(), key));
|
|
}
|
|
|
|
// Any v2beta POST row (stable-image.*, 3d.*, audio.*). Paid: confirm required.
|
|
// Returns {image|audio, finish_reason, seed} or, for async rows, {id}.
|
|
Json submit(const std::string& key, const Json& fields, const std::vector<FilePart>& files, bool confirm);
|
|
PreparedCall plan(const std::string& key, const Json& fields, const std::vector<FilePart>& files) const;
|
|
|
|
// Polls: HTTP 202 {id,status} while running, 200 with the result when done.
|
|
Json result(const std::string& id); // /v2beta/results/{id}
|
|
Json audio_result(const std::string& id); // /v2beta/audio/results/{id}
|
|
Json creative_upscale_result(const std::string& id); // legacy creative upscale path
|
|
|
|
// v1 reads.
|
|
Json engines();
|
|
Json account();
|
|
Json balance();
|
|
// v1 text-to-image (JSON body, artifacts[] with base64).
|
|
Json v1_text_to_image(const std::string& engine_id, const Json& body, bool confirm);
|
|
};
|
|
|
|
class StabilityImageGenerator : public ImageGenerator {
|
|
public:
|
|
explicit StabilityImageGenerator(std::shared_ptr<StabilityClient> client) : client_(std::move(client)) {}
|
|
std::string provider() const override { return "stability"; }
|
|
bool configured() const override { return client_->configured(); }
|
|
std::vector<std::string> models() const override;
|
|
Json plan(const ImageRequest& request) const override;
|
|
JobTicket submit(const ImageRequest& request, bool confirm) override;
|
|
JobStatus poll(const JobTicket& ticket) override;
|
|
bool cancel(const JobTicket&, bool) override { return false; } // no cancel in the API
|
|
|
|
// model -> table key (ultra, core, sd3*), "" model = core.
|
|
static std::string key_for(const std::string& model);
|
|
|
|
private:
|
|
Json fields(const ImageRequest& request, std::string& key) const;
|
|
std::shared_ptr<StabilityClient> client_;
|
|
};
|
|
|
|
} // namespace molo::media
|