Logo vun Fastapi Service

Fastapi Service

Communautéit
0xBakeer
fastapi-service

Writing a Python HTTP API with FastAPI (or Flask) - pydantic models, routers, validation errors, status codes, dependencies, settings from the environment, running with uvicorn and checking routes with curl.

Iwwersiicht

Editeur0xBakeer
RepositoryTandemLLM
Skill-Nummfastapi-service
Stären
75
Forks
14
Matgeliwwert Fichieren
Nëmmen Instruktiounen
LizenzAGPL-3.0
Linken
  • Instruktiounen am Markdown-Format

    Eng SKILL.md-Datei, déi de Modell bei Bedarf luet, soudatt nëmmen Token ufalen, wann eng Ufro tatsächlech dozou passt.

  • Funktionéiert mat all LLM

    KI-Skills si reng Markdown, keen ubidderspezifesche Code. Dofir funktionéiert dëse Skill mat GPT, Claude, Gemini, Grok oder engem lokale Modell.

  • Alles an den Instruktiounen

    Alles, wat de Modell brauch, steet an den Instruktiounen — keng zousätzlech Dateien ze synchroniséieren.

  • Open Source

    Vum 0xBakeer op GitHub verëffentlecht. Liest de Quelltext, ier Dir de Skill installéiert.

Installatioun

Installéiert de KI-Skill Fastapi Service an TypingMind, fir e mat all LLM ze benotzen, oder füügt en an en anere KI-Agent an, deen SKILL.md liest.

1

An TypingMind installéieren

TypingMind installéiert e Skill direkt aus sengem GitHub-Dossier — dobäi gëtt SKILL.md gelies, d'Ressourcedateie gi gebëndelt an d'Resultat gëtt lokal gespäichert.

  1. Maacht d'App op a gitt op Plugins → Skills.
  2. Wielt „Vun GitHub installéieren“.
  3. Pecht d'URL vum Skill-Dossier hei drënner an a bestätegt.
    https://github.com/0xBakeer/TandemLLM/tree/main/packages/library/fastapi-service
  4. Aktivéiert de Skill an all Chat, an deem Dir e benotze wëllt.
Plugins → Skills → Skill afügen → Vu GitHub-URL, pecht dann d'URL vum Dossier an a klickt op Weider.
2

An engem anere KI-Agent installéieren

All KI-Agent, deen d'Format Agent Skills liest, kann dëse Skill benotzen — kopéiert den Dossier an de Skill-Verzeechnes vun deem KI-Agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/0xBakeer/TandemLLM.git /tmp/TandemLLM
mkdir -p .claude/skills
cp -r /tmp/TandemLLM/packages/library/fastapi-service .claude/skills/fastapi-service
Start Claude Code nom Kopéieren nei, fir datt den neie Skill erkannt gëtt.

An TypingMind benotzen

Aktivéiert Fastapi Service an engem Chat vun TypingMind, an de Modell iwwerhëlt de Rescht. Den Numm an d'Beschreiwung stinn am System-Prompt. Soubal eng Ufro dozou passt, luet de Modell déi komplett Instruktioune selwer — Dir musst de Skill ni manuell opruffen, an et fale keng Token un, bis en tatsächlech benotzt gëtt.

De Modell luet Fastapi Service automatesch, soubal eng Ufro dozou passt.

Funktionéiert mat all KI-Modell

KI-Skills si reng Markdown-Instruktiounen amplaz vun ubidderspezifeschem Code. Dofir ass Fastapi Service net un de Modell gebonnen, fir deen de Skill geschriwwe gouf. Installéiert en eemol an TypingMind a benotzt e mat GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder engem lokale Modell, deen Dir selwer bedreift — alles mat Ären eegenen API-Keys.

  • Gëtt nëmme gelueden, wann et néideg ass

    De System-Prompt enthält nëmmen den Numm an d'Beschreiwung. D'Instruktioune gi bei der éischter passender Ufro gelueden, soudatt en onbenotzte Skill näischt kascht.

  • De Modell am lafende Chat wiesselen

    Well de Skill aus Instruktiounen amplaz vu Code besteet, funktionéiert en och no engem Modellwiessel — den nächste Modell liest déi selwecht SKILL.md-Datei.

Skill-Instruktiounen

Dëst ass den Inhalt vu SKILL.md, deen de Modell luet. Liest e virun der Installatioun — e Skill besteet aus Instruktiounen, déi Äre Modell befollegt.

FastAPI service

