UNPKG

@llumiverse/drivers

Version:

LLM driver implementations. Currently supported are: openai, huggingface, bedrock, replicate.

120 lines 4.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FireflyDriver = void 0; const core_1 = require("@llumiverse/core"); class FireflyDriver extends core_1.AbstractDriver { static PROVIDER = "firefly"; provider = FireflyDriver.PROVIDER; endpoint; constructor(options) { super(options); if (!options.apiKey) { throw new Error("No API key provided for Firefly driver"); } this.endpoint = options.endpoint || "https://firefly-api.adobe.io/v3"; } async requestTextCompletion(_prompt, _options) { throw new Error("Text completion not supported by Firefly"); } async requestTextCompletionStream(_prompt, _options) { throw new Error("Text completion streaming not supported by Firefly"); } async requestImageGeneration(segments, options) { this.logger.debug(`[${this.provider}] Generating image with model ${options.model}`); const prompt = segments.map(s => s.content).join("\n\n"); try { const payload = { prompt: prompt, }; const response = await fetch(`${this.endpoint}/images/generate`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-api-key': this.options.apiKey, }, body: JSON.stringify(payload) }); if (!response.ok) { const error = await response.json(); throw new Error(`Firefly API error: ${error.message || response.statusText}`); } const result = await response.json(); if (result.promptHasDeniedWords || result.promptHasBlockedArtists) { return { result: [], error: { message: "Prompt contains denied words or blocked artists", code: "content_policy_violation" } }; } return { result: result.outputs.map(output => ({ type: "image", value: output.image.url })) }; } catch (error) { this.logger.error({ error }, "[Firefly] Image generation failed"); return { result: [], error: { message: error.message, code: error.code || 'GENERATION_FAILED' } }; } } mapSize(size) { // Default to 1024x1024 if no size specified if (!size) return { width: 1024, height: 1024 }; const [width, height] = size.split('x').map(Number); return { width, height }; } async listModels(_params) { return [ { id: "firefly-v3-text-to-image", name: "Firefly v3 Text to Image", provider: this.provider, description: "Adobe Firefly v3 text to image generation model", tags: ["image-generation"] }, { id: "firefly-v3-image-to-image", name: "Firefly v3 Image to Image", provider: this.provider, description: "Adobe Firefly v3 image to image generation model", tags: ["image-generation"] }, { id: "firefly-v3-inpainting", name: "Firefly v3 Inpainting", provider: this.provider, description: "Adobe Firefly v3 inpainting model", tags: ["image-generation"] } ]; } async validateConnection() { try { const response = await fetch(`${this.endpoint}/auth/validate`, { headers: { 'x-api-key': this.options.apiKey } }); return response.ok; } catch (error) { this.logger.error({ error }, "[Firefly] Connection validation failed"); return false; } } async generateEmbeddings(_options) { throw new Error("Embeddings not supported by Firefly"); } } exports.FireflyDriver = FireflyDriver; //# sourceMappingURL=firefly.js.map