Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add page to test generators/deployment endpoints #2

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions constants/endpoints-constants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
export const appUrl = `https://local.webaverse.com`;
export const gpt3Url = `https://gpt3.webaverse.com`; // create
export const voiceUrl = `https://voice-cw.webaverse.com`;
export const diffsoundUrl = `https://diffsound.webaverse.com`;
export const motionDiffusionUrl = `https://motion-diffusion.webaverse.com`; // create
export const stableDreamfusionUrl = `https://stable-dreamfussion.webaverse.com`; // create
export const get3dUrl = `https://get-3d.webaverse.com`; // create
export const musicGeneratorUrl = `https://music-generator.webaverse.com`; // create
export const discoDiffusionUrl = `https://disco-diffusion.weabaverse.com`; // create
listofbanned marked this conversation as resolved.
Show resolved Hide resolved
// coreweave
export const pixelArtUrl = `https://pixel-art.weabaverse.com`;
export const weaviateUrl = `https://weaviate.weabaverse.com`;
export const stableDiffusionUrl = `https://stable-diffusion.webaverse.com`;
export const voiceUrl = `https://voice-cw.webaverse.com`;
export const diffsoundUrl = `https://diffsound.webaverse.com`;
export const blipUrl = `https://blip.webaverse.com`;
149 changes: 149 additions & 0 deletions generators/generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
// import {stableDiffusionUrl} from '../../constants/endpoints.js';
import fetch from 'node-fetch';
import {
gpt3Url,
voiceUrl,
stableDiffusionUrl,
diffsoundUrl,
motionDiffusionUrl,
stableDreamfusionUrl,
get3dUrl,
musicGeneratorUrl,
weaviateUrl,
discoDiffusionUrl,
} from '../constants/endpoints-constants';

export const generateText = ({model}) => async ({x} = {}) => {
const url = `${gpt3Url}/text?x=${x}` // mock endpoint
await fetch(url)
.then(res => {
if (res.ok) {
// TODO: return generated text
} else {
throw new Error(`invalid status: ${res.status}`);
}
})
.catch(err => {
throw new Error(`url error: ${err}`);
})
}

export const generateVoice = () => async ({s, voice} = {}) => {
return `${voiceUrl}/tts?s=${s}&voice=${voice}`
}

export const generateImage = ({
modelName,
prefix,
}) => async ({
name,
description,
} = {}) => {
const s = `${prefix} ${description}`;
const u = `${stableDiffusionUrl}/image?s=${encodeURIComponent(s)}&model=${modelName}`;
const res = await fetch(u);
if (res.ok) {
const arrayBuffer = await res.arrayBuffer();
if (arrayBuffer.byteLength > 0) {
return arrayBuffer;
} else {
throw new Error(`generated empty image`);
}
} else {
throw new Error(`invalid status: ${res.status}`);
}
}

export const generateDiffSound = () => async ({s} = {}) => {
return `${diffsoundUrl}/sound?s=${s}`
}

export const generateMotionDiffusion = ({model}) => async ({x} = {}) => {
const url = `${motionDiffusionUrl}/motion?x=${x}` // mock endpoint
await fetch(url)
.then(res => {
if (res.ok) {
// TODO: return generated motion
} else {
throw new Error(`invalid status: ${res.status}`);
}
})
.catch(err => {
throw new Error(`url error: ${err}`);
})
}

export const generateObjectOrConsumable = ({model}) => async ({x} = {}) => {
const url = `${stableDreamfusionUrl}/object?x=${x}` // mock endpoint
await fetch(url)
.then(res => {
if (res.ok) {
// TODO: return generated object | consumable
} else {
throw new Error(`invalid status: ${res.status}`);
}
})
.catch(err => {
throw new Error(`url error: ${err}`);
})
}

export const generateGet3DObject = ({model}) => async ({x} = {}) => {
const url = `${get3dUrl}/object?x=${x}` // mock endpoint
await fetch(url)
.then(res => {
if (res.ok) {
// TODO: return generated object
} else {
throw new Error(`invalid status: ${res.status}`);
}
})
.catch(err => {
throw new Error(`url error: ${err}`);
})
}

export const generateMusic = ({model}) => async ({x} = {}) => {
const url = `${musicGeneratorUrl}/music?x=${x}` // mock endpoint
await fetch(url)
.then(res => {
if (res.ok) {
// TODO: return generated music
} else {
throw new Error(`invalid status: ${res.status}`);
}
})
.catch(err => {
throw new Error(`url error: ${err}`);
})
}

export const generateWeaviateCharacter = ({model}) => async ({x} = {}) => {
const url = `${weaviateUrl}/character?x=${x}` // mock endpoint
await fetch(url)
.then(res => {
if (res.ok) {
// TODO: return generated character ??
} else {
throw new Error(`invalid status: ${res.status}`);
}
})
.catch(err => {
throw new Error(`url error: ${err}`);
})
}

export const generateSprite = ({model}) => async ({x} = {}) => {
const url = `${discoDiffusionUrl}/sprite?x=${x}` // mock endpoint
await fetch(url)
.then(res => {
if (res.ok) {
// TODO: return generated sprite
} else {
throw new Error(`invalid status: ${res.status}`);
}
})
.catch(err => {
throw new Error(`url error: ${err}`);
})
}
Loading