Spaces:
Running on Zero
Running on Zero
File size: 917 Bytes
f30eaab | 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 | export default {
async fetch(request, env) {
const corsHeaders = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type"
};
if (request.method === "OPTIONS") {
return new Response(null, { headers: corsHeaders });
}
if (request.method !== "POST") {
return new Response("OK", { status: 200, headers: corsHeaders });
}
const body = await request.json();
const resp = await fetch("https://api.siliconflow.cn/v1/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${env.SILICONFLOW_API_KEY}`
},
body: JSON.stringify(body)
});
return new Response(resp.body, {
status: resp.status,
headers: { ...corsHeaders, "Content-Type": "application/json" }
});
}
};
|