Watch
1
0
Fork
You've already forked bericht-backend
0
mirror of https://github.com/DCC-BS/bericht-backend.git synced 2026-08-17 12:55:14 +00:00
  • JavaScript 98.9%
  • Python 0.8%
  • HTML 0.1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-06-11 14:22:40 +02:00
.devcontainer Update mcr.microsoft.com/devcontainers/python Docker tag to v2 2025-09-06 23:38:43 +00:00
.github Update astral-sh/setup-uv action to v7 2025-10-08 06:10:54 +00:00
.vscode first commit 2025-03-18 10:36:58 +01:00
docs Implement logs API endpoint and in-memory logging handler 2025-06-03 13:36:28 +02:00
src/bericht_backend Enhance logging and configuration: add file name fallback in send_mail, improve log entry handling, and update dotenv loading 2025-06-04 12:01:46 +02:00
static/swaggerui added swagger ui 2025-04-30 16:47:10 +02:00
.env.example Update environment variables in .env.example and docker-compose.yml for consistency 2025-06-02 10:46:08 +02:00
.gitignore first commit 2025-03-18 10:36:58 +01:00
.pre-commit-config.yaml first commit 2025-03-18 10:36:58 +01:00
.python-version first commit 2025-03-18 10:36:58 +01:00
codecov.yaml first commit 2025-03-18 10:36:58 +01:00
docker-compose.yml Update vllm/vllm-openai Docker tag to v0.17.1 (#21) 2026-03-25 15:20:34 +01:00
Dockerfile Remove unnecessary Streamlit installation from Dockerfile 2025-03-19 17:48:18 +01:00
Dockerfile.LLM Update vllm/vllm-openai Docker tag to v0.17.1 (#21) 2026-03-25 15:20:34 +01:00
LICENSE first commit 2025-03-18 10:36:58 +01:00
Makefile first commit 2025-03-18 10:36:58 +01:00
mkdocs.yml Implement logs API endpoint and in-memory logging handler 2025-06-03 13:36:28 +02:00
publiccode.yml Add organisation URI to publiccode.yml 2026-06-11 14:22:40 +02:00
pyproject.toml Update dependency openai to v2 2025-10-06 18:28:59 +00:00
README.md Update README.md 2025-08-06 16:38:03 +02:00
renovate.json Enable lock file maintenance in renovate.json 2025-12-02 16:14:42 +01:00
run.sh Add run script and email sending functionality 2025-04-29 12:15:34 +02:00
tox.ini first commit 2025-03-18 10:36:58 +01:00
uv.lock Update dependency openai to v1.108.1 2025-09-22 09:21:30 +00:00

Bericht Generator (Backend)

Bericht Generator Backend is a high-performance FastAPI-based API service that powers the comprehensive report generation system. Built with modern Python 3.12+ and utilizing advanced AI technologies, it provides speech-to-text transcription, intelligent title generation, email services, and comprehensive logging capabilities. This repository contains only the backend API; the frontend is available separately.

Build status Python 3.12+ Ruff

Features

  • Speech-to-Text: High-quality audio transcription using Whisper API integration
  • AI-Powered Title Generation: Intelligent title generation using LLM (Qwen3) models
  • Email Services: Automated email sending with document attachments
  • Comprehensive Logging: Structured logging with in-memory storage and REST API access
  • RESTful API: Well-documented FastAPI endpoints with automatic OpenAPI documentation
  • Production Ready: Docker support with multi-stage builds and SSL/TLS security
  • Type Safety: Full type annotations compatible with Python 3.12+
  • Async Architecture: Non-blocking asynchronous operations for optimal performance

Technology Stack

  • Framework: FastAPI with async/await support
  • AI/ML: LLM Facade with Qwen3 integration
  • Speech Processing: OpenAI Whisper API for audio transcription
  • HTTP Client: aiohttp for efficient async HTTP operations
  • Logging: Structlog for structured logging with JSON output
  • Package Manager: uv for fast dependency management
  • Code Quality: Ruff for linting and formatting, Pre-commit hooks
  • Testing: pytest with coverage reporting
  • Documentation: MkDocs with Material theme

API Endpoints

Core Services

  • POST /stt - Speech-to-text transcription from audio files
  • POST /title - Generate intelligent titles from text content
  • POST /send - Send emails with document attachments

Documentation

  • /docs - Interactive API documentation (Swagger UI)
  • /redoc - Alternative API documentation (ReDoc)

Setup

Environment Configuration

Create a .env file in the project root with the required environment variables:

# Whisper API Configuration
WHISPER_API=http://localhost:3000

# LLM Configuration
LLM_API=http://localhost:50002/v1
LLM_MODEL="Qwen/Qwen3-32B-AWQ"
LLM_API_KEY=your_api_key_here

Pre-requisites

  • Install uv
  • Python 3.12 or higher

Installation

  1. Create venv with uv and install dependencies:
uv sync
  1. Start the development server:
./run.sh

or directly with uv:

uv run fastapi dev src/bericht_backend/app.py

The API will be available at http://localhost:8000 with interactive documentation at http://localhost:8000/docs.

Development

Running the Application

For development with auto-reload:

uv run fastapi dev src/bericht_backend/app.py

For production:

uv run fastapi run src/bericht_backend/app.py

Frontend Integration

This backend is designed to work with the Bericht Frontend application. Ensure both services are running and properly configured to communicate with each other.

The frontend should be configured to point to this backend's URL in its environment configuration.

Code Quality

Code Formatting and Linting

Format and lint code with Ruff:

# Check code quality
uv run ruff check

# Fix auto-fixable issues
uv run ruff check --fix

# Format code
uv run ruff format

Type Checking

Run type checking with basedpyright:

uv run basedpyright

Docker Deployment

Production Deployment

The application includes a multi-stage Dockerfile:

# Build the Docker image
docker build -t bericht-backend .

# Run the container
docker run -p 8000:8000 \
  -e WHISPER_API=http://your-whisper-service:3000 \
  -e QWEN_BASE_URL=http://your-llm-service:11434 \
  bericht-backend

Docker Compose

For local development with dependencies:

docker-compose up -d

This will start any required services defined in docker-compose.yml.

Project Architecture

src/bericht_backend/
├── app.py                 # FastAPI application and route definitions
├── config.py              # Configuration management and environment variables
├── models/                # Pydantic models for request/response schemas
│   ├── generate_title_input.py
│   ├── generate_title_response.py
│   ├── log_response.py
│   ├── response_format.py
│   └── transcription_response.py
├── services/              # Business logic and external service integrations
│   ├── mail_services.py
│   ├── title_generation_service.py
│   └── whisper_services.py
├── utils/                 # Utility functions and helpers
│   └── logger.py
└── stubs/                 # Type stubs for external libraries

API Usage Examples

Speech-to-Text Transcription

curl -X POST "http://localhost:8000/stt" \
  -F "audio_file=@recording.wav"

Generate Title

curl -X POST "http://localhost:8000/title" \
  -H "Content-Type: application/json" \
  -d '{"text": "This is a complaint about noise pollution in the neighborhood..."}'

Send Email

curl -X POST "http://localhost:8000/send" \
  -F "to_email=recipient@example.com" \
  -F "subject=Report Document" \
  -F "email_body=Please find the attached report." \
  -F "file=@report.docx"

License

MIT © Data Competence Center Basel-Stadt


DCC Logo

Datenwissenschaften und KI
Developed with ❤️ by DCC - Data Competence Center