Spaces:
Running
Running
File size: 1,824 Bytes
cdb73a8 | 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 | import axios from 'axios';
import type { RecommendationResult, Book, BookCluster } from './types';
const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:8000';
export const api = {
getClusters: async (): Promise<BookCluster[]> => {
const response = await axios.get<BookCluster[]>(`${API_URL}/clusters`);
return response.data;
},
recommendByQuery: async (query: string): Promise<RecommendationResult[]> => {
const response = await axios.post<RecommendationResult[]>(`${API_URL}/recommend/query`, {
query,
top_k: 12,
});
return response.data;
},
searchBooks: async (query: string): Promise<{ books: Book[] }> => {
const response = await axios.get(`${API_URL}/books/search`, {
params: { query, page: 1, page_size: 20 },
});
return response.data;
},
submitFeedback: async (query: string, bookId: string, type: 'positive' | 'negative') => {
await axios.post(`${API_URL}/feedback`, {
query,
book_id: bookId,
feedback_type: type,
});
},
explainRecommendation: async (query: string, book: Book, score: number) => {
const response = await axios.post(`${API_URL}/explain`, {
query_text: query,
recommended_book: book,
similarity_score: score
});
return response.data;
},
getRelatedBooks: async (title: string): Promise<RecommendationResult[]> => {
const response = await axios.post<RecommendationResult[]>(`${API_URL}/recommend/title`, {
title,
top_k: 6,
});
return response.data;
},
recommendPersonalized: async (history: string[]): Promise<RecommendationResult[]> => {
const response = await axios.post<RecommendationResult[]>(`${API_URL}/recommend/personalize`, {
user_history: history,
top_k: 12,
});
return response.data;
}
};
|