== Contributors ==
Vansh Saluja, Nandini Khokhani
== Overview ==
Frontend
This code is a React application that implements a chat interface powered by the OpenAI GPT 3.5 model. Here's a summary of its functionality:
-
State Management: The component uses useState to manage state variables such as input, posts, botTyping, and history.
-
Fetching Bot Response: The fetchBotResponse function sends a request to a backend API endpoint with user input and conversation history to retrieve a response from the OpenAI GPT model.
-
Speech Recognition: It utilizes the useSpeechRecognition hook from the react-speech-recognition library to enable speech-to-text functionality.
-
Effects: useEffect hooks are used for various purposes such as scrolling, updating input focus, and managing speech recognition.
-
Toast Notifications: Toast notifications are displayed using the react-toastify library for copying text confirmation.
Backend
This code is an Express.js server that serves as an interface for interacting with the OpenAI GPT (Generative Pre-trained Transformer) model. Here's a summary of what it does:
-
It imports necessary modules such as Express, CORS, dotenv for environment variables, and OpenAI SDK.
-
CORS (Cross-Origin Resource Sharing) middleware is used to allow cross-origin requests.
-
A POST endpoint ("/") is defined to handle incoming messages for conversation with the AI model.
i) It receives user input and conversation history from the request body.
ii) The server adds the user input to the conversation history.
iii) It then sends the conversation history to the OpenAI API for generating a response.
iv) The response from the AI model is added to the conversation history.
v) The server sends back the AI's response and updated conversation history to the client.
-
Another POST endpoint ("/test/:query") is defined for testing purposes which performs similarly to point no. 3 but is only for testing purposes using Postman.
Overall, this React application provides a user-friendly chat interface that allows users to interact with the OpenAI GPT model through text input or speech recognition and acts as a middleware between clients and the OpenAI GPT model, allowing clients to send messages and receive responses generated by the AI model.