Skip to content

Instantly share code, notes, and snippets.

View lovemycodesnippets's full-sized avatar

The New Stack lovemycodesnippets

View GitHub Profile
docker run -d -v /var/run/docker.sock:/var/run/docker.sock -p 8082:8080 amir20/dozzle:latest
sudo usermod -aG docker $USER
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin git -y
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc]
https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
@lovemycodesnippets
lovemycodesnippets / step8_eval.py
Created January 19, 2026 20:35
How to Build Production-Ready AI Agents with RAG and FastAPI
# eval.py
import json
from langchain.chat_models import ChatOpenAI
from langchain.schema import HumanMessage
judge = ChatOpenAI(model="gpt-4o", temperature=0)
def judge_pair(question, answer, ref):
prompt = f"""You are a strict evaluator.
Q: {question}
@lovemycodesnippets
lovemycodesnippets / step7_skeleton-cache.py
Created January 19, 2026 20:34
How to Build Production-Ready AI Agents with RAG and FastAPI
# cache.py
from hashlib import sha256
CACHE = {}
def cache_key(query: str, doc_ids: list[str]) -> str:
return sha256(("||".join([query] + doc_ids)).encode()).hexdigest()
def get_cache(key: str): return CACHE.get(key)
def set_cache(key: str, val: dict): CACHE[key] = val
@lovemycodesnippets
lovemycodesnippets / step6_telemetry.py
Created January 19, 2026 20:33
How to Build Production-Ready AI Agents with RAG and FastAPI
# telemetry.py
import time, json, logging
logging.basicConfig(filename="agent.log", level=logging.INFO)
def log_event(kind: str, **kwargs):
logging.info(json.dumps({"ts": time.time(), "kind": kind, **kwargs}))
@lovemycodesnippets
lovemycodesnippets / step5_app.py
Created January 19, 2026 20:32
How to Build Production-Ready AI Agents with RAG and FastAPI
# app.py
import os, asyncio
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from rag import build_index
from agent import agent_run
app = FastAPI(title="Agentic AI API")
# Build a tiny demo index (swap with your corpus)