| const config = require('../../config'); | |
| class FireworksAPI { | |
| constructor() { | |
| this.apiKey = config.fireworks.apiKey; | |
| this.baseUrl = config.fireworks.baseUrl; | |
| } | |
| async generateImage(prompt, options = {}) { | |
| const defaultOptions = { | |
| model: 'stable-diffusion-xl-1024-v1-0', | |
| steps: 30, | |
| width: 1024, | |
| height: 1024, | |
| }; | |
| const requestOptions = { ...defaultOptions, ...options }; | |
| try { | |
| const response = await fetch(`${this.baseUrl}/image_generation`, { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| 'Authorization': `Bearer ${this.apiKey}`, | |
| }, | |
| body: JSON.stringify({ | |
| prompt, | |
| ...requestOptions, | |
| }), | |
| }); | |
| if (!response.ok) { | |
| throw new Error(`API request failed with status ${response.status}`); | |
| } | |
| const data = await response.json(); | |
| return data; | |
| } catch (error) { | |
| console.error('Error generating image:', error); | |
| throw error; | |
| } | |
| } | |
| } | |
| module.exports = FireworksAPI; | |