feat: LLM module — Ollama client with transcript refinement
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import httpx
|
||||
|
||||
SYSTEM_PROMPT = """Du bist ein präziser Schreibassistent.
|
||||
Du bekommst einen rohen Sprachtranskript und optionale Instruktionen des Nutzers.
|
||||
Deine Aufgabe:
|
||||
1. Bereinige den Text (Füllwörter, Wiederholungen, Tippfehler)
|
||||
2. Strukturiere ihn mit Markdown-Überschriften wenn sinnvoll
|
||||
3. Erzeuge einen passenden deutschen Titel als H1
|
||||
4. Beachte Instruktionen des Nutzers wenn vorhanden
|
||||
5. Antworte NUR mit dem fertigen Markdown — kein Kommentar, keine Erklärung
|
||||
|
||||
Format:
|
||||
# Titel
|
||||
|
||||
Inhalt...
|
||||
"""
|
||||
|
||||
|
||||
class OllamaClient:
|
||||
def __init__(self, base_url: str = "http://localhost:11434"):
|
||||
self.base_url = base_url
|
||||
|
||||
async def list_models(self) -> list[str]:
|
||||
async with httpx.AsyncClient() as client:
|
||||
r = await client.get(f"{self.base_url}/api/tags")
|
||||
r.raise_for_status()
|
||||
return [m["name"] for m in r.json().get("models", [])]
|
||||
|
||||
async def refine(
|
||||
self,
|
||||
raw_text: str,
|
||||
instructions: str = "",
|
||||
model: str = "gemma3:12b",
|
||||
) -> str:
|
||||
prompt = f"Transkript:\n{raw_text}"
|
||||
if instructions.strip():
|
||||
prompt += f"\n\nInstruktionen:\n{instructions.strip()}"
|
||||
async with httpx.AsyncClient(timeout=120) as client:
|
||||
r = await client.post(
|
||||
f"{self.base_url}/api/generate",
|
||||
json={"model": model, "prompt": prompt, "system": SYSTEM_PROMPT, "stream": False},
|
||||
)
|
||||
r.raise_for_status()
|
||||
return r.json()["response"]
|
||||
Reference in New Issue
Block a user