A step-by-step guide to creating a powerful, AI-driven web application that leverages GPT models and Perplexity API to provide real-time, multi-source research results. This project demonstrates how to integrate advanced AI models with a scalable backend using FastAPI.
- Real-Time Research: Get instant answers to user queries with dynamic updates.
- Multi-Source Integration: Combines GPT and Perplexity API for comprehensive results.
- Related Questions Generator: Automatically generates follow-up questions for deeper insights.
- User-Friendly Interface: Intuitive frontend with search history and downloadable results.
- Scalable Architecture: Asynchronous processing with WebSockets for real-time communication.
git clone https://github.com/Moe230391/research-assistant.git
cd research-assistant
pip install -r requirements.txt
Create a .env
file in the root directory:
OPENAI_API_KEY=your_openai_api_key
PERPLEXITY_API_KEY=your_perplexity_api_key
Start the FastAPI server:
uvicorn app:app --reload
Open the app in your browser at http://127.0.0.1:8000
.
├── app.py # Main entry point for the application
├── config.py # Configuration for environment variables
├── websocket_handler.py # Handles WebSocket connections
├── search_handler.py # AI-related logic (GPT and Perplexity integration)
├── models.py # Pydantic models for data validation
├── utils.py # Utility functions for timeouts and response formatting
├── static/ # Static files (HTML, CSS, JS)
│ ├── index.html # Frontend interface
│ ├── style.css # Styling for the app
│ └── script.js # Frontend JavaScript logic
├── tests/ # Test files for validating app functionality
│ ├── test.txt # Sample input queries
├── .env # Environment variables (ignored in version control)
├── requirements.txt # List of dependencies
└── README.md # Project documentation
- FastAPI: Backend framework for building APIs and WebSocket support.
- WebSockets: Real-time updates for research results.
- GPT Models (OpenAI): Generative AI for related question generation and synthesis.
- Perplexity API: Multi-source search for robust answers.
- Python Libraries: asyncio, Pydantic, Termcolor.
- Frontend: HTML, CSS, JavaScript.
-
User Query:
- User enters a query in the search bar.
- WebSocket sends the query to the backend.
-
Backend Processing:
- GPT generates related questions.
- Perplexity API fetches answers for related questions.
- Results are synthesized into a comprehensive final answer.
-
Real-Time Updates:
- WebSocket streams partial results as they are processed.
- Final synthesized answer is displayed when all results are ready.
Use test.txt
to validate the app with sample queries:
What will be the NVIDIA stock price at the end of 2024?
Explain quantum computing in simple terms.
Ensure the app:
- Generates accurate answers.
- Handles timeouts and errors gracefully.
- Provides a clear final synthesized response.
Contributions are welcome! To contribute:
- Fork the repository.
- Create a feature branch:
git checkout -b feature-name
. - Commit changes:
git commit -m "Add feature"
. - Push to the branch:
git push origin feature-name
. - Submit a pull request.
This project is licensed under the MIT License.
- Add user authentication for personalized research history.
- Integrate additional APIs for broader data coverage.
- Enhance frontend design with modern frameworks like React or Vue.js.