File size: 4,810 Bytes
c01955c
 
0e17177
c01955c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import axios from 'axios';

const PYTHON_BASE_URL = import.meta.env.VITE_PYTHON_BASE_URL || 'http://localhost:8000';

const pythonApiInstance = axios.create({
    baseURL: PYTHON_BASE_URL,
    headers: {
        'Content-Type': 'application/json',
    },
});

class PythonApi {
    // ── User ──────────────────────────────────────────────────────────────
    /** Generate an interview-ready schema from plain-text user details */
    async createSchema(userDetails: string) {
        const response = await pythonApiInstance.post('/api/user/generate_schema', {
            userDetails,
        });
        return response.data;
    }

    /** Upload a resume PDF and get back a parsed "about user" text blob */
    async uploadResume(file: File) {
        const formData = new FormData();
        formData.append('file', file);
        const response = await pythonApiInstance.post('/api/user/aboutUserByResume', formData, {
            headers: { 'Content-Type': 'multipart/form-data' },
        });
        return response.data;
    }

    // ── Interview ─────────────────────────────────────────────────────────
    /** Generate N interview schemas for given fields / companies */
    async generateInterviewSchemas(
        noOfInterviews: number = 3,
        fields: string[] = ['AI/ML', 'Backend', 'Data Science'],
        companiesName: string[] = ['Google', 'Amazon', 'Microsoft'],
        updated: boolean = false,
    ) {
        const params = new URLSearchParams();
        params.append('no_of_interviews', noOfInterviews.toString());
        params.append('updated', updated.toString());
        fields.forEach((f) => params.append('fields', f));
        companiesName.forEach((c) => params.append('companiesName', c));

        const response = await pythonApiInstance.post(
            `/api/interview/generate_interview_schemas?${params.toString()}`,
        );
        return response.data;
    }

    /** Send a single chat turn to the AI interviewer */
    async chatInterviewer(
        threadId: string,
        timeRemain: number,
        topic: string,
        userInput: string,
    ) {
        const response = await pythonApiInstance.post('/api/interview/chat_interviewer', null, {
            params: {
                thread_id: threadId,
                time_remain: timeRemain,
                topic,
                user_input: userInput,
            },
        });
        return response.data;
    }

    // ── Performance ───────────────────────────────────────────────────────
    /** Fetch AI-evaluated performance report for a given thread */
    async getPerformance(threadId: string) {
        const response = await pythonApiInstance.get(`/api/performance/performance/${threadId}`);
        return response.data;
    }

    // ── Thread ────────────────────────────────────────────────────────────
    /** Delete a thread conversation from the SQLite checkpointer */
    async deleteThread(threadId: string) {
        const response = await pythonApiInstance.delete(`/api/thread/${threadId}`);
        return response.data;
    }

    // ── Health ────────────────────────────────────────────────────────────
    async health() {
        const response = await pythonApiInstance.get('/api/health/health');
        return response.data;
    }

    // ── Live Job Fetcher ──────────────────────────────────────────────────
    /** Fetch real-time jobs from indeed / internet */
    async fetchJobs(jobtile: string = "machine learning intern", updated: boolean = false) {
        const response = await pythonApiInstance.post(`/api/jobFetcher/fetchJobs?jobtile=${encodeURIComponent(jobtile)}&updated=${updated}`);
        return response.data;
    }

    async similarJobPredictor(jobDiscription:string,userDetails:string){
        const response = await pythonApiInstance.post(`/api/similarJobPredictor/similarJobPredictor?jobDiscription=${encodeURIComponent(jobDiscription)}&userDetails=${encodeURIComponent(userDetails)}`);
        console.log("Similar Job Predictor",response.data);
        return response.data;
    }
}

export default new PythonApi();