Rules:

  • Layout: app/main.py (app + routers), app/models.py (pydantic in/out), app/db.py, app/routes/*.py. One router per resource.
  • Every request body and response is a pydantic model. Return response_model= so the output is validated and documented.
  • Status codes on purpose: 201 on create, 204 on delete, 404 with HTTPException(404, "item not found"), 422 left to pydantic.
  • Settings from the environment (pydantic-settings), never hard-coded; .env ignored by git.
  • Run: uvicorn app.main:app --port 8000 > {tandem_scratch}/run.log 2>&1 &, then curl /healthz. Add /healthz and /__state.

What goes wrong:

  • async def route calling a sync database driver; the whole server stalls.
  • 500 on a known error path; map it to 400/404/409 with a JSON body.
  • Mutable default or module-level state shared across requests.

Check: curl each route: a valid call, an invalid body (422), a missing id (404); read status and body each time; read the log tail; stop the server at the end.

Done when:

  • Log line shows uvicorn listening; /healthz returns 200 (curl output in the result).
  • For every route the status and body for valid, invalid and not-found calls are in the result.
  • Create then read-back agrees; the server you started is stopped.

Reference

python
# app/main.py
from fastapi import FastAPI, HTTPException, status
from pydantic import BaseModel, Field
app = FastAPI()
class ItemIn(BaseModel):
    text: str = Field(min_length=1, max_length=200)
class Item(ItemIn):
    id: int
DB: dict[int, Item] = {}
@app.get("/healthz")
def healthz(): return {"ok": True}
@app.get("/__state")
def state(): return {"tandem_state": 1, "items": len(DB), "routes": [r.path for r in app.routes]}
@app.post("/items", response_model=Item, status_code=status.HTTP_201_CREATED)
def create(body: ItemIn):
    item = Item(id=len(DB) + 1, **body.model_dump()); DB[item.id] = item; return item
@app.get("/items/{item_id}", response_model=Item)
def get(item_id: int):
    if item_id not in DB: raise HTTPException(404, "item not found")
    return DB[item_id]

Run and probe:

bash
python -m venv .venv && . .venv/bin/activate && pip install fastapi uvicorn
(uvicorn app.main:app --port 8000 > {tandem_scratch}/run.log 2>&1 &) ; sleep 1
curl -s -o /dev/null -w '%{http_code}\n' localhost:8000/healthz
curl -s -X POST localhost:8000/items -H 'Content-Type: application/json' -d '{"text":"a"}'
curl -s -w ' %{http_code}\n' -X POST localhost:8000/items -H 'Content-Type: application/json' -d '{"text":""}'
curl -s -w ' %{http_code}\n' localhost:8000/items/99
tail -n 20 {tandem_scratch}/run.log; pkill -f 'uvicorn app.main'

Settings: class Settings(BaseSettings): db_url: str = "sqlite:///app.db" with model_config = SettingsConfigDict(env_file=".env").

More rules:

  • Blocking work (files, CPU) in def routes or a threadpool; async def only with async libraries.

More pitfalls:

  • Port in use from a previous run; check lsof -i :8000 and kill the old process.
  • Flask alternative: the same rules; validate by hand or with marshmallow, run with flask --app app run --port 8000.

Heefeg gestallte Froen

Wat mécht de KI-Skill Fastapi Service?

Writing a Python HTTP API with FastAPI (or Flask) - pydantic models, routers, validation errors, status codes, dependencies, settings from the environment, running with uvicorn and checking routes with curl.

Firwat Fastapi Service op TypingMind benotzen?

Well Dir en eemol installéiert a mat all Modell benotze kënnt. Fastapi Service besteet aus einfachem Markdown amplaz vun ubidderspezifeschem Code. Dee selwechte Skill funktionéiert also mat GPT-5, Claude, Gemini, Grok oder engem lokale Modell – an Dir kënnt de Modell matzen am Chat wiesselen, ouni datt de Skill ophält ze funktionéieren. TypingMind benotzt Är eegen API-Schlësselen, sou datt Dir d'Ubidder direkt bezuelt amplaz vun engem Abonnement pro Benotzerplaz. Är Skills a Chats bleiwen an Ärem eegene Späicher.

Wéi installéieren ech Fastapi Service an TypingMind?

Maacht an TypingMind Plugins → Skills → Vu GitHub installéieren op a setzt https://github.com/0xBakeer/TandemLLM/tree/main/packages/library/fastapi-service an. TypingMind liest d'Datei SKILL.md an installéiert de Skill, deen Dir pro Chat aktivéiere kënnt.

Wéi eng KI-Modeller kënnen Fastapi Service benotzen?

All Modell, deen Dir an TypingMind verbënnt. KI-Skills sinn einfach Markdown-Instruktiounen an net ubidderspezifesche Code. Dofir kënne GPT, Claude, Gemini, Grok a lokal Modeller dëse Skill lueden, wann eng Ufro dozou passt.

Wéi vill KI-Modeller kann ech mat Fastapi Service benotzen?

Esou vill Dir wëllt. Soulaang e Modell Skills ënnerstëtzt, kënnt Dir Fastapi Service domat benotzen – GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama a méi – alles op TypingMind mat Ären eegenen API-Schlësselen.

Ass de KI-Skill Fastapi Service gratis?

Jo. De Skill gëtt vum 0xBakeer ënner der Lizenz AGPL-3.0 op GitHub publizéiert. Dir bezuelt nëmmen Ären eegene KI-Ubidder fir d'Token, déi Dir benotzt.

Wat si KI-Skills?

E KI-Skill ass e weiderverwendbaart Pak vun Instruktiounen, dat engem KI-Modell bäibréngt, wéi en eng bestëmmt Aufgab erfëllt. E follegt dem oppenen Agent Skills-Format: eng Datei SKILL.md mat engem Numm an enger Beschreiwung, plus all Scripten, Virlagen oder Referenzdateien, déi de Modell eventuell brauch. De Modell liest d'Instruktiounen eréischt, wann Är Ufro zum Skill passt. En installéierte Skill kascht also näischt, bis e benotzt gëtt.

Wéi ënnerscheede sech KI-Skills vu Plugins oder MCP-Serveren?

E Plugin oder MCP-Server gëtt engem Modell nei Tools, déi en opruffe kann – Code, deen iergendwou leeft an e Resultat zeréckgëtt. E KI-Skill gëtt dem Modell dogéint Wëssen an eng Virgoensweis: wéi en eng Aufgab ugeet, wéi eng Schrëtt en nokënnt a wéi eng gutt Ausgab ausgesäit. Skills bestinn aus einfachem Markdown, brauche kee Server, keen API-Schlëssel a keng Lafzäitëmfeld a funktionéiere mat all Modell.

All weisen

Elo Ären eegene KI-Workspace ariichten

Abonnéiert Iech op eisen Newsletter, fir iwwer nei Funktiounen an zukünfteg Gewënnspiller informéiert ze ginn 👇