Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Used consistent structure for sending request (like used everywhere else in the client) #115

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion client/src/actions/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ export const FETCH_PROFILES_BY_USER = 'FETCH_PROFILES_BY_USER';

export const LIST_MEETINGS = 'LIST_MEETINGS';
export const GET_MEETING = 'GET_MEETING';
export const SCHEDULE_MEETING = 'SCHEDULE_MEETING';
export const SCHEDULE_MEETING = 'SCHEDULE_MEETING';

export const PROCESS_AUDIO = 'PROCESS_AUDIO';
16 changes: 16 additions & 0 deletions client/src/actions/modelCommunication.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as api from "../api/index.js";
import { PROCESS_AUDIO } from "./constants";

export const processCandidateAnswer = (audioBase64) => async (dispatch) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will not work as expected.
some references - https://www.npmjs.com/package/react-media-recorder

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested it locally with my own django server. The audio data is reaching the server. Please elaborate if this is not what you are talking about.

try {
const audioJson = {
audioBase64: audioBase64,
};
const { data } = await api.processCandidateAnswer(audioJson);
dispatch({ type: PROCESS_AUDIO, payload: data });
return data;
} catch (error) {
console.log(error);
return error;
}
};
5 changes: 4 additions & 1 deletion client/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ if (NODE_ENV === 'development') {
}
export const baseURL = url;
const API = axios.create({ baseURL: baseURL})
const AI_API = axios.create({ baseURL: process.env.AI_API })


API.interceptors.request.use((req) => {
Expand Down Expand Up @@ -56,4 +57,6 @@ export const getInterviewsHR = (id) => API.get(`/interviews/hr/${id}`);
export const listMeetings = () => API.get('/meetings');
export const getMeeting = (id) => API.get(`/meetings/${id}`);
// export const scheduleMeeting = (meetingData) => API.post('/schedule', meetingData);
export const scheduleMeeting = (formData) => API.post(`/interviews/schedule`, formData);
export const scheduleMeeting = (formData) => API.post(`/interviews/schedule`, formData);

export const processCandidateAnswer = (audioJson) => AI_API.post('/process/', audioJson);
26 changes: 6 additions & 20 deletions client/src/components/Interview/Interview.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import { Link } from "react-router-dom";
import styles from "./Interview.module.css";
import { useLocation } from "react-router-dom";
import { questions, introduction } from "./FirstQuestions";
import { processCandidateAnswer } from "../../actions/modelCommunication";
import { useDispatch } from "react-redux";

const Interview = () => {
const dispatch = useDispatch();
const location = useLocation();
const candidateName = location?.state?.participantNameFromDB;
const endTime = location?.state?.endTimeFromDB;
Expand Down Expand Up @@ -138,26 +141,9 @@ const Interview = () => {
};
};

const sendAudioAndGetNextQuestion = (audioBase64) => {
const sendAudioAndGetNextQuestion = async (audioBase64) => {
// TODO: Test with django server
const url = process.env.AI_APP_API || "http://127.0.0.1:8000"; // Replace with your server endpoint
const apiUrl = url + "/process";
const requestBody = { audioBase64 };

fetch(apiUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(requestBody),
})
.then((response) => response.json())
.then((data) => {
startRecording();
})
.catch((error) => {
console.error("Error:", error);
});
let response = await dispatch(processCandidateAnswer(audioBase64));
// TODO: Change it to the question from response
let str = generateString(10);
displayAndReadQuestion(str);
Expand Down Expand Up @@ -189,7 +175,7 @@ const Interview = () => {
resolve();
};
});
}
};

const displayAndReadQuestion = async (question) => {
document.getElementById("question").innerHTML = question;
Expand Down
Loading