correct friendli api usage
This commit is contained in:
@@ -1,17 +1,49 @@
|
|||||||
export async function POST(req) {
|
export async function POST(req) {
|
||||||
try {
|
try {
|
||||||
|
const token = process.env.FRIENDLI_TOKEN;
|
||||||
const body = await req.json();
|
const body = await req.json();
|
||||||
const { query } = body;
|
const { query } = body;
|
||||||
|
|
||||||
const response = await fetch("https://api.friendli.ai/dedicated", {
|
const headers = {
|
||||||
method: "POST",
|
Authorization: "Bearer " + token,
|
||||||
headers: {
|
"Content-Type": "application/json",
|
||||||
"Content-Type": "application/json",
|
};
|
||||||
"Authorization": `Bearer ${process.env.FRIENDLI_TOKEN}`,
|
|
||||||
"X-Friendli-Team": process.env.TEAM_ID,
|
const requestBody = {
|
||||||
|
model: "meta-llama-3.3-70b-instruct",
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
role: "system",
|
||||||
|
content:
|
||||||
|
"You\u0027re an assistant for possibly elderly or ill patients. Give responses to medical questions in a brief, understandable, and kind way.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: "user",
|
||||||
|
content: query,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
tools: [],
|
||||||
|
min_tokens: 0,
|
||||||
|
max_tokens: 2048,
|
||||||
|
temperature: 1,
|
||||||
|
top_p: 0.8,
|
||||||
|
frequency_penalty: 0,
|
||||||
|
stop: [],
|
||||||
|
response_format: null,
|
||||||
|
stream: false,
|
||||||
|
stream_options: {
|
||||||
|
include_usage: false,
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ id: "idv6w0upi158", query }),
|
};
|
||||||
});
|
|
||||||
|
const response = await fetch(
|
||||||
|
"https://api.friendli.ai/serverless/v1/chat/completions",
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body: JSON.stringify(requestBody),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const errorDetails = await response.text();
|
const errorDetails = await response.text();
|
||||||
@@ -22,8 +54,8 @@ export async function POST(req) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.text();
|
||||||
return new Response(JSON.stringify({ answer: data.answer }), { status: 200 });
|
return new Response(JSON.stringify({ answer: data }), { status: 200 });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Backend error:", error);
|
console.error("Backend error:", error);
|
||||||
return new Response(
|
return new Response(
|
||||||
|
|||||||
Reference in New Issue
Block a user