File size: 1,071 Bytes
4595df6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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;