Feel free to contribute to the documentation!
WomboDream
is the main class of the library and is used to interact with the picture generation api.
Build api endpoint url from the instance template.
buildApiTaskUrl(taskId: string): string
Example:
buildApiTaskUrl('ae6za016-2695-4383-7ba5-fab53e58b7be');
https://paint.api.wombo.ai/api/tasks/ae6za016-2695-4383-7ba5-fab53e58b7be
Build api endpoint url from the instance template without task id.
buildRawApiTaskUrl(): string
Example:
buildRawApiTaskUrl();
https://paint.api.wombo.ai/api/tasks/
Build api endpoint url for media uploading.
buildUploadUrl(): string
Example:
buildUploadUrl();
https://mediastore.api.wombo.ai/io/
Create a new request agent with the correct authentication headers with the instance information.
async buildRequestAgent(): Promise<AxiosInstance>
Example:
buildRequestAgent();
agent.then((agent) => {
console.log(agent);
agent.get('https://app.wombo.ai/');
});
{
...,
headers: {
...,
Origin: "https://app.wombo.art",
Referer: "https://app.wombo.art",
Authorization: "Bearer xxxxxxxxxxxxxxxxxxxxxxx",
Service: "Dream",
...
},
baseURL: "https://paint.api.wombo.ai/api/tasks/",
...
}
Generate a task from the given parameters.
async createTask(prompt: string, style: number, input_image?: TaskImageInputSpec, display_freq?: number, premium?: boolean): Promise<Task>
Examples:
createTask(prompt: "kitten", style: 3).then(console.log);
{
id: '384e00ee-bc71-4260-8aab-c475a7f14da1',
user_id: 'XfLI9hZ5Y8gXWvbieoJlXNvCcR32',
input_spec: {
display_freq: 10,
prompt: 'kitten',
style: 3,
},
state: 'pending',
premium: false,
created_at: '2022-03-15T23:41:02.396770+00:00',
updated_at: '2022-03-15T23:41:02.892364',
photo_url_list: [],
generated_photo_keys: [],
result: null,
}
createTask(prompt: "kitten", style: 3, {mediastore_id: "c24c5f97-47de-457a-9f27-922323b22eff", weight: 'HIGH'}).then(console.log);
{
id: '384e00ee-bc71-4260-8aab-c475a7f14da1',
user_id: 'XfLI9hZ5Y8gXWvbieoJlXNvCcR32',
input_spec: {
display_freq: 10,
prompt: 'kitten',
style: 3,
input_image: {
weight: 'HIGH',
mediastore_id: '385ca487-6714-48bd-a015-0b8961f75abd',
},
},
state: 'pending',
premium: false,
created_at: '2022-03-15T23:41:02.396770+00:00',
updated_at: '2022-03-15T23:41:02.892364',
photo_url_list: [],
generated_photo_keys: [],
result: null,
}
Fetch task information from the given id.
fetchTaskInfos(taskId: string): Promise<Task>
Example:
fetchTaskInfos('d5f9efc1-2d7c-4e13-9543-be4a508d1d03').then(console.log);
{
id: 'd5f9efc1-2d7c-4e13-9543-be4a508d1d03',
user_id: 'w8hVba2l1hbETsel4gwFDqMoxXj2',
input_spec: {
style: 3,
prompt: 'kitten',
display_freq: 10,
},
state: 'generating',
premium: false,
created_at: '2022-03-15T23:52:30.320655+00:00',
updated_at: '2022-03-15T23:52:32.446872+00:00',
photo_url_list: [
'https://prod-wombo-paint.s3.amazonaws.com/generated/d5f9efc1-2d7c-4e13-9543-be4a508d1d03/0.jpg?AWSAccessKeyId=AKIAWGXQXQ6WCOB7PP5J&Signature=6zvzjO1BMr0UPy9UY%2B6SY1xTF5Q%3D&Expires=1647391954',
],
generated_photo_keys: [
'generated/d5f9efc1-2d7c-4e13-9543-be4a508d1d03/0.jpg',
],
result: null,
}
Generate a picture from the given parameters.
The
progressCallback
is called every time the generating task is fetched.The returned
Task
is the final result of the generation.
async generatePicture(prompt: string, style: number, progressCallback?: (task: Task) => void, input_image?: TaskImageInputSpec, checkFrequency?: number, display_freq?: number, premium?: boolean): Promise<Task>
Examples:
generatePicture('kitten', 21, (task) => {
console.log(task.state, 'stage', task.photo_url_list.length);
}).then((task) => console.log(task?.result.final));
generatePicture(
'kitten',
21,
(task) => {
console.log(task.state, 'stage', task.photo_url_list.length);
},
{ mediastore_id: 'c24c5f97-47de-457a-9f27-922323b22eff', weight: 'HIGH' }
).then((task) => console.log(task?.result.final));
generating stage 0
generating stage 4
generating stage 10
generating stage 13
generating stage 14
generating stage 16
generating stage 17
generating stage 18
generating stage 20
completed stage 21
https://prod-wombo-paint.s3.amazonaws.com/generated/fbcb32c2-1119-46e4-8fd5-797e9b2d69ac/final.jpg?AWSAccessKeyId=AKIAWGXQXQ6WCOB7PP5J&Signature=DMYucir%2FAYhCbM2aer8Ct6GFHt4%3D&Expires=1647392658
Upload an image to use it for future image generations.
async uploadImage(bufferedImage: Buffer): Promise<UploadResource>
Example:
uploadImage(fs.readFileSync('./image.jpg')).then(console.log);
{
id: '385ca487-6714-48bd-a015-0b8961f75abd',
media_url: 'https://d3r7u1fd9rqpsu.cloudfront.net/data_72/385ca487-6714-48bd-a015-0b8961f75abd.jpeg?Expires=1647470685&Signature=u48mJy3A5t0rx6vv5UpDhn-wo1WF2UgZBScU3Rb38L2owmckh6-1dACclQXStKyZAp6ZdpeXy5AacWEu5r6DVGOcNIES~IRcO1UKogRaqKTAYrGnqyG~Gb82CfnAxVfCg4tHMKS5z3W~AQjdIF9pdeJcGu5xf1n3ra02vt2u19~i0uZ1CO-UjLoHn-yq7qzSw3QaL4mwdaFJhfCpZHu67VelYMt2S9Riixadg0LiNiBvG-zvz6Xtll7qOmYMvtfruCeiYHle68Csy8gkudisVllTeE-Wxn5P7zTMkKQfvu9Ls--nFtmvqoCWFzL9vX8NJRmIrebCJsaxOG6KEYD83A__&Key-Pair-Id=K31QTIHFNZAJ0H',
created_at: '2022-03-16T21:44:45.659979+00:00',
expiry_at: '2022-03-19T21:44:45.659979+00:00'
}
Fetch all available styles.
async fetchStyles(): Promise<Array<Style>>
Example:
fetchStyles().then((styles) => console.log(styles));
[
{
id: 21,
name: 'Psychedelic',
is_visible: true,
created_at: '2022-03-08T04:45:45.191477+00:00',
updated_at: '2022-03-08T04:45:45.191477+00:00',
deleted_at: null,
photo_url:
'https://d3j730xi5ph1dq.cloudfront.net/dream/style_thumbnail/lisa.jpg',
},
{
id: 1,
name: 'Synthwave',
is_visible: true,
created_at: '2021-10-11T17:55:51.462768+00:00',
updated_at: '2021-12-03T00:57:10.269924+00:00',
deleted_at: null,
photo_url:
'https://d3j730xi5ph1dq.cloudfront.net/dream/style_thumbnail/synthwave.jpg',
},
...
]
GoogleAuthentifier
is a class that helps you to authenticate with Googleidentitytoolkit
api.
Build a signUp api endpoint url from the instance template.
buildSignUpUserUrl(): string
Example:
buildSignUpUserUrl();
https://www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser?key=AIzaSyDxCoSRCFvdsYcJalNfBQQfGl0-YycRkdE
Build a refresh token api endpoint url from the instance template.
buildTokenRefreshUrl(): string
Example:
buildTokenRefreshUrl();
https://securetoken.googleapis.com/v1/token?key=AIzaSyDxCoSRCFvdsYcJalNfBQQfGl0-YycRkdE
Build a signIn api endpoint url from the instance template.
buildSignInUserUrl(): string
Example:
buildSignInUserUrl();
https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key=AIzaSyDxCoSRCFvdsYcJalNfBQQfGl0-YycRkdE
Sign up a new user with the given parameters.
signUpBody
can be empty, in this case, the user will be registered as a guess, or you can pass asignUpBody
with the following fields:{ "email": string, "password": string, }
async signUp(signUpBody?: CreditentialsBody): Promise<AuthorisationCache>
Example:
signUp();
{
kind: 'identitytoolkit#SignupNewUserResponse',
idToken: 'xxxxxxxxxxxxxxxxxxxxxxx',
refreshToken: 'xxxxxxxxxxxxxxxxxxxxxxx',
expiresIn: '3600',
localId: 'Io5e1uKnZPh446Dp06H9S1R15xz2',
}
Sign in a user with the given parameters.
You must pass
signUpBody
with the following fields:{ "email": string, "password": string, }
async signIn(signInBody: CreditentialsBody): Promise<AuthorisationCache>
Example:
signIn({
email: '[email protected]',
password: 'mypassword',
});
{
kind: 'identitytoolkit#SignupNewUserResponse',
localId: 'Io5e1uKnZPh446Dp06H9S1R15xz2',
displayName: '',
email: '[email protected]',
idToken: 'xxxxxxxxxxxxxxxxxxxxxxx',
registered: true,
refreshToken: 'xxxxxxxxxxxxxxxxxxxxxxx',
expiresIn: '3600',
}
Retrieve the authorisation token.
async obtainAuthorisationToken(): Promise<string>
Example:
obtainAuthorisationToken().then(console.log);
xxxxxxxxxxxxxxxxxxxxxxx
Refresh the authorisation token from the cached refresh token.
async refreshAuthorisationToken(): Promise<AuthorisationCache>
Example:
refreshAuthorisationToken().then(console.log);
{
token: "xxxxxxxxxxxxxxxxxxxxxxx",
expirationDate: 2022-03-16T01:39:06.625Z,
refreshToken: "xxxxxxxxxxxxxxxxxxxxxx"
}
Makes sure that the cached token is valid.
async ensureCacheValidity(): Promise<AuthorisationCache>
Example:
ensureCacheValidity().then(console.log);
{
token: "xxxxxxxxxxxxxxxxxxxxxxx",
expirationDate: 2022-03-16T01:39:06.625Z,
refreshToken: "xxxxxxxxxxxxxxxxxxxxxx"
}
Returns
true
if the cached token is still valid.
isCacheValid(): boolean
Example:
isCacheValid();
false