Spaces:
Sleeping
Sleeping
File size: 2,844 Bytes
b46ff5d | 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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | import axios from 'axios';
const API_BASE_URL = import.meta.env.VITE_API_URL || "http://localhost:8080";
const api = axios.create({
baseURL: API_BASE_URL,
headers: {
'Content-Type': 'application/json',
},
});
export const healthCheck = async () => {
try {
const res = await api.get('/');
return res.data;
} catch (error) {
console.error("Health check failed:", error);
return null;
}
};
// ์ ์ฒด ๋ ์ํผ ๋ชฉ๋ก ์กฐํ (ํ์ด์ง๋ค์ด์
)
export const listRecipes = async (limit = 50, offset = 0) => {
try {
const res = await api.get('/recipes', { params: { limit, offset } });
return res.data;
} catch (error) {
console.error("List recipes failed:", error);
return { total: 0, recipes: [] };
}
};
export const searchRecipes = async (query) => {
try {
const res = await api.get('/recipes/search', { params: { q: query } });
return res.data;
} catch (error) {
console.error("Recipe search failed:", error);
return [];
}
};
export const getRecipeDetail = async (id) => {
try {
const res = await api.get(`/recipes/${id}`);
return res.data;
} catch (error) {
console.error("Get recipe detail failed:", error);
return null;
}
};
// ๋จ์ผ ์ฌ๋ฃ ๋์ฒด ์ถ์ฒ
export const recommendDbSingle = async (recipeId, target, w2v = 0.5, d2v = 0.5, method = 0.0, cat = 0.0) => {
try {
const res = await api.post('/recommend/db/single', {
recipe_id: recipeId,
target: [target],
stopwords: [],
w_w2v: w2v,
w_d2v: d2v,
w_method: method,
w_cat: cat
});
return res.data;
} catch (error) {
console.error("DB Single Rec failed:", error);
return [];
}
};
// ๋ค์ค ์ฌ๋ฃ ๋์ฒด ์ถ์ฒ
export const recommendDbMulti = async (recipeId, targets, w2v = 0.5, d2v = 0.5, method = 0.0, cat = 0.0) => {
try {
const res = await api.post('/recommend/db/multi', {
recipe_id: recipeId,
target: targets,
stopwords: [],
w_w2v: w2v,
w_d2v: d2v,
w_method: method,
w_cat: cat
});
return res.data;
} catch (error) {
console.error("DB Multi Rec failed:", error);
return [];
}
};
// Custom recommendation (์ฌ์ฉ์ ์ ์ ์ฌ๋ฃ)
export const recommendCustomSingle = async (target, contextIngs) => {
try {
const res = await api.post('/recommend/custom/single', {
context_ings: contextIngs,
target: [target],
stopwords: [],
excluded: []
});
return res.data;
} catch (error) {
return [];
}
};
export default api;
|