diff --git a/src/lib/apis/images/index.ts b/src/lib/apis/images/index.ts index a58d16085f..86b8a90ed1 100644 --- a/src/lib/apis/images/index.ts +++ b/src/lib/apis/images/index.ts @@ -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'; } diff --git a/src/lib/components/playground/Images.svelte b/src/lib/components/playground/Images.svelte new file mode 100644 index 0000000000..e128bc5bac --- /dev/null +++ b/src/lib/components/playground/Images.svelte @@ -0,0 +1,276 @@ + + +
+
+
+ + + + +
+
+ + {#if sourceImages.length > 0} +
+ {#each sourceImages as image, index} +
+
+ +
+
+ +
+
+ {/each} +
+ {/if} + + +
+