This is a Flask-based frontend application designed to serve static files and provide various API endpoints for integration with OpenAI's ChatGPT, Groq's API, and a custom Knowledge Graph (KG) API. The application runs on port 8001 and integrates seamlessly with a backend environment.
- Serves static files including
index.html, CSS, and JS from thestaticfolder. - Provides multiple API endpoints:
/chatgpt: Interacts with OpenAI's ChatGPT API./groq: Integrates with Groq's Llama3 API for generating responses./kg-graph: Returns a simulated Knowledge Graph response./custom-response: Provides a simulated custom response for testing.
-
Conda Environment: Ensure you are using the same Conda environment as the backend for consistency. Activate the environment using:
conda activate <backend_environment_name>
Replace
<backend_environment_name>with the name of your backend environment. -
Python Dependencies: Install the required dependencies in the activated environment:
pip install flask openai groq
-
API Keys:
- Set up your OpenAI API key: Replace
<open_ai_key>in the code with your actual OpenAI API key. - Set up your Groq API key: Replace
<groq_key>in the code with your actual Groq API key.
- Set up your OpenAI API key: Replace
-
Navigate to the Application Directory: Ensure you are in the directory containing the
app.pyfile. -
Run the Flask App: Start the application by running:
python app.py
-
Access the Application: Open a browser and navigate to:
http://127.0.0.1:8001The app serves the
index.htmlfile and provides access to the APIs.
- URL:
/chatgpt - Method:
POST - Payload:
{ "question": "<Your question here>" } - Response:
{ "response": "<ChatGPT's response>" }
- URL:
/groq - Method:
POST - Payload:
{ "question": "<Your question here>" } - Response:
{ "response": "<Groq's response>" }
- URL:
/kg-graph - Method:
GET - Response:
{ "kg_graph_text": "This is the simulated KG Graph output." }
- URL:
/custom-response - Method:
POST - Payload:
{ "question": "<Your question here>" } - Response:
{ "response": "Response: <Your question>. This is a simulated custom response..." }
- Debugging: The app runs in debug mode by default. If deploying to production, set
debug=False. - Static Folder: Place your static files (e.g., HTML, CSS, JS) in the
staticfolder. - Port: The app runs on port
8001. Update theapp.runcall inapp.pyif you need to use a different port.