Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit 968f96c

Browse files
authored
api updated & cancel model required (#3)
1 parent ea7e69a commit 968f96c

7 files changed

+208
-188
lines changed

main.d.ts

+17-6
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ declare class ProdiaAI {
1111
*/
1212
constructor(key: string)
1313

14-
models: string[]
15-
1614
/**
1715
* Creates an AI image job.
1816
* @param {Object} config - Image job configuration.
@@ -22,7 +20,7 @@ declare class ProdiaAI {
2220
* @param {Number} config.cfg_scale - Image generation scale.
2321
* @param {String} config.sampler - Image generation sampler.
2422
* @param {String} config.model - Image generation model.
25-
* @returns {Promise<String>} - Promise with the API response content.
23+
* @returns {Promise<Object>} - Promise with the API response content.
2624
*/
2725
createJob(config: {
2826
prompt: string
@@ -31,14 +29,27 @@ declare class ProdiaAI {
3129
cfg_scale: number
3230
sampler: string
3331
model: string
34-
}): Promise<string>
32+
}): Promise<{
33+
job: string;
34+
status: string;
35+
}>
3536

3637
/**
3738
* Retrieves information about a specific job ID.
3839
* @param {String} jobId - Job ID.
39-
* @returns {Promise<String>} - Promise with the API response content.
40+
* @returns {Promise<Object>} - Promise with the API response content.
41+
*/
42+
getJob(jobId: string): Promise<{
43+
job: string,
44+
status: string,
45+
imageUrl: string
46+
}>
47+
48+
/**
49+
* Get a list of current available models.
50+
* @returns {Promise<string[]>} - Promise with the API response content.
4051
*/
41-
getJob(jobId: string): Promise<string>
52+
getModels(): Promise<string[]>
4253
}
4354

4455
/**

main.js

+17-39
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,10 @@
44
class ProdiaAI {
55
#API_DOMAIN = 'https://api.prodia.com'
66
#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-
]
367

378
/**
389
* 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.
4111
*/
4212
constructor (key) {
4313
this.key = key
@@ -52,18 +22,12 @@ class ProdiaAI {
5222
* @param {Number} config.cfg_scale - Image generation scale.
5323
* @param {String} config.sampler - Image generation sampler.
5424
* @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.
5626
*/
5727
async createJob(config) {
5828
if (!config?.prompt && config.prompt === '') {
5929
throw new Error('Prompt is required!')
6030
}
61-
if (config?.model) {
62-
const model = this.models.includes(config.model)
63-
if (!model) {
64-
throw new Error('Model not accepted')
65-
}
66-
}
6731
const fetch_response = await fetch(`${this.#API_DOMAIN}/${this.#API_VERSION}/job`, {
6832
method: 'POST',
6933
headers: {
@@ -79,7 +43,7 @@ class ProdiaAI {
7943
/**
8044
* Retrieves information about a specific job ID.
8145
* @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.
8347
*/
8448
async getJob (jobId) {
8549
if (!jobId) {
@@ -93,6 +57,20 @@ class ProdiaAI {
9357
})
9458
return await fetch_response.json()
9559
}
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+
}
9674
}
9775

9876

0 commit comments

Comments
 (0)