async function runCompletion(messages: any) {
const response=await fetch(
“https://api.openai-proxy.com/v1/chat/completions”,
{
method: “POST”,
headers: {
“Content-Type”: “application/json”,
Authorization: “Bearer ” + process.env.OPENAI_API_KEY,
},
body: JSON.stringify({
model: “gpt-3.5-turbo”,
messages: [{ role: “user”, content: messages }],
}),
}
).then((res)=> res.json())
return await response.choices[0].message.content;
}
export async function loader({ request }: any) {
const url=new URL(request.url);
const text=url.searchParams.get(“text”)!;
return runCompletion(text);
}
const response=await fetch(
“https://api.openai-proxy.com/v1/chat/completions”,
{
method: “POST”,
headers: {
“Content-Type”: “application/json”,
Authorization: “Bearer ” + process.env.OPENAI_API_KEY,
},
body: JSON.stringify({
model: “gpt-3.5-turbo”,
messages: [{ role: “user”, content: messages }],
}),
}
).then((res)=> res.json())
return await response.choices[0].message.content;
}
export async function loader({ request }: any) {
const url=new URL(request.url);
const text=url.searchParams.get(“text”)!;
return runCompletion(text);
}
© 版权声明
文章版权归作者所有,未经允许请勿转载。