/* eslint-disable no-use-before-define */ import { DocumentType } from '../../documents/DocumentTypes'; export interface IDocRequest { id: string; title: string; text: string; type: string; } export const fetchRecommendations = async (src: string, query: string, docs?: IDocRequest[], dummy?: boolean) => { console.log('[rec] making request'); if (dummy) { return { recommendations: [], // dummyRecs, keywords: dummyKeywords, num_recommendations: 4, max_x: 100, max_y: 100, min_x: 0, min_y: 0, }; } const response = await fetch('http://127.0.0.1:8000/recommend', { method: 'POST', headers: { Accept: 'application/json', 'Content-Type': 'application/json', }, body: JSON.stringify({ src: src, query: query, docs: docs, }), }); const data = await response.json(); return data; }; export const fetchKeywords = async (text: string, n: number, dummy?: boolean) => { console.log('[fetchKeywords]'); if (dummy) { return { keywords: dummyKeywords, }; } const response = await fetch('http://127.0.0.1:8000/keywords', { method: 'POST', headers: { Accept: 'application/json', 'Content-Type': 'application/json', }, body: JSON.stringify({ text: text, n: n, }), }); const data = await response.json(); return data; }; export const getType = (type: DocumentType | string) => { switch (type) { case DocumentType.AUDIO: return 'Audio'; case DocumentType.VID: return 'Video'; case DocumentType.PDF: return 'PDF'; case DocumentType.WEB: return 'Webpage'; case 'YouTube': return 'Video'; case 'HTML': return 'Webpage'; default: return 'Unknown: ' + type; } }; /* const dummyRecs = { a: { title: 'Vannevar Bush - American Engineer', previewUrl: 'https://cdn.britannica.com/98/23598-004-1E6A382E/Vannevar-Bush-Differential-Analyzer-1935.jpg', type: 'web', distance: 2.3, source: 'www.britannica.com', related_concepts: ['vannevar bush', 'knowledge'], embedding: { x: 0, y: 0, }, }, b: { title: "From Memex to hypertext: Vannevar Bush and the mind's machine", type: 'pdf', distance: 5.4, source: 'Google Scholar', related_concepts: ['memex', 'vannevar bush', 'hypertext'], }, c: { title: 'How the hyperlink changed everything | Small Thing Big Idea, a TED series', previewUrl: 'https://pi.tedcdn.com/r/talkstar-photos.s3.amazonaws.com/uploads/b17d043f-2642-4117-a913-52204505513f/MargaretGouldStewart_2018V-embed.jpg?u%5Br%5D=2&u%5Bs%5D=0.5&u%5Ba%5D=0.8&u%5Bt%5D=0.03&quality=82w=640', type: 'youtube', distance: 5.3, source: 'www.youtube.com', related_concepts: ['User Control', 'Explanations'], }, d: { title: 'Recommender Systems: Behind the Scenes of Machine Learning-Based Personalization', previewUrl: 'https://sloanreview.mit.edu/wp-content/uploads/2018/10/MAG-Ransbotham-Ratings-Recommendations-1200X627-1200x627.jpg', type: 'pdf', distance: 9.3, source: 'www.altexsoft.com', related_concepts: ['User Control', 'Explanations'], }, }; */ const dummyKeywords = ['user control', 'vannevar bush', 'hypermedia', 'hypertext'];