This project is a FastAPI-based service designed to help users prepare for IELTS writing tasks. The system combines a CSV knowledge base, a PostgreSQL-backed vector database, and OpenAI GPT to provide personalized guidance, example essays, and feedback on writing.
- Knowledge Base Integration: Uses a CSV knowledge base of sample IELTS writing essays, managed with a PostgreSQL-backed vector database (
PgVector
). - Embedding Models: Employs OpenAI embeddings for efficient vector representation of essay data.
- Agent Functionality: A custom agent, "IELTS Writing Tutor," interacts with users, retrieves relevant essay examples, and provides tailored feedback and suggestions.
- API Endpoint: Accepts user queries via a
/query
endpoint and responds in JSON format. - Guided Writing Assistance: Offers suggestions for writing styles, scores, and improvements, inspired by existing examples.
- FastAPI: Framework for creating the REST API.
- PgVector: PostgreSQL extension for vector similarity searches.
- Phi Framework: Facilitates the creation of the custom agent and integration of knowledge bases.
- LangChain: Manages knowledge base and embeddings.
- OpenAI GPT: Utilizes the
gpt-4o-mini
model for natural language processing. - Python Dotenv: For managing environment variables.
.
├── app.py # Main API and agent implementation
├── sample_data/ # Directory containing sample IELTS writing essays
├── requirements.txt # Python dependencies
├── .env # Environment variables (e.g., OpenAI API key)
-
Clone the repository:
git clone https://github.com/your-repo/ielts-writing-tutor-api.git cd ielts-writing-tutor-api
-
Set up a Python virtual environment:
python3 -m venv venv source venv/bin/activate # For Linux/macOS venv\Scripts\activate # For Windows
-
Install dependencies:
pip install -r requirements.txt
-
Configure Environment Variables: Create a
.env
file in the project root with your OpenAI API key:OPENAI_API_KEY=your_openai_api_key
-
Run the FastAPI server:
uvicorn app:app --host 0.0.0.0 --port 8000
-
Query the Agent: Interact with the agent using the
/query
endpoint:- Request Format:
{ "query": "Provide examples of band 7 essays on environmental topics." }
- Response Format:
{ "response": "Here is an example of a band 7 essay on environmental protection: ..." }
- Request Format:
-
Customize Data: Add or update IELTS writing examples in the
sample_data/
directory. Ensure the file is a properly formatted CSV.
- Knowledge Base Path: Update the path in
CSVKnowledgeBase
to point to your custom dataset. - Database Configuration: Modify database connection details (e.g., table name, database URL) as required.
- Model and Embeddings: Adjust the
OpenAIChat
andOpenAIEmbeddings
configurations if using alternative models or embeddings.
faiss
fastapi
phi
langchain_openai
uvicorn
python-dotenv
Install all dependencies with:
pip install -r requirements.txt
- Ensure the PostgreSQL database with
PgVector
is set up and accessible. - Use the agent's built-in instructions to customize user interactions further.
- This project is extensible for additional features, such as support for other writing tasks or exam formats.