惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LangChain Blog
N
Netflix TechBlog - Medium
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
V2EX
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Blog — PlanetScale
Blog — PlanetScale
Microsoft Security Blog
Microsoft Security Blog
D
Docker
WordPress大学
WordPress大学
罗磊的独立博客
J
Java Code Geeks
博客园 - 【当耐特】
博客园 - 司徒正美
雷峰网
雷峰网
H
Help Net Security
酷 壳 – CoolShell
酷 壳 – CoolShell
Last Week in AI
Last Week in AI
宝玉的分享
宝玉的分享
Martin Fowler
Martin Fowler
T
Tailwind CSS Blog
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence
Recent Announcements
Recent Announcements
B
Blog

Hacker News - Newest: "AI"

AI can't read an investor deck AI as an attorney? Student uses ChatGPT, Gemini to sue UW over alleged racial discrimination Hacking MCP Servers in AI Systems – The Rug Pull: Tool Changes After Approval GitHub - MeepCastana/KubeezCut: Free Web based video editor Can AI judge journalism? A Thiel-backed startup says yes, even if it risks chilling whistleblowers Coming soon: 10 Things That Matter in AI Right Now DARPA built an AI to fact-check enemy weapons claims What explains heterogeneity in AI adoption? When AI Meets Muscle: Context-Aware Electrical Stimulation Promises a New Way to Guide Human Movements - Department of Computer Science AI Changed How We Build. It Did Not Change What Matters. Linux rules on using AI-generated code - Copilot is OK, but humans must take 'full responsibility for the… Meta spins up AI version of Mark Zuckerberg to engage with employees Code Mode: Let Your AI Write Programs, Not Just Call Tools | TanStack Blog GitHub - Delavalom/graft: Go framework for building AI agents. Type-safe tools, multi-provider (OpenAI, Anthropic, Gemini, Bedrock), zero vendor SDKs. India's TCS tops estimates, says new AI models did not dent services demand Gen Z's fading AI hype Strong feeling: we are in a folded AI reality GitHub - machinarii/total-recall-catalog: A reference catalog of latest knowledge retrieval, memory & RAG systems GitHub - mensfeld/code-on-incus: Give each AI agent its own isolated machine with root, Docker, and systemd. Active defense detects and stops threats automatically.. Quantization, LoRA, and the 8% Problem: Benchmarking Local LLMs for Production AI Iran war: We spoke to the man making Lego-style AI videos that experts say are powerful propaganda Powell, Bessent discussed Anthropic's Mythos AI cyber threat with major U.S. banks GitHub - immartian/bellamem: Persistent belief-graph memory for AI agents. Retrieves decisive context by importance — not recency, not RAG, not /compact. recursive-mode: The Repo-Native Operating System for AI Engineering After the attack on Sam Altman's home, will AI CEO's go on the offensive? The biggest advance in AI since the LLM Opus 4.6 vs GPT 5.4 One Prompt Unity World Generation Test “AI polls” are fake polls Client Challenge Can AI be a 'child of God'? Inside Anthropic's meeting with Christian leaders
GitHub - JoeCardoso13/brush-up-backend: FastAPI backend f...
jow13_12 · 2026-04-29 · via Hacker News - Newest: "AI"

Backend for Brush Up Python, Brush Up Ruby, and Brush Up JavaScript. A small AI-powered backend for tutors of Python, Ruby, and JavaScript built to showcase applied product and engineering work. You can read about its creation in my blog post.

The app answers programming questions by grounding model responses in a personal Zettelkasten-style knowledge base of interconnected markdown notes. This repository contains the backend API, retrieval pipeline, tutor prompt, and test suite.

What this does

  • Serves a FastAPI chat API for the public brush-up frontend
  • Builds one directed knowledge graph per language from markdown notes in notes/<language>/
  • Retrieves the most relevant topic with a lightweight TF-IDF index
  • Expands context with 1-hop graph neighbors before calling Anthropic
  • Tracks per-user token usage in memory to limit abuse on the public demo

Architecture

