A lightweight, production-ready Go microservice that generates LLM-powered summaries, explanations, and text transformations using either OpenAI or a deterministic mock LLM for local/offline development.
This service is part of a 4-service AI Backend ecosystem that powers a full RAG (Retrieval-Augmented Generation) system.
POST /summary→ Generate a summary or explanation from input text- Real OpenAI support (gpt-4o-mini recommended)
- Deterministic mock mode for local development
- Clean Fiber HTTP API
- Structured logging (Zerolog)
- Metrics endpoint for observability
- Lightweight, fast, and deployable on Fly.io
- Fully containerized (Docker)
flowchart TD
A[Client / RAG Core] --> B[POST /summary]
B --> C[Handler]
C --> D[AI Layer]
D --> E[OpenAI API or Mock LLM]
E --> C
C --> A
ai-summary-service/
├── main.go
├── go.mod
├── Dockerfile
├── .env.example
└── internal/
├── ai/
│ └── llm.go
├── handlers/
│ └── summary_handler.go
└── middleware/
├── logger.go
└── metrics.go
git clone https://github.com/ai-backend-course/ai-summary-service
cd ai-summary-servicecp .env.example .envgo run .The service will start at:
http://localhost:8080
POST /summary
{
"text": "Golang is a fast, typed, compiled language designed for scalable backend systems."
}{
"summary": "Go is a fast, compiled language built for scalable backend systems."
}{
"summary": "MOCK SUMMARY: Golang is a fast, typed..."
}.env.example:
OPENAI_API_KEY=your_api_key_here
USE_LLM_MOCK=true
OPENAI_MODEL=gpt-4o-mini
PORT=8080
ENV=developmentGET /metrics
Example:
{
"total_requests": 14,
"total_errors": 0,
"avg_latency_ms": 1.4
}docker build -t ai-summary-service .
docker run -p 8080:8080 ai-summary-serviceflyctl launch
flyctl secrets set OPENAI_API_KEY="your_key"
flyctl secrets set USE_LLM_MOCK=false
flyctl deployMIT License.