Skip to content

jxiaof/agent-proj

Repository files navigation

Document Q&A System

AI-based intelligent document question answering system built with FastAPI, supporting multiple document formats and AI providers.

Features

  • Document Management: Upload, parse, and store documents (TXT, Markdown, PDF, DOCX)
  • Intelligent Q&A: RAG-based question answering using semantic search
  • Multi-turn Conversations: Context-aware chat with conversation history
  • Multiple AI Providers: Support for OpenAI, Anthropic (Claude), and local models
  • Vector Search: ChromaDB for efficient document chunk retrieval

Tech Stack

  • Backend: FastAPI, Async SQLAlchemy, Pydantic v2
  • Database: PostgreSQL, Redis
  • Vector Store: ChromaDB
  • AI: OpenAI, Anthropic, Sentence Transformers
  • Document Parsing: pypdf, python-docx, markdown

Quick Start

Prerequisites

  • Python 3.11+
  • Docker and Docker Compose
  • OpenAI or Anthropic API key

1. Clone and Setup

cd python-proj

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
make dev

2. Configure Environment

cp .env.example .env
# Edit .env with your settings (especially API keys)

3. Start Services

# Start PostgreSQL and Redis
make docker-up

# Run database migrations
make migrate

4. Run the Application

make run

The API will be available at http://localhost:8000

API Endpoints

Documents

Method Endpoint Description
POST /api/v1/documents Upload a document
GET /api/v1/documents List all documents
GET /api/v1/documents/{id} Get document details
DELETE /api/v1/documents/{id} Delete a document

Q&A

Method Endpoint Description
POST /api/v1/qa/ask Ask a question

Conversations

Method Endpoint Description
POST /api/v1/conversations Create a conversation
GET /api/v1/conversations List conversations
GET /api/v1/conversations/{id} Get conversation details
PUT /api/v1/conversations/{id} Update a conversation
DELETE /api/v1/conversations/{id} Delete a conversation
POST /api/v1/conversations/{id}/messages Send a message

AI Settings

Method Endpoint Description
GET /api/v1/settings/ai-providers List AI providers
POST /api/v1/settings/ai-providers Add AI provider
PUT /api/v1/settings/ai-providers/{id} Update AI provider
DELETE /api/v1/settings/ai-providers/{id} Delete AI provider
POST /api/v1/settings/ai-providers/{id}/test Test AI connection

Usage Examples

Upload a Document

curl -X POST "http://localhost:8000/api/v1/documents" \
  -F "file=@document.pdf" \
  -F "title=My Document"

Ask a Question

curl -X POST "http://localhost:8000/api/v1/qa/ask" \
  -H "Content-Type: application/json" \
  -d '{"question": "What is the main topic of the document?"}'

Create a Conversation

curl -X POST "http://localhost:8000/api/v1/conversations" \
  -H "Content-Type: application/json" \
  -d '{"title": "My Chat", "document_ids": ["doc-uuid-here"]}'

Send a Message

curl -X POST "http://localhost:8000/api/v1/conversations/{id}/messages" \
  -H "Content-Type: application/json" \
  -d '{"message": "Tell me more about section 2"}'

Project Structure

python-proj/
├── app/
│   ├── api/routers/     # API route handlers
│   ├── services/        # Business logic
│   ├── daos/            # Data access layer
│   ├── models/          # SQLAlchemy models
│   ├── schemas/         # Pydantic schemas
│   ├── core/            # Config, exceptions, middleware
│   └── infra/           # Database, Redis, Vector store
├── migrations/          # Alembic migrations
├── tests/               # Test suite
├── docker/              # Docker configuration
└── docs/                # Documentation

Development

# Run tests
make test

# Run linters
make lint

# Format code
make format

# Create a migration
make migration msg="add new table"

Docker Deployment

# Build the image
make docker-build

# Run with Docker Compose
make docker-run

Configuration

Key environment variables:

Variable Description Default
ENV Environment (dev/test/prod) dev
DB_HOST PostgreSQL host localhost
REDIS_HOST Redis host localhost
OPENAI_API_KEY OpenAI API key -
ANTHROPIC_API_KEY Anthropic API key -
DEFAULT_AI_PROVIDER Default AI provider openai

See .env.example for all options.

License

MIT

About

a agent project with

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages