Spaces:
Running
Running
File size: 954 Bytes
13c9aca |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import { error, json, type RequestEvent } from '@sveltejs/kit';
import { env } from '$env/dynamic/private'
/** @type {import('./$types').RequestHandler} */
export async function POST({ request }: RequestEvent) {
const body = await request?.json().catch(() => {});
if (!body?.model) {
throw error(400, 'missing model value')
}
if (!body?.inputs || body.inputs === null) {
throw error(400, 'missing inputs value')
}
const response = await fetch(env.SECRET_INFERENCE_API_URL + "/models/" + body.model, {
method: "POST",
headers: {
Authorization: `Bearer ${env.SECRET_HF_TOKEN}`,
'Content-Type': 'application/json',
['x-use-cache']: "0"
},
body: JSON.stringify(body),
})
.then((res) => res.json())
.then((res) => res)
.catch((error) => {
return {
error: error.message,
}
})
if ("error" in response) {
error(400, response.error as string)
}
return json(response)
}
|