feat: images playground
This commit is contained in:
1 parent
45d7486485
commit
94302de49b
4 files changed
+345
-1
No files matched your search
@@ -217,7 +217,63 @@ export const imageGenerations = async (token: string = '', prompt: string) => {
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
if ('detail' in err) {
|
||||
error = err.detail;
|
||||
if (Array.isArray(err.detail)) {
|
||||
error = err.detail.map((e: { msg?: string }) => e.msg || JSON.stringify(e)).join(', ');
|
||||
} else {
|
||||
error = err.detail;
|
||||
}
|
||||
} else {
|
||||
error = 'Server connection failed';
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
export const imageEdits = async (
|
||||
token: string = '',
|
||||
images: string | string[],
|
||||
prompt: string,
|
||||
model?: string,
|
||||
size?: string,
|
||||
n?: number
|
||||
) => {
|
||||
let error = null;
|
||||
|
||||
const res = await fetch(`${IMAGES_API_BASE_URL}/edit`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
...(token && { authorization: `Bearer ${token}` })
|
||||
},
|
||||
body: JSON.stringify({
|
||||
form_data: {
|
||||
image: images,
|
||||
prompt,
|
||||
...(model && { model }),
|
||||
...(size && { size }),
|
||||
...(n && { n })
|
||||
}
|
||||
})
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res.ok) throw await res.json();
|
||||
return res.json();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
if ('detail' in err) {
|
||||
if (Array.isArray(err.detail)) {
|
||||
error = err.detail.map((e: { msg?: string }) => e.msg || JSON.stringify(e)).join(', ');
|
||||
} else {
|
||||
error = err.detail;
|
||||
}
|
||||
} else {
|
||||
error = 'Server connection failed';
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user