A FastAPI-based English correction service designed for Korean speakers preparing for English interviews. This service utilizes Large Language Models to analyze and improve English expressions, making them more natural and professional.
Langquence API is part of a larger system designed to help Korean speakers improve their English interview skills. The system consists of multiple layers:
- Data Collection Layer: Collects English interview data from sources like YouTube
- Data Processing Layer: Processes the collected data including speech-to-text conversion
- Model Learning Layer: Trains NLP models using the processed data
- Realtime Processing Layer (this project): Provides real-time English correction via API
- Presentation Layer: User interfaces for interacting with the service
This repository implements the Realtime Processing Layer as a FastAPI application.
The application follows a modular architecture with clear separation of concerns:
langquence-was/
βββ app/
β βββ main.py # FastAPI application entry point
β βββ api/ # API routes
β βββ config/ # Configuration management
β βββ consts/
β βββ clients/ # External service clients
β βββ services/ # Business logic
β βββ dto/
β βββ utils/
βββ .env # Environment variables
βββ requirements.txt # Dependencies
- API Layer: Handles HTTP requests and responses
- Correction Service: Orchestrates the correction process
- Qwen Client: Interacts with Alibaba Cloud's Qwen LLM API
- Pattern Matching Engine: Validates and enhances LLM responses
- Feedback Generator: Creates user-friendly feedback from corrections
- Python 3.8+
- An Alibaba Cloud account with access to DashScope API
- Clone the repository:
git clone https://github.com/your-username/langquence-was.git
cd langquence-was- Create and activate a virtual environment:
python -m venv venv
# Windows
venv\Scripts\activate
# Mac/Linux
source venv/bin/activate- Install dependencies:
pip install -r requirements.txt- Create a
.envfile in the project root with the following contents:
APP_NAME=Langquence API
APP_EXECUTE_COMMAND=app.main:app
APP_HOST=127.0.0.1
APP_PORT=8000
APP_RELOAD=True
API_PREFIX=/api
DEBUG=True
LOG_LEVEL=INFO
ALIBABA_API_KEY=your_api_key_here
MODEL_NAME=qwen-plus
MAX_TOKENS=512
Run the application using Uvicorn:
uvicorn app.main:app --reloadOr use the provided entry point:
python -m app.mainThe API will be available at: http://localhost:8000
Corrects English text for interview settings.
Endpoint: POST /api/correct
Request:
{
"text": "I have work in this company for 5 years."
}Response:
{
"original": "I have work in this company for 5 years.",
"needs_correction": true,
"corrected": "I have worked in this company for 5 years.",
"explanation": "Changed 'work' to 'worked' to use present perfect tense correctly for an action that started in the past and continues to the present.",
"alternatives": ["I have been working in this company for 5 years."]
}The Pattern Matching Engine validates and enhances the LLM's corrections by:
- Checking if the LLM identified errors correctly
- Comparing against known error patterns
- Providing additional validation for the corrections
- Suggesting alternative expressions when appropriate
The application uses a carefully designed prompting strategy that:
- Provides clear instructions to the LLM
- Specifies the expected response format
- Includes examples of common errors and corrections
- Guides the model to produce consistent, high-quality responses
To add new features to the application:
- Implement traffic rate limitation
- Enhance security policies
- Optimize prompt token usage
- Refactoring the Architecture
- Connecting to the DB for saving requests
To run tests:
pytest