Commit 36f53281 authored by Kantz's avatar Kantz
Browse files

readme Übersetzt

parent c851f3de
# DER Tutor # Der Tutor
Dies ist ein Tutor-Bot der auf dem digitalen Lehrwerk von Anselm Knebusch beruht.
Es gibt 4 Modi.
1. Ein Q&A-Modus in dem man Fragen zum den Inhalten des Skript stellen kann.
2. Ein offener Tutormodus in dem man eigene Fragen stellen kann und diese mit dem Bot besprechen kann
3. Ein geschlossener Task Modus in dem man Aufgaben aus dem Lehrwerk mit dem Tutorbot besprechn kann.
4. Ein Sokrates Modus in dem man ein sokratischen Dialog zu einem Abschnitt aus dem Lehrwerk führen kann.
Aktuell gibt es noch nicht zu allen Themen Material.
## Prequisits ## Prequisits
- Postgres-Database [Database (pgvector) setup] - Postgres-Datenbank [Einrichtung der Datenbank (pgvector)]
- sources folder with your markdown files structured with section, subsection and child - Ordner „sources“ mit Ihren Markdown-Dateien, strukturiert nach Abschnitten, Unterabschnitten und Unter-Unterabschnitten
- OpenAI endpoint - OpenAI-Endpunkt
- Ollama Instanz - Ollama-Instanz
if you want to use the task mode you need : Wenn Sie den Aufgabenmodus nutzen möchten, benötigen Sie:
- task folder in sources with your tasks - Ordner „tasks“ im Verzeichnis „sources“ mit Ihren Aufgaben
- `_subsection_map.yaml` as the topic-to-index map for section, subsection, or subsubsection references. - `_subsection_map.yaml` als Zuordnung von Themen zu Indizes für Verweise auf Abschnitte, Unterabschnitte oder Unter-Unterabschnitte.
## Setup Übersetzt mit DeepL.com (kostenlose Version)
Configurate the `backend/.env`-file based on the `backend/.env-example`. You can che following modes: ## Setup
- QA : Direct answer based on the retrieval Konfigurieren Sie die Datei `backend/.env` anhand der Datei `backend/.env-example`.
- Tutor: Helps with tips on a task given by the user
- Task: A mode where you can select from the list in the taskfolder and get help with this Task.
Backend (Python): Backend (Python):
...@@ -56,24 +64,24 @@ pnpm run dev ...@@ -56,24 +64,24 @@ pnpm run dev
### Task Deep Links ### Task Deep Links
You can open a task chat directly with URL query parameters: Sie können einen Aufgaben-Chat direkt über URL-Abfrageparameter öffnen:
`/chat?orchestrator=task&file_id=<task_file_id>&task_id=<task_id>` `/chat?orchestrator=task&file_id=<task_file_id>&task_id=<task_id>`
Example: Beispiel:
`http://localhost:5173/chat?orchestrator=task&file_id=abc-formel-anwenden&task_id=03` `http://localhost:5173/chat?orchestrator=task&file_id=abc-formel-anwenden&task_id=03`
Notes: Hinweise:
- `file_id` must match an existing task file id from the task catalog. - `file_id` muss mit der ID einer vorhandenen Aufgabendatei aus dem Aufgabenkatalog übereinstimmen.
- `task_id` must exist inside that file. - `task_id` muss in dieser Datei vorhanden sein.
- If the link is invalid, the frontend falls back to `/select-task`. - Ist der Link ungültig, weicht das Frontend auf `/select-task` aus.
- The task is not locked by deep link, so users can still switch tasks afterwards. - Die Aufgabe wird durch den Deep Link nicht gesperrt, sodass Benutzer anschließend weiterhin zwischen Aufgaben wechseln können.
### Socratic Deep Links ### Socratic Deep Links
You can open a socratic chat directly with URL query parameters: Sie können einen Sokratischen Chat direkt über URL-Abfrageparameter öffnen:
`/chat?orchestrator=socratic&topic_key=<topic_key>` `/chat?orchestrator=socratic&topic_key=<topic_key>`
...@@ -81,16 +89,16 @@ Example: ...@@ -81,16 +89,16 @@ Example:
`http://localhost:5173/chat?orchestrator=socratic&topic_key=klammerrechnung` `http://localhost:5173/chat?orchestrator=socratic&topic_key=klammerrechnung`
Notes: Hinweise:
- `topic_key` must match an existing socratic topic from the task catalog. - `topic_key` muss mit einem vorhandenen Sokratischen Thema aus dem Aufgabenkatalog übereinstimmen.
- The links use normalized topic keys in the URL, and the app resolves them back to the catalog key. - Die Links verwenden normalisierte Themen-Schlüssel in der URL, und die App löst diese wieder in den Katalog-Schlüssel auf.
- The fallback `/select-socratic` page only shows the topic dropdown and start button. - Die Fallback-Seite `/select-socratic` zeigt nur das Themen-Dropdown-Menü und die Start-Schaltfläche an.
- If the link is invalid, the frontend falls back to `/select-socratic`. - Wenn der Link ungültig ist, weicht das Frontend auf `/select-socratic` aus.
- The socratic dialog is not locked by deep link, so users can still switch topics afterwards. - Der Sokratische Dialog ist nicht durch einen Deep Link gesperrt, sodass Benutzer das Thema auch nachträglich noch wechseln können.
To make it accessible over the network. Um den Zugriff über das Netzwerk zu ermöglichen.
Add the frontend- and backend-adress in the `backend/.env`-file in the frontend- and backend-folder. Use the following command to run the front- and backend. Füge die Frontend- und Backend-Adressen in die Datei `backend/.env` im Frontend- und Backend-Ordner ein. Verwende den folgenden Befehl, um das Frontend und Backend auszuführen.
```powershell ```powershell
python -m uvicorn app.main:app --reload --host 0.0.0.0 --port 8000 python -m uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
...@@ -99,23 +107,23 @@ pnpm run dev -- --host 0.0.0.0 ...@@ -99,23 +107,23 @@ pnpm run dev -- --host 0.0.0.0
### Frontend package manager policy (pnpm) ### Frontend package manager policy (pnpm)
- Required versions: - Erforderliche Versionen:
- Node.js: 22.x or newer - Node.js: 22.x oder neuer
- pnpm: pinned via `math-tutor/frontend/package.json` (`packageManager`) - pnpm: über `math-tutor/frontend/package.json` (`packageManager`) festgelegt
- Lockfile policy: - Richtlinie für die Lockdatei:
- Commit `pnpm-lock.yaml`. - `pnpm-lock.yaml` festschreiben.
- Use `pnpm install --frozen-lockfile` in local CI-like checks and Docker builds. - Verwende `pnpm install --frozen-lockfile` bei lokalen CI-ähnlichen Prüfungen und Docker-Builds.
- Install-script policy (strict): - Richtlinie für Installationsskripte (streng):
- Dependency build/install scripts are allowlisted. - Skripte zum Erstellen/Installieren von Abhängigkeiten werden auf die Whitelist gesetzt.
- After adding/updating dependencies, run `pnpm approve-builds` and review what is allowed. - Führe nach dem Hinzufügen/Aktualisieren von Abhängigkeiten `pnpm approve-builds` aus und überprüfe, was zugelassen ist.
- Check blocked scripts with `pnpm ignored-builds`. - Überprüfe blockierte Skripte mit `pnpm ignored-builds`.
### Vite Proxy (Development) ### Vite Proxy (Development)
The frontend now supports a dev proxy for API calls: Das Frontend unterstützt nun einen Dev-Proxy für API-Aufrufe:
- Frontend requests `/api/...` to Vite - Das Frontend sendet Anfragen an `/api/...` an Vite
- Vite forwards `/api` to the backend target - Vite leitet `/api` an das Backend-Ziel weiter
Optional in `math-tutor/frontend/.env`: Optional in `math-tutor/frontend/.env`:
...@@ -139,18 +147,18 @@ cd math-tutor/docker ...@@ -139,18 +147,18 @@ cd math-tutor/docker
docker compose up --build -d docker compose up --build -d
``` ```
Open in browser: In browser öffnen:
- `http://<HOST>:80` - `http://<HOST>:80`
Notes: Hinweise:
- Nginx serves the built frontend and proxies `/api` to backend (`http://backend:8000`). - Nginx stellt das integrierte Frontend bereit und leitet Anfragen an `/api` an das Backend weiter (`http://backend:8000`).
- Keep frontend API calls relative (`/api/...`) for this setup. - Halten Sie die API-Aufrufe im Frontend in dieser Konfiguration relativ (`/api/...`).
## Database (pgvector) setup ## Database (pgvector) setup
Ensure `POSTGRES_URL` and embedding env vars are in `backend/.env`: Stelle sicher, dass `POSTGRES_URL` und die anderen Umgebungsvariablen in `backend/.env` enthalten sind:
``` env ``` env
POSTGRES_URL=postgresql://user:pass@host:5432/db POSTGRES_URL=postgresql://user:pass@host:5432/db
...@@ -159,7 +167,7 @@ OPENAI_API_KEY=... ...@@ -159,7 +167,7 @@ OPENAI_API_KEY=...
OPENAI_EMBED_MODEL=... OPENAI_EMBED_MODEL=...
``` ```
Create the Postgres database before running init. Erstellen Sie die Postgres-Datenbank, bevor Sie „init“ ausführen.
Init DB schema: Init DB schema:
...@@ -169,7 +177,7 @@ cd math-tutor/backend ...@@ -169,7 +177,7 @@ cd math-tutor/backend
python -m scripts.retrieval_cli init-db python -m scripts.retrieval_cli init-db
``` ```
Ingest markdown docs (expects `markdown/sections`, `markdown/subsections`, `markdown/childs`): Markdown docs einbetten (expects `markdown/sections`, `markdown/subsections`, `markdown/childs`):
```powershell ```powershell
cd math-tutor/backend cd math-tutor/backend
...@@ -185,32 +193,24 @@ cd math-tutor/backend ...@@ -185,32 +193,24 @@ cd math-tutor/backend
python -m scripts.retrieval_cli query --q "Was ist eine Teilmenge?" --k 8 --expand python -m scripts.retrieval_cli query --q "Was ist eine Teilmenge?" --k 8 --expand
``` ```
## Generate Socratic Chats
```powershell
cd math-tutor/backend
.\.venv\Scripts\Activate.ps1
python -m scripts.generate_socratic_chats --source-root sources/lecture_script --output sources/inital_socratic_prompt/initial_prompts.yaml
```
## Configuration ## Configuration
Differend Orchestrators: Verschiedene Orchestrators:
- Edit `math-tutor/backend/app/api/chat.py` and update `SYSTEM_PROMPT`. - Edit `math-tutor/backend/app/api/chat.py` and update `SYSTEM_PROMPT`.
Retrieval settings: Retrieval settings:
- Frontend request parameters live in `math-tutor/frontend/src/pages/App.tsx`: - Frontend-Anfrageparameter befinden sich in `math-tutor/frontend/src/pages/App.tsx`:
- `k` - `k`
- `expand_links` - `expand_links`
- `neighbor_expand` - `neighbor_expand`
- Backend defaults are in `math-tutor/backend/app/api/retrieval.py` (`QueryRequest`). - Die Backend-Standardeinstellungen sind enthalten `math-tutor/backend/app/api/retrieval.py` (`QueryRequest`).
- Core retrieval logic is in `math-tutor/backend/app/services/vector_store.py` (`retrieve`). - Die Kernlogik für das Abrufen ist vorhanden `math-tutor/backend/app/services/vector_store.py` (`retrieve`).
## Testing ## Testing
currently there a multiple test to test some components seperatly. Check the test files for specific calling. Here are some example calls. Derzeit gibt es mehrere Tests, um bestimmte Komponenten separat zu prüfen. Die genauen Aufrufe finden Sie in den Testdateien. Hier sind einige Beispielaufrufe.
```powershell ```powershell
python -m test.hint_test --chat-id draft_session_mlgmxxzc_avmjfb python -m test.hint_test --chat-id draft_session_mlgmxxzc_avmjfb
...@@ -223,3 +223,11 @@ python -m test.math_intent_test --input "Integrate x^2" --input "Was ist 2+2?" ...@@ -223,3 +223,11 @@ python -m test.math_intent_test --input "Integrate x^2" --input "Was ist 2+2?"
python -m test.decision_test --chat-id draft_session_mlgmxxzc_avmjfb python -m test.decision_test --chat-id draft_session_mlgmxxzc_avmjfb
``` ```
## Generate Socratic Chats
```powershell
cd math-tutor/backend
.\.venv\Scripts\Activate.ps1
python -m scripts.generate_socratic_chats --source-root sources/lecture_script --output sources/inital_socratic_prompt/initial_prompts.yaml
```
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment