-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.tsx
More file actions
37 lines (32 loc) · 1.62 KB
/
Copy pathutils.tsx
File metadata and controls
37 lines (32 loc) · 1.62 KB
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
export async function getItemCategory(item: string) {
if (!import.meta.env.VITE_OPENAI_API_KEY) {
throw new Error("Missing env var from OpenAI");
}
if (!item) {
throw new Error("Missing item");
}
const payload = {
model: "gpt-3.5-turbo-0613",
temperature: 0,
messages: [
{
role: "system",
content:
'You are to act as categorisation system. You will be given an item and you must categorise it into one of the following categories: "Fruits and vegetables", "Dairy and eggs", "Meat and poultry", "Fish and seafood", "Grains, pasta, and rice", "Breads and bakery", "Canned and jarred goods", "Frozen foods", "Snacks and sweets", "Condiments and sauces", "Spices and seasonings", "Beverages", "Breakfast items", "Deli and prepared foods", "Cooking oils and fats", "Baking supplies", "Health foods and supplements", "Baby and toddler products", "Pet food and supplies", "Household and cleaning products", "Personal care items", "Office supplies", "Other". Only ever use the categories listed above, in the format listed above. Never respond with a category that is not listed above. If you are unsure, respond with simply: "Other".',
},
{ role: "user", content: item },
],
};
const res = await fetch("https://api.openai.com/v1/chat/completions", {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${import.meta.env.VITE_OPENAI_API_KEY ?? ""}`,
},
method: "POST",
body: JSON.stringify(payload),
});
const data = res.body;
return new Response(data, {
headers: { "Content-Type": "application/json; charset=utf-8" },
});
}