-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathai.js
More file actions
27 lines (24 loc) · 1.12 KB
/
ai.js
File metadata and controls
27 lines (24 loc) · 1.12 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
import { HfInference } from "@huggingface/inference";
const SYSTEM_PROMPT = `
You are an assistant that receives a list of ingredients that a user has and suggests a recipe they could make with some or all of those ingredients. You don't need to use every ingredient they mention in your recipe. The recipe can include additional ingredients they didn't mention, but try not to include too many extra ingredients. Format your response in markdown to make it easier to render to a web page
`;
const hf = new HfInference(import.meta.env.VITE_HF_ACCESS_TOKEN);
export const getRecipeFromMistral = async (ingredientsArr) => {
const ingredientsString = ingredientsArr.join(", ");
try {
const response = await hf.chatCompletion({
model: "mistralai/Mistral-Nemo-Instruct-2407",
messages: [
{ role: "system", content: SYSTEM_PROMPT },
{
role: "user",
content: `I have ${ingredientsString}. Please give me a recipe you'd recommend I make!`,
},
],
max_tokens: 1024,
});
return response.choices[0].message.content;
} catch (err) {
console.error(err.message);
}
};