4
4
class ProdiaAI {
5
5
#API_DOMAIN = 'https://api.prodia.com'
6
6
#API_VERSION = 'v1'
7
-
8
- models = [
9
- 'analog-diffusion-1.0.ckpt [9ca13f02]' ,
10
- 'anythingv3_0-pruned.ckpt [2700c435]' ,
11
- 'anything-v4.5-pruned.ckpt [65745d25]' ,
12
- 'anythingV5_PrtRE.safetensors [893e49b9]' ,
13
- 'AOM3A3_orangemixs.safetensors [9600da17]' ,
14
- 'deliberate_v2.safetensors [10ec4b29]' ,
15
- 'dreamlike-diffusion-1.0.safetensors [5c9fd6e0]' ,
16
- 'dreamlike-diffusion-2.0.safetensors [fdcf65e7]' ,
17
- 'dreamshaper_5BakedVae.safetensors [a3fbf318]' ,
18
- 'dreamshaper_6BakedVae.safetensors [114c8abb]' ,
19
- 'elldreths-vivid-mix.safetensors [342d9d26]' ,
20
- 'lyriel_v15.safetensors [65d547c5]' ,
21
- 'lyriel_v16.safetensors [68fceea2]' ,
22
- 'mechamix_v10.safetensors [ee685731]' ,
23
- 'meinamix_meinaV9.safetensors [2ec66ab0]' ,
24
- 'openjourney_V4.ckpt [ca2f377f]' ,
25
- 'portrait+1.0.safetensors [1400e684]' ,
26
- 'Realistic_Vision_V1.4-pruned-fp16.safetensors [8d21810b]' ,
27
- 'Realistic_Vision_V2.0.safetensors [79587710]' ,
28
- 'revAnimated_v122.safetensors [3f4fefd9]' ,
29
- 'riffusion-model-v1.ckpt [3aafa6fe]' ,
30
- 'sdv1_4.ckpt [7460a6fa]' ,
31
- 'v1-5-pruned-emaonly.ckpt [81761151]' ,
32
- 'shoninsBeautiful_v10.safetensors [25d8c546]' ,
33
- 'theallys-mix-ii-churned.safetensors [5d9225a4]' ,
34
- 'timeless-1.0.ckpt [7c4971d4]'
35
- ]
36
7
37
8
/**
38
9
* Initializes a ProdiaAI instance.
39
- * @param {Object } obj - Initialization parameters object.
40
- * @param {String } obj.key - Your API key.
10
+ * @param {String } key - Your API key.
41
11
*/
42
12
constructor ( key ) {
43
13
this . key = key
@@ -52,18 +22,12 @@ class ProdiaAI {
52
22
* @param {Number } config.cfg_scale - Image generation scale.
53
23
* @param {String } config.sampler - Image generation sampler.
54
24
* @param {String } config.model - Image generation model.
55
- * @returns {Promise<String> } - Promise with the API response content.
25
+ * @returns {Promise<{ job: String, status: String }> } object - Promise with the API response content.
56
26
*/
57
27
async createJob ( config ) {
58
28
if ( ! config ?. prompt && config . prompt === '' ) {
59
29
throw new Error ( 'Prompt is required!' )
60
30
}
61
- if ( config ?. model ) {
62
- const model = this . models . includes ( config . model )
63
- if ( ! model ) {
64
- throw new Error ( 'Model not accepted' )
65
- }
66
- }
67
31
const fetch_response = await fetch ( `${ this . #API_DOMAIN} /${ this . #API_VERSION} /job` , {
68
32
method : 'POST' ,
69
33
headers : {
@@ -79,7 +43,7 @@ class ProdiaAI {
79
43
/**
80
44
* Retrieves information about a specific job ID.
81
45
* @param {String } jobId - Job ID.
82
- * @returns {Promise<String > } - Promise with the API response content.
46
+ * @returns {Promise<{ job: string, status: string, imageUrl: string } > } - Promise with the API response content.
83
47
*/
84
48
async getJob ( jobId ) {
85
49
if ( ! jobId ) {
@@ -93,6 +57,20 @@ class ProdiaAI {
93
57
} )
94
58
return await fetch_response . json ( )
95
59
}
60
+
61
+ /**
62
+ * Get a list of current available models.
63
+ * @returns {Promise<string[]> } - Promise with the API response content.
64
+ */
65
+ async getModels ( ) {
66
+ const fetch_response = await fetch ( `${ this . #API_DOMAIN} /${ this . #API_VERSION} /models/list` , {
67
+ headers : {
68
+ 'X-Prodia-Key' : this . key ,
69
+ 'content-type' : 'application/json' ,
70
+ }
71
+ } )
72
+ return await fetch_response . json ( )
73
+ }
96
74
}
97
75
98
76
0 commit comments