Flow

  1. A user asks a programming question from the frontend, scoped to a specific tutor (Python, Ruby, or JavaScript).
  2. The backend scores the question against the note corpus with TF-IDF retrieval.
  3. The top matching note becomes the primary topic.
  4. The graph expands that topic with connected neighbor notes.
  5. The backend builds a grounded system prompt from tutor_prompt.md plus the retrieved note context.
  6. Anthropic generates the tutoring response.
  7. The API returns the response, updated conversation history, and token usage metadata.

Main pieces

  • src/api.py
    FastAPI app with /api/chat and /api/health, app startup lifecycle, CORS config, and API error handling.

  • src/agent.py
    Retrieval-aware tutoring logic. Selects context, assembles the system prompt, calls Anthropic, and returns usage metadata.

  • src/graph.py
    Builds a networkx.DiGraph from Obsidian-style [[wikilinks]], exposes 1-hop context gathering, and implements the TF-IDF search index.

  • src/budget.py
    In-memory per-user input/output token budget tracking.

  • src/main.py
    Simple CLI entrypoint for chatting with the tutor locally.

  • notes/<language>/
    The teaching corpus: atomic markdown notes per language (Python, Ruby, JavaScript) with wikilinks between them.

  • tutor_prompt.md
    The tutor's behavioral/system prompt.

Tech stack

  • Python 3.11+
  • FastAPI
  • NetworkX
  • Anthropic Python SDK
  • pytest
  • uv for environment and dependency management
  • Fly.io for deployment

Local development

Prerequisites

  • Python 3.11 or newer
  • uv
  • ANTHROPIC_API_KEY

Install dependencies

uv pip install -e ".[dev,web]"

If you only want the core package plus tests:

uv pip install -e ".[dev]"

Run the API

ANTHROPIC_API_KEY=your_key uvicorn api:app --app-dir src --reload --port 8080

Run the CLI

ANTHROPIC_API_KEY=your_key python src/main.py

Run tests

uv run pytest

Environment variables

Variable Default Purpose
ANTHROPIC_API_KEY none Required for model calls
BRUSH_UP_MODEL claude-sonnet-4-20250514 Anthropic model used by the tutor
BRUSH_UP_INPUT_BUDGET 250000 Per-user input token cap
BRUSH_UP_OUTPUT_BUDGET 60000 Per-user output token cap
BRUSH_UP_ALLOWED_ORIGINS built-in allowlist Comma-separated CORS origins
BRUSH_UP_ALLOWED_ORIGIN_REGEX ^https://[-a-zA-Z0-9]+\.vercel\.app$ Regex-based CORS allowlist

API

POST /api/chat

Request body:

{
  "user_id": "browser-generated-id",
  "tutor": "python",
  "question": "What is a list comprehension?",
  "conversation_history": []
}

Response body:

{
  "response": "A list comprehension is ...",
  "history": [
    { "role": "user", "content": "What is a list comprehension?" },
    { "role": "assistant", "content": "A list comprehension is ..." }
  ],
  "usage": {
    "input_tokens": 123,
    "output_tokens": 456,
    "retrieval": {
      "topic": "Comprehension",
      "score": 0.73,
      "neighbors": 4
    }
  }
}

Behavior notes:

  • Returns 429 when a user exceeds the in-memory token budget
  • Returns 503 when Anthropic reports temporary overload
  • Returns 502 for other Anthropic API failures
  • Does not persist conversation history server-side; the client sends it back on each request

GET /api/health

Returns service status plus the number of topics loaded into each tutor's graph, e.g. {"status": "ok", "tutors": {"python": 127, "ruby": 42, "javascript": 30}}.

Deployment

This repo includes:

  • Dockerfile for containerized deployment
  • fly.toml for Fly.io

The production container:

  • installs the web dependencies
  • copies src/, notes/, and tutor_prompt.md
  • runs uvicorn on port 8080

Testing

The project includes unit, integration, and API-level tests covering the graph builder, retrieval, tutor flow, budget logic, and FastAPI endpoints.

License

MIT