feat: max_tokens and repeat_penalty inputs, truncated and stop_reason outputs, 0.4.0
Some checks failed
CI / Linux x86_64 (Forgejo) (push) Failing after 1s

A model caught in a repetition loop wrote until the flow's 300 s
timeout. max_tokens bounds the answer on every wire (Ollama
num_predict, OpenAI max_tokens, Anthropic max_tokens), and
truncated tells the caller whether the answer stopped at that
limit. repeat_penalty goes to Ollama and vLLM and is refused where
the backend has no such setting.

Signed-off-by: flemming-it <sf@flemming.it>
This commit is contained in:
flemming-it 2026-11-12 15:49:50 +01:00
parent 14c63083d7
commit 72f3037ebe
8 changed files with 361 additions and 9 deletions

View file

@ -10,7 +10,7 @@ die Anthropic Messages API.
## Capability
- `llm.chat@0.3.0`
- `llm.chat@0.4.0`
## Eingaben
@ -22,6 +22,8 @@ die Anthropic Messages API.
| `api_key` | text | Optionaler API-Key. Erscheint nie in Ausgaben, Logs oder Events. |
| `keep_alive` | text | Nur Ollama: wie lange der Server das Modell nach dieser Anfrage geladen lässt (`4h`, `30m`, `-1` = unbegrenzt). Leer = Server-Voreinstellung, die nach fünf Minuten entlädt. Mit anderer `api` abgelehnt. |
| `think` | text | `true` oder `false`: ob ein Reasoning-Modell seine Denkphase durchläuft. Leer = Voreinstellung des Servers (Ollama lässt Modelle wie qwen3 denken). Ollama bekommt `think`, vLLM `chat_template_kwargs.enable_thinking`; im OpenAI-Format abgelehnt; Anthropic nimmt nur `false`. Gemessen mit Ollama 0.40.9: `qwen3.8:27b` und `gemma4:26b` halten `false` ein; `qwen3:30b-a3b` denkt trotzdem, das Denken steht dann in der Antwort und endet mit `</think>`. |
| `max_tokens` | text | Obergrenze für die Länge der Antwort in Token (ganze Zahl ab 1). Ollama bekommt `options.num_predict`, das OpenAI-Format `max_tokens`, Anthropic `max_tokens` (4096, wenn leer). Leer = keine Grenze bei Ollama und im OpenAI-Format. Ohne Grenze schreibt ein Modell in einer Wiederholungsschleife bis zur Zeitgrenze des Ablaufs; mit `num_predict: 400` brach `qwen3.8:27b` unter Ollama 0.40.9 eine solche Schleife nach 39 s ab. |
| `repeat_penalty` | text | Abschlag auf wiederholte Token, 1.0 = neutral. Ollama bekommt `options.repeat_penalty`, vLLM `repetition_penalty`; im OpenAI-Format und bei Anthropic abgelehnt. |
| `system_prompt` | text | Optionale System-Nachricht. Leer = Default des Modells. |
| `api` | text | Optionales Wire-Format: `ollama` (Default), `openai`, `anthropic`. |
@ -31,13 +33,15 @@ die Anthropic Messages API.
| ----------- | ----------------------------------------- | ---------------------------------- | ------------------------------------------------------------ |
| `ollama` | `http://localhost:11434/api/chat` | `Authorization: Bearer` (optional) | Verhalten wie v0.1.0, unverändert. Modell-Digest-Probe via `/api/show`. |
| `openai` | `https://.../v1/chat/completions` | `Authorization: Bearer` | OpenAI-Chat-Completions-Format — sprechen auch vLLM und die meisten selbst gehosteten Inferenz-Server. |
| `anthropic` | `https://api.anthropic.com/v1/messages` | `x-api-key` + `anthropic-version` | Messages API: `system` ist Top-Level-Feld; `max_tokens` ist Pflicht und steht fest auf 4096. |
| `anthropic` | `https://api.anthropic.com/v1/messages` | `x-api-key` + `anthropic-version` | Messages API: `system` ist Top-Level-Feld; `max_tokens` ist Pflicht; `max_tokens` setzt es, sonst 4096. |
## Ausgaben
| Name | Typ | Beschreibung |
| ---------------- | ---- | --------------------------------------------------------------------- |
| `response` | text | Die Antwort des Assistants als Plain-Text. |
| `truncated` | text | `true`, wenn die Antwort an der Längengrenze endete, `false`, wenn das Modell fertig war. Leer, wenn das Backend keinen Grund nannte. Eine abgeschnittene Antwort wird trotzdem geliefert; der Ablauf entscheidet, was damit geschieht. |
| `stop_reason` | text | Der Grund des Backends: Ollama `done_reason`, OpenAI `finish_reason`, Anthropic `stop_reason`. Leer, wenn er fehlt. |
| `model_endpoint` | text | URL, gegen die die Antwort erzeugt wurde. |
| `model_name` | text | Modell-ID wie an die LLM-API gesendet. |
| `model_digest` | text | SHA-256-Digest des bedienenden Ollama-Modells. Leer bei `openai`/`anthropic` — diese APIs bieten keinen Digest; das Feld bleibt leer statt erfunden. |