// Veriyle Konusan Analitik Asistan
Deploy:
Production'a Cikis
Ders 6 · API + Docker + AWS + izleme
01 / Temsil
02 / Text-to-SQL
03 / Schema-RAG
04 / Agent
05 / Guvenlik
06 / Deploy
API'lestir — FastAPI
from fastapi import FastAPI
from pydantic import BaseModel
from ders4_agent import run_agent # Ders 4 agent'ini sariyoruz
app = FastAPI(title="Veriyle Konusan Analitik Asistan")
class Question(BaseModel):
text: str
@app.post("/ask")
def ask(q: Question):
return {"question": q.text, "answer": run_agent(q.text)}
Tum egitim boyunca kurdugumuz asistan, artik bir HTTP endpoint. Kod degismedi — sardik.
Canli Test — Swagger UI
uvicorn ders6_api:app --reload
# -> http://localhost:8000/docs (Swagger UI)
POST /ask
{ "text": "en cok satan 3 urun" }
↓
{ "question": "en cok satan 3 urun",
"answer": "En cok satan urunler: Kablosuz Kulaklik (10), ..." }
Tarayicidan canli sor — asistan cevabi doner.
Paketle — Docker (Kopru)
FROM python:3.11-slim
WORKDIR /app
# YALIN imaj: serving'de torch/chroma yok
COPY requirements-serve.txt .
RUN pip install --no-cache-dir -r requirements-serve.txt
COPY . .
RUN python seed_db.py # DB'yi imaja koy
EXPOSE 8000
CMD ["uvicorn", "ders6_api:app",
"--host", "0.0.0.0", "--port", "8000"]
"Docker mantigi: ortami paketle, her yerde calissin." Docker/AWS egitimiyle ayni akis.
LLM'e ozel fark
- API key'i image'a GOMME
- Runtime'da Secrets Manager'dan gelir
- Sadece serving bagimliliklari → kucuk imaj
Buluta Cikis — AWS (Mimari)
Docker image
→
ECR
→
ECS / Fargate
→
ALB → public URL
Text-to-SQL production notlari
- API key + DB credential → Secrets Manager
- DB kullanicisi read-only (agent yazamaz/silemez)
- Gercekte DuckDB yerine Aurora/RDS (Postgres) + havuz
- Buyuk semada retrieval → OpenSearch / pgvector
Hizli alternatifler
- AWS Copilot (tek komut)
- Lightsail
- Railway / Render
Tek Komut Deploy — AWS CDK (IaC)
# Altyapi = Python. app.py: VPC + ECS + Fargate + ALB
ecs_patterns.ApplicationLoadBalancedFargateService(self, "Service",
cluster=cluster, cpu=1024, memory_limit_mib=2048,
task_image_options=...(
image=ecs.ContainerImage.from_asset("../kod"), # kod/ + Dockerfile
secrets={"DEEPSEEK_API_KEY": ecs.Secret.from_secrets_manager(secret)}))
Tek komut
# anahtari bir kez koy
aws secretsmanager create-secret \
--name text-to-sql/deepseek --secret-string "sk-..."
cdk bootstrap # ilk kez
cdk deploy # -> ALB public URL
Ne kuruldu?
- VPC, ECS Cluster
- Fargate task (image build+push)
- ALB + public URL
- Secret runtime'da enjekte
Bitince cdk destroy (maliyet!)
Izleme — Neyi Gozlemlersin?
Latency — SQL uretme + calistirma suresi
Token maliyeti — istek basi $
Audit log — agent HANGI SQL'i calistirdi
Trace — self-correction kac adim surdu
Dogruluk — kullanici geri bildirimi + eval regresyonu
Audit log neden kritik?
DB'ye dokunan bir sistemde "hangi sorgu calisti"
kaydi sart. Guvenlik, hata ayiklama ve uyumluluk icin.
Araclar: Langfuse, LangSmith, OpenTelemetry
📦 Sektor Notu: LLM Gozlemlenebilirligi
LLM gozlemlenebilirligi klasik APM'den farklidir: cikti olasiliksal +
DB'ye yazan/okuyan bir agent var.
Bu yuzden loglama + eval + audit birlikte gider. "200 OK dondu" yetmez —
dogru SQL mi, guvenli mi, ne kadara mal oldu?
Klasik API
status + latency
+ LLM
token + trace + eval
+ DB agent
audit log + yetki
Tum Yolculuk
Token
→
Embedding
→
LLM/SQL
→
Schema-RAG
→
Agent
→
Guvenlik
→
Deploy
Sifirdan, dogal dille veritabanina soru soran canli bir asistan kurduk.
Kapanis + Kaynaklar
Kaynaklar
- "Attention is All You Need" (2017)
- Spider / BIRD — text-to-SQL eval
- DeepSeek / OpenAI API dokumanlari
- LangGraph, DuckDB docs
- Bu egitimin yazili notlari / blog serisi
Kacirmayin
- Repo linki — evde dene
- Demo AWS kaynaklarini bitince sil (maliyet)
- Docker/AWS serisi — deploy derinlemesine
Sorulariniz? — Tesekkurler.