eq-chatbot-core 4.0.3__tar.gz → 4.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/CHANGELOG.md +32 -0
  2. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/PKG-INFO +3 -3
  3. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/README.md +2 -2
  4. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/RELEASE_NOTES.md +26 -0
  5. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/providers/__init__.py +2 -0
  6. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/providers/anthropic_provider.py +45 -1
  7. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/providers/base.py +264 -0
  8. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/providers/langdock_provider.py +16 -0
  9. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/providers/openai_compatible.py +65 -3
  10. eq_chatbot_core-4.2.0/src/eq_chatbot_core/providers/param_learning.py +666 -0
  11. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/version.py +1 -1
  12. eq_chatbot_core-4.0.3/src/eq_chatbot_core/providers/param_learning.py +0 -282
  13. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/.gitignore +0 -0
  14. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/LICENSE +0 -0
  15. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/pyproject.toml +0 -0
  16. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/__init__.py +0 -0
  17. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/cli.py +0 -0
  18. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/data/__init__.py +0 -0
  19. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/data/config.toml.example +0 -0
  20. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/mcp/__init__.py +0 -0
  21. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/mcp/client.py +0 -0
  22. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/mcp/streamable_http.py +0 -0
  23. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/providers/anthropic_shared.py +0 -0
  24. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/providers/ionos_provider.py +0 -0
  25. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/providers/litellm_provider.py +0 -0
  26. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/providers/local_provider.py +0 -0
  27. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/providers/mammouth_provider.py +0 -0
  28. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/providers/melious_provider.py +0 -0
  29. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/providers/openai_provider.py +0 -0
  30. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/providers/openrouter_provider.py +0 -0
  31. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/providers/privatemode_provider.py +0 -0
  32. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/providers/stream_accumulator.py +0 -0
  33. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/providers/temperature_constraints.py +0 -0
  34. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/py.typed +0 -0
  35. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/rag/__init__.py +0 -0
  36. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/rag/chunker.py +0 -0
  37. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/rag/context_manager.py +0 -0
  38. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/rag/embedder.py +0 -0
  39. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/rag/retriever.py +0 -0
  40. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/realtime/__init__.py +0 -0
  41. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/realtime/abc.py +0 -0
  42. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/realtime/contracts.py +0 -0
  43. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/realtime/factory.py +0 -0
  44. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/realtime/mock.py +0 -0
  45. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/realtime/providers/__init__.py +0 -0
  46. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/realtime/providers/elevenlabs.py +0 -0
  47. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/realtime/providers/gemini_live.py +0 -0
  48. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/realtime/providers/openai.py +0 -0
  49. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/realtime/websocket_client.py +0 -0
  50. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/security/__init__.py +0 -0
  51. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/security/encryption.py +0 -0
  52. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/security/file_validator.py +0 -0
  53. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/security/injection.py +0 -0
  54. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/security/rate_limit.py +0 -0
  55. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/server/__init__.py +0 -0
  56. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/server/app.py +0 -0
  57. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/server/auth.py +0 -0
  58. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/server/lifecycle.py +0 -0
  59. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/server/models.py +0 -0
  60. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/server/streaming.py +0 -0
  61. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/services/__init__.py +0 -0
  62. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/services/capability_catalog.py +0 -0
  63. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/services/document_extractor.py +0 -0
  64. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/services/error_handler.py +0 -0
  65. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/services/knowledge_service.py +0 -0
  66. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/utils/__init__.py +0 -0
  67. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/utils/config.py +0 -0
  68. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/utils/image.py +0 -0
  69. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/utils/pdf.py +0 -0
  70. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/utils/secret_scrub.py +0 -0
  71. {eq_chatbot_core-4.0.3 → eq_chatbot_core-4.2.0}/src/eq_chatbot_core/utils/url_validation.py +0 -0
@@ -5,6 +5,38 @@ All notable changes to eq-chatbot-core will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [4.2.0] - 2026-10-12
9
+
10
+ ### Added
11
+
12
+ - `BaseLLMProvider.check_model(model, *, temperature, max_tokens, tools, vision, probe_limit, **kwargs)` finds out what a model accepts before a chat needs it, with a few small streamed requests shaped like a chat turn (system and user message, the caller's temperature and extra arguments, an output limit of at most `CHECK_MAX_TOKENS` = 256): plain text, then with one function tool, then with a 32x32 PNG, then `probe_output_limit`. Returns a `ModelCheck` (per step `ok` / `refused` / `error` / `skipped`, the adjustments the model needs, the limits the provider named, and the provider's message per failed step, secrets scrubbed). Adjustments learned earlier are forgotten first, so a re-check notices a model the provider has changed. Never raises for a provider's answer. A connection test without tools passed while every chat turn with tools failed (12.10.2026); this check sends what the chat sends.
13
+ - Exploring unrecognised rejections (`param_learning.exploring()`, active only inside `check_model`): a rejection no rule recognises is answered by a bounded search — the unchanged request once more (a gateway may have hit a bad upstream; nothing is learned when it then passes), then each candidate adjustment alone. Candidates the error text names come first; without a name only harmless ones are tried (drop `temperature`, drop `stream_options`, `reasoning_effort="none"` with tools). Renaming `max_tokens` or dropping a configured `reasoning_effort` needs the name. Authentication, rate-limit, overload, server and network errors stop the search at once. Never active for a conversation or for the output-limit probe. Verified live 12.10.2026: with the 4.1.1 rule removed, the check found `reasoning_with_tools` for gpt-6-luna on its own.
14
+ - `learned_adjustments(model)` / `seed_adjustments(model, names)` on every provider, and `param_learning.learned_adjustments` / `seed_adjustments` / `forget_adjustments`: persist what was learned and restore it after a restart, so the first request is right.
15
+ - `param_learning.is_rejection(error)`: whether an error is the provider refusing the request as sent (HTTP 400/422 or a stream error event), following a `ProviderError` to the SDK error it was raised from. Overload, rate-limit, context-length and server errors relayed in the body are not rejections.
16
+ - Learnable `stream_usage`: drops `stream_options` for servers that refuse to report token usage in a stream.
17
+
18
+ ### Fixed
19
+
20
+ - A model that reasons by default and refuses function tools while it does now works with tools. OpenAI answered every `/chat/completions` request with tools for such a model with HTTP 400 ("Function tools with reasoning_effort are not supported ... set reasoning_effort to 'none'") — even when no `reasoning_effort` was sent, so a chat that always sends tools failed on every turn while a connection test without tools succeeded. The rejection is now recognised (learnable `reasoning_with_tools`): the request is resent once with `reasoning_effort="none"`, and once that succeeded it is remembered for the endpoint and model. It applies to requests with tools only; without tools the model keeps reasoning. Verified live 12.10.2026. (Prepared as 4.1.1, never released; shipped with 4.2.0.)
21
+
22
+ ### Changed
23
+
24
+ - While a model is checked, a stream is read on to the first chunk that carries an answer before it leaves the retry loop, so a refusal after an empty opening chunk can be explored too.
25
+
26
+ ## [4.1.0] - 2026-10-12
27
+
28
+ ### Added
29
+
30
+ - `BaseLLMProvider.probe_output_limit(model)` asks the provider for a model's output limit without generating text: one streaming request with an output limit far above any real one (`PROBE_MAX_TOKENS`, 10,000,000). The provider rejects it and names the limit ("This model supports at most 16384 completion tokens", "max_tokens: N > 128000, which is the maximum allowed number of output tokens"), which costs nothing. Returns `None` when the provider accepts the request (the stream is closed after the first chunk) or rejects it without a number (Melious); raises `ProviderError` on authentication, rate-limit and network errors. Implemented for every OpenAI-wire provider, Anthropic, and LangDock's `openai` backend; other backends return what was learned. Verified live 12.10.2026: OpenAI gpt-4o 16384, gpt-4.1-mini 32768, gpt-6-luna 128000; Anthropic claude-haiku-5-5 128000.
31
+ - `BaseLLMProvider.learned_limits(model)` returns the limits a rejection or probe stated for this endpoint and API key (`max_output_tokens`, `context_length`). The memory is process-wide and never persisted — callers that want to keep the values store them.
32
+ - `param_learning.stated_limits()`, `allowed_output()`, `cap_output()`, `remember_limits()`, `learned_limits()` and `LIMIT_KEYS`.
33
+
34
+ ### Changed
35
+
36
+ - A request rejected because its output limit is too large is resent once, capped to the limit the rejection states, and the limit is remembered: later requests to that model are capped before they are sent. A context rejection that names the request's input tokens (vLLM, older OpenAI wording) is resent with the room the context leaves; that room is not remembered as the model's output limit. A context rejection about the input itself still raises `ContextLengthError`, and the stated context length is remembered.
37
+ - `list_models()` fills `max_output_tokens` / `context_length` from learned limits where the endpoint reports none; a reported value is kept.
38
+ - `param_learning.call_with_learning()` takes `cap` (default `True`); `cap=False` is for the probe, whose oversized request must reach the provider.
39
+
8
40
  ## [4.0.3] - 2026-10-09
9
41
 
10
42
  ### Changed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: eq-chatbot-core
3
- Version: 4.0.3
3
+ Version: 4.2.0
4
4
  Summary: Core library for LLM chatbot integration with multi-provider support (OpenAI, Anthropic, LangDock, OpenRouter, Mammouth, LiteLLM, IONOS, Melious, Privatemode, Local)
5
5
  Project-URL: Homepage, https://www.ownerp.com
6
6
  Project-URL: Documentation, https://github.com/equitania/eq-chatbot-core
@@ -83,7 +83,7 @@ Originally extracted from an Odoo 18 chatbot integration; works standalone witho
83
83
 
84
84
  - **Multi-Provider Support** — OpenAI, Anthropic, LangDock, OpenRouter, Mammouth AI, LiteLLM gateway, IONOS AI Model Hub (EU-hosted), Melious.ai (sovereign EU), Privatemode.ai (end-to-end encrypted, EU), Local (LM Studio/Ollama)
85
85
  - **Unified API** — same interface regardless of provider
86
- - **No built-in model IDs** (v4.0.0) — the model is always the caller's; whether a model accepts `temperature`, `max_completion_tokens` or `reasoning_effort` is learned from the provider at runtime
86
+ - **No built-in model IDs** (v4.0.0) — the model is always the caller's; whether a model accepts `temperature`, `max_completion_tokens` or `reasoning_effort` is learned from the provider at runtime; output limits are read from the provider's own rejection (`probe_output_limit()`, v4.1.0) and requests are capped to them; `check_model()` (v4.2.0) finds out before the first chat what a model accepts — text, tools, images — with a few small requests shaped like a chat turn, tries adjustments for rejections no rule knows, and returns what to persist
87
87
  - **Security** — Fernet encryption, prompt-injection detection (direct user input + indirect tool/RAG content), file-upload validation, race-free token-bucket rate limiting
88
88
  - **RAG Pipeline** — chunking, embeddings (incl. Melious.ai and IONOS embedders), Qdrant-backed retrieval, context-window management
89
89
  - **MCP Client** — Streamable HTTP, legacy HTTP/SSE and stdio transports, hardened against DNS rebinding, SSRF, and subprocess env injection; LAN mode for servers on the intranet
@@ -287,7 +287,7 @@ Ursprünglich aus einer Odoo-18-Chatbot-Integration extrahiert; funktioniert sta
287
287
 
288
288
  - **Multi-Provider-Unterstützung** — OpenAI, Anthropic, LangDock, OpenRouter, Mammouth AI, LiteLLM-Gateway, IONOS AI Model Hub (EU-gehostet), Melious.ai (souverän EU), Privatemode.ai (Ende-zu-Ende-verschlüsselt, EU), Local (LM Studio/Ollama)
289
289
  - **Einheitliche API** — gleiche Schnittstelle unabhängig vom Provider
290
- - **Keine eingebauten Modell-IDs** (v4.0.0) — das Modell kommt immer vom Aufrufer; ob ein Modell `temperature`, `max_completion_tokens` oder `reasoning_effort` annimmt, lernt die Bibliothek zur Laufzeit vom Anbieter
290
+ - **Keine eingebauten Modell-IDs** (v4.0.0) — das Modell kommt immer vom Aufrufer; ob ein Modell `temperature`, `max_completion_tokens` oder `reasoning_effort` annimmt, lernt die Bibliothek zur Laufzeit vom Anbieter; `check_model()` (v4.2.0) prüft vor dem ersten Chat mit wenigen kleinen Anfragen in Chat-Form, was ein Modell annimmt – Text, Werkzeuge, Bilder –, probiert bei unbekannten Ablehnungen selbst Anpassungen aus und liefert, was gespeichert werden sollte
291
291
  - **Sicherheit** — Fernet-Verschlüsselung, Prompt-Injection-Erkennung (direkte Nutzereingaben + indirekte Tool-/RAG-Inhalte), File-Upload-Validierung, Race-freies Token-Bucket-Rate-Limiting
292
292
  - **RAG-Pipeline** — Chunking, Embeddings (inkl. Melious.ai- und IONOS-Embedder), Qdrant-basiertes Retrieval, Context-Window-Management
293
293
  - **MCP-Client** — Streamable HTTP, älteres HTTP/SSE und stdio als Transports, gehärtet gegen DNS-Rebinding, SSRF und Subprocess-Env-Injection; LAN-Modus für Server im Intranet
@@ -22,7 +22,7 @@ Originally extracted from an Odoo 18 chatbot integration; works standalone witho
22
22
 
23
23
  - **Multi-Provider Support** — OpenAI, Anthropic, LangDock, OpenRouter, Mammouth AI, LiteLLM gateway, IONOS AI Model Hub (EU-hosted), Melious.ai (sovereign EU), Privatemode.ai (end-to-end encrypted, EU), Local (LM Studio/Ollama)
24
24
  - **Unified API** — same interface regardless of provider
25
- - **No built-in model IDs** (v4.0.0) — the model is always the caller's; whether a model accepts `temperature`, `max_completion_tokens` or `reasoning_effort` is learned from the provider at runtime
25
+ - **No built-in model IDs** (v4.0.0) — the model is always the caller's; whether a model accepts `temperature`, `max_completion_tokens` or `reasoning_effort` is learned from the provider at runtime; output limits are read from the provider's own rejection (`probe_output_limit()`, v4.1.0) and requests are capped to them; `check_model()` (v4.2.0) finds out before the first chat what a model accepts — text, tools, images — with a few small requests shaped like a chat turn, tries adjustments for rejections no rule knows, and returns what to persist
26
26
  - **Security** — Fernet encryption, prompt-injection detection (direct user input + indirect tool/RAG content), file-upload validation, race-free token-bucket rate limiting
27
27
  - **RAG Pipeline** — chunking, embeddings (incl. Melious.ai and IONOS embedders), Qdrant-backed retrieval, context-window management
28
28
  - **MCP Client** — Streamable HTTP, legacy HTTP/SSE and stdio transports, hardened against DNS rebinding, SSRF, and subprocess env injection; LAN mode for servers on the intranet
@@ -226,7 +226,7 @@ Ursprünglich aus einer Odoo-18-Chatbot-Integration extrahiert; funktioniert sta
226
226
 
227
227
  - **Multi-Provider-Unterstützung** — OpenAI, Anthropic, LangDock, OpenRouter, Mammouth AI, LiteLLM-Gateway, IONOS AI Model Hub (EU-gehostet), Melious.ai (souverän EU), Privatemode.ai (Ende-zu-Ende-verschlüsselt, EU), Local (LM Studio/Ollama)
228
228
  - **Einheitliche API** — gleiche Schnittstelle unabhängig vom Provider
229
- - **Keine eingebauten Modell-IDs** (v4.0.0) — das Modell kommt immer vom Aufrufer; ob ein Modell `temperature`, `max_completion_tokens` oder `reasoning_effort` annimmt, lernt die Bibliothek zur Laufzeit vom Anbieter
229
+ - **Keine eingebauten Modell-IDs** (v4.0.0) — das Modell kommt immer vom Aufrufer; ob ein Modell `temperature`, `max_completion_tokens` oder `reasoning_effort` annimmt, lernt die Bibliothek zur Laufzeit vom Anbieter; `check_model()` (v4.2.0) prüft vor dem ersten Chat mit wenigen kleinen Anfragen in Chat-Form, was ein Modell annimmt – Text, Werkzeuge, Bilder –, probiert bei unbekannten Ablehnungen selbst Anpassungen aus und liefert, was gespeichert werden sollte
230
230
  - **Sicherheit** — Fernet-Verschlüsselung, Prompt-Injection-Erkennung (direkte Nutzereingaben + indirekte Tool-/RAG-Inhalte), File-Upload-Validierung, Race-freies Token-Bucket-Rate-Limiting
231
231
  - **RAG-Pipeline** — Chunking, Embeddings (inkl. Melious.ai- und IONOS-Embedder), Qdrant-basiertes Retrieval, Context-Window-Management
232
232
  - **MCP-Client** — Streamable HTTP, älteres HTTP/SSE und stdio als Transports, gehärtet gegen DNS-Rebinding, SSRF und Subprocess-Env-Injection; LAN-Modus für Server im Intranet
@@ -1,5 +1,31 @@
1
1
  # Release Notes
2
2
 
3
+ ## Version 4.2.0 (12.10.2026)
4
+
5
+ ### [ADD]
6
+
7
+ - **Modell vorab prüfen: `check_model(model)`.** Der Verbindungstest schickte bisher eine nackte Anfrage ohne Werkzeuge, der Chat schickt immer Werkzeuge mit – so lief der Test durch, während jede Chat-Nachricht scheiterte. `check_model` schickt dagegen einige kleine Anfragen in genau der Form des Chats: Text, dann mit einem Werkzeug, dann mit einem kleinen Bild, zuletzt die Abfrage der Ausgabegrenze. Jede Anfrage ist gestreamt, hat System- und Benutzernachricht und höchstens 256 Ausgabe-Tokens; abgelehnte Anfragen kosten nichts. Das Ergebnis (`ModelCheck`) sagt je Schritt „ok“, „abgelehnt“, „kein Urteil“ (Anmeldung, Rate-Limit, Netz) oder „übersprungen“, nennt die nötigen Anpassungen, die vom Anbieter genannten Grenzen und dessen Meldung. Vorher Gelerntes wird zuerst vergessen, damit eine erneute Prüfung bemerkt, wenn der Anbieter ein Modell geändert hat.
8
+ - **Ausprobieren statt Fehlertexte deuten.** Erkennt keine Regel eine Ablehnung, sucht die Prüfung selbst: zuerst dieselbe Anfrage noch einmal (ein Gateway kann an ein gestörtes Backend geraten sein – geht sie dann durch, wird nichts gelernt), danach jede mögliche Anpassung einzeln. Was die Fehlermeldung nennt, kommt zuerst; ohne Nennung werden nur ungefährliche Anpassungen probiert (Temperatur weglassen, Nutzungsangaben im Stream weglassen, Reasoning bei Werkzeugen abschalten). Die Ausgabegrenze umbenennen oder ein eingestelltes Reasoning weglassen geschieht nur, wenn die Meldung es nennt. Bei Anmelde-, Rate-Limit-, Überlast- und Netzfehlern bricht die Suche sofort ab. Im Chat selbst wird nie gesucht. Live geprüft am 12.10.2026: Ohne die Regel aus 4.1.1 fand die Prüfung für gpt-6-luna die nötige Anpassung allein.
9
+ - **Gelerntes speichern und zurückgeben:** `learned_adjustments(model)` und `seed_adjustments(model, namen)`. Wer die Liste speichert und nach einem Neustart zurückgibt, hat sofort die richtige erste Anfrage.
10
+ - **`param_learning.is_rejection(error)`** sagt, ob der Anbieter die Anfrage so abgelehnt hat (HTTP 400/422 oder Fehlerereignis im Stream), auch durch einen `ProviderError` hindurch.
11
+ - **Neue lernbare Anpassung `stream_usage`:** lässt `stream_options` weg, für Server, die im Stream keine Token-Nutzung melden wollen.
12
+
13
+ ### [FIX]
14
+
15
+ - **Werkzeuge mit Modellen, die von sich aus „nachdenken“.** Manche OpenAI-Modelle arbeiten standardmäßig mit Reasoning und lehnen Werkzeuge ab, solange es aktiv ist. Jede `/chat/completions`-Anfrage mit Werkzeugen kam mit HTTP 400 zurück („Function tools with reasoning_effort are not supported … set reasoning_effort to 'none'“), auch ohne gesendetes `reasoning_effort`. Ein Chat, der immer Werkzeuge mitschickt, scheiterte daher bei jeder Nachricht, während der Verbindungstest ohne Werkzeuge durchlief. Jetzt wird die Anfrage einmal mit `reasoning_effort="none"` wiederholt und das nach Erfolg für Endpunkt und Modell gemerkt. Das gilt nur für Anfragen mit Werkzeugen; ohne Werkzeuge denkt das Modell weiter nach. Live geprüft am 12.10.2026.
16
+
17
+ ## Version 4.1.0 (12.10.2026)
18
+
19
+ ### [ADD]
20
+
21
+ - **Ausgabegrenze beim Anbieter abfragen:** `probe_output_limit(model)` schickt eine Anfrage mit einer Ausgabegrenze weit über jeder echten (10 Millionen Tokens). Der Anbieter lehnt sie ab und nennt dabei die echte Grenze. Das kostet nichts, und die Grenze wird gemerkt. Nimmt der Anbieter die Anfrage doch an, wird der Stream nach dem ersten Abschnitt geschlossen. Nennt er keine Zahl (Melious), bleibt die Grenze unbekannt. Live geprüft am 12.10.2026: OpenAI gpt-4o 16384, gpt-4.1-mini 32768, gpt-6-luna 128000; Anthropic claude-haiku-5-5 128000.
22
+ - **`learned_limits(model)`** liefert, was eine Ablehnung oder Abfrage für Endpunkt und API-Key genannt hat (`max_output_tokens`, `context_length`). Das Gedächtnis lebt nur im Prozess; wer die Werte behalten will, speichert sie selbst.
23
+
24
+ ### [CHG]
25
+
26
+ - **Zu große Ausgabegrenze wird gekürzt statt abgelehnt.** Lehnt der Anbieter eine Anfrage wegen der Ausgabegrenze ab, geht sie einmal mit der genannten Grenze erneut raus, und die Grenze wird gemerkt; spätere Anfragen werden vorab gekürzt. Nennt eine Kontext-Ablehnung die Eingabe-Tokens (vLLM, ältere OpenAI-Fassung), geht die Anfrage mit dem verbleibenden Platz erneut raus. Eine Kontext-Ablehnung wegen zu langer Eingabe bleibt ein `ContextLengthError`; die genannte Kontextlänge wird gemerkt.
27
+ - **Modellliste ergänzt gelernte Grenzen**, wo der Endpunkt keine meldet; gemeldete Werte bleiben.
28
+
3
29
  ## Version 4.0.3 (09.10.2026)
4
30
 
5
31
  ### [CHG]
@@ -179,6 +179,7 @@ from eq_chatbot_core.providers.base import ( # noqa: E402
179
179
  ContextLengthError,
180
180
  ImageResult,
181
181
  LLMResponse,
182
+ ModelCheck,
182
183
  ModelInfo,
183
184
  ModelNotSpecifiedError,
184
185
  OverloadedError,
@@ -202,6 +203,7 @@ __all__ = [
202
203
  "ImageResult",
203
204
  "StreamChunk",
204
205
  "ModelInfo",
206
+ "ModelCheck",
205
207
  "ProviderError",
206
208
  "ModelNotSpecifiedError",
207
209
  "RateLimitError",
@@ -9,7 +9,13 @@ from collections.abc import Iterator
9
9
  from contextlib import ExitStack
10
10
  from typing import Any
11
11
 
12
- from eq_chatbot_core.providers.anthropic_shared import create_message, list_anthropic_models, open_message_stream
12
+ from eq_chatbot_core.providers import param_learning
13
+ from eq_chatbot_core.providers.anthropic_shared import (
14
+ ANTHROPIC_LEARNABLE,
15
+ create_message,
16
+ list_anthropic_models,
17
+ open_message_stream,
18
+ )
13
19
  from eq_chatbot_core.providers.base import (
14
20
  AuthenticationError,
15
21
  BaseLLMProvider,
@@ -536,6 +542,44 @@ class AnthropicProvider(BaseLLMProvider):
536
542
  if last_error:
537
543
  raise self._handle_error(last_error) from last_error
538
544
 
545
+ def _limit_scope(self) -> str | None:
546
+ return self._learning_scope(self._endpoint())
547
+
548
+ def _check_image_part(self, png_base64: str) -> dict[str, Any]:
549
+ """The Messages API's own image block (``_convert_messages`` passes user content through)."""
550
+ return {"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": png_base64}}
551
+
552
+ def probe_output_limit(self, model: str | None = None) -> int | None:
553
+ """Ask for the output limit with an oversized streaming request (see the base class).
554
+
555
+ The Models API reports the limit too (``list_models``); the probe covers
556
+ endpoints that do not serve it.
557
+ """
558
+ model = self.resolve_model(model)
559
+ known = super().probe_output_limit(model)
560
+ if known:
561
+ return known
562
+ params: dict[str, Any] = {
563
+ "model": model,
564
+ "messages": [{"role": "user", "content": "OK"}],
565
+ "max_tokens": self.PROBE_MAX_TOKENS,
566
+ }
567
+ try:
568
+ with ExitStack() as stack:
569
+ param_learning.call_with_learning(
570
+ lambda: stack.enter_context(self.client.messages.stream(**params)),
571
+ self._limit_scope() or "",
572
+ params,
573
+ provider=self.provider_name,
574
+ logger=logger,
575
+ only=ANTHROPIC_LEARNABLE,
576
+ cap=False,
577
+ )
578
+ except Exception as error:
579
+ return self._probe_outcome(model, error)
580
+ logger.info("%s: model %s accepted the probe's output limit; limit stays unknown", self.provider_name, model)
581
+ return None
582
+
539
583
  def list_models(self) -> list[dict[str, Any]]:
540
584
  """
541
585
  List the models the Anthropic Models API reports, with the limits and
@@ -140,6 +140,84 @@ def normalize_tools(
140
140
  return [tool.to_chat_tool() if isinstance(tool, ToolDefinition) else dict(tool) for tool in tools]
141
141
 
142
142
 
143
+ # --- check_model -----------------------------------------------------------------
144
+
145
+ CHECK_STATES = ("ok", "refused", "error", "skipped")
146
+
147
+
148
+ @dataclass
149
+ class ModelCheck:
150
+ """What ``check_model`` found out about one model on one endpoint.
151
+
152
+ Each step is ``"ok"`` (the provider accepted the request), ``"refused"`` (it
153
+ rejected the request even after the adjustments it allows were tried),
154
+ ``"error"`` (no verdict: authentication, rate limit, network) or ``"skipped"``.
155
+ """
156
+
157
+ model: str
158
+ text: str = "skipped"
159
+ """A plain streamed answer, sent the way a chat sends it."""
160
+
161
+ tools: str = "skipped"
162
+ """The same with one function tool."""
163
+
164
+ vision: str = "skipped"
165
+ """The same with a small image."""
166
+
167
+ adjustments: list[str] = field(default_factory=list)
168
+ """Request adjustments this model needs (``param_learning.LEARNABLE`` names).
169
+ Persist them and hand them back with ``seed_adjustments`` after a restart."""
170
+
171
+ limits: dict[str, int] = field(default_factory=dict)
172
+ """Token limits the provider named (``max_output_tokens``, ``context_length``)."""
173
+
174
+ messages: dict[str, str] = field(default_factory=dict)
175
+ """The provider's message per step that was not ``"ok"`` (secrets scrubbed)."""
176
+
177
+ @property
178
+ def ok(self) -> bool:
179
+ """The model answers at all."""
180
+ return self.text == "ok"
181
+
182
+
183
+ # Output limit of a check request: enough for a reasoning model to finish a
184
+ # one-word answer, small enough that a check costs next to nothing.
185
+ CHECK_MAX_TOKENS = 256
186
+ CHECK_SYSTEM = "This is an automated capability check. Answer in one word."
187
+ CHECK_TOOL: dict[str, Any] = {
188
+ "type": "function",
189
+ "function": {
190
+ "name": "get_time",
191
+ "description": "Returns the current time in a time zone.",
192
+ "parameters": {
193
+ "type": "object",
194
+ "properties": {"timezone": {"type": "string", "description": "IANA time zone, e.g. Europe/Berlin"}},
195
+ },
196
+ },
197
+ }
198
+
199
+
200
+ def check_image_png() -> str:
201
+ """A 32x32 grey PNG, base64 — small, but not below the minimum size vision models accept."""
202
+ import base64
203
+ import struct
204
+ import zlib
205
+
206
+ width = height = 32
207
+ rows = b"".join(b"\x00" + b"\x80\x80\x80" * width for _ in range(height))
208
+
209
+ def chunk(kind: bytes, data: bytes) -> bytes:
210
+ return struct.pack(">I", len(data)) + kind + data + struct.pack(">I", zlib.crc32(kind + data) & 0xFFFFFFFF)
211
+
212
+ png = (
213
+ b"\x89PNG\r\n\x1a\n"
214
+ + chunk(b"IHDR", struct.pack(">IIBBBBB", width, height, 8, 2, 0, 0, 0))
215
+ + chunk(b"IDAT", zlib.compress(rows))
216
+ + chunk(b"IEND", b"")
217
+ )
218
+ return base64.b64encode(png).decode("ascii")
219
+
220
+
143
221
  class BaseLLMProvider(ABC):
144
222
  """
145
223
  Abstract base class for LLM providers.
@@ -315,6 +393,191 @@ class BaseLLMProvider(ABC):
315
393
  provider=self.provider_name,
316
394
  )
317
395
 
396
+ # Output limit sent by probe_output_limit(): above every model's real limit, so
397
+ # the provider rejects the request and names the limit instead of generating.
398
+ PROBE_MAX_TOKENS: int = 10_000_000
399
+
400
+ def _limit_scope(self) -> str | None:
401
+ """The ``param_learning`` scope that holds this provider's learned limits.
402
+
403
+ ``None`` for providers that learn nothing at runtime.
404
+ """
405
+ return None
406
+
407
+ def learned_limits(self, model: str | None = None) -> dict[str, int]:
408
+ """Limits a rejection stated for ``model`` on this endpoint and API key.
409
+
410
+ Keys are ``max_output_tokens`` and ``context_length``; a key is present
411
+ only when the provider named the number (in a rejection or a probe). The
412
+ memory lives in this process only — persist the values to keep them.
413
+ """
414
+ scope = self._limit_scope()
415
+ if scope is None:
416
+ return {}
417
+ from eq_chatbot_core.providers import param_learning # local: providers/__init__ imports this module
418
+
419
+ return param_learning.learned_limits(scope, self.resolve_model(model))
420
+
421
+ def probe_output_limit(self, model: str | None = None) -> int | None:
422
+ """The model's output limit, asked from the provider without generating text.
423
+
424
+ Providers that support it send one request with an output limit far above
425
+ any real one (``PROBE_MAX_TOKENS``); the provider rejects it and names the
426
+ limit, which costs nothing and is remembered like a learned limit. Returns
427
+ ``None`` when the provider accepts the request (it is closed at once) or
428
+ rejects it without naming a number. A limit learned earlier is returned
429
+ without a request. The base implementation sends nothing.
430
+
431
+ Raises:
432
+ ProviderError: On errors other than the rejection (authentication,
433
+ rate limit, network).
434
+ """
435
+ return self.learned_limits(model).get("max_output_tokens")
436
+
437
+ def _probe_outcome(self, model: str, error: Exception) -> int | None:
438
+ """Result of a probe request that raised ``error``: the stated limit, ``None``, or a raise."""
439
+ limit = self.learned_limits(model).get("max_output_tokens")
440
+ if limit:
441
+ return limit
442
+ status = getattr(error, "status_code", None)
443
+ # A rejection without a number: HTTP 400/422, or an error event inside the
444
+ # stream (no status, but a body — unlike a connection error).
445
+ if status in (400, 422) or (status is None and getattr(error, "body", None) is not None):
446
+ return None
447
+ handle_error = getattr(self, "_handle_error", None)
448
+ if isinstance(error, ProviderError) or handle_error is None:
449
+ raise error
450
+ raise handle_error(error) from error
451
+
452
+ # --- learned adjustments ------------------------------------------------------
453
+
454
+ def learned_adjustments(self, model: str | None = None) -> list[str]:
455
+ """Request adjustments learned for ``model`` on this endpoint and API key.
456
+
457
+ Names from ``param_learning.LEARNABLE``. The memory lives in this process
458
+ only — persist the list (``check_model`` returns it) and restore it with
459
+ ``seed_adjustments``.
460
+ """
461
+ scope = self._limit_scope()
462
+ if scope is None:
463
+ return []
464
+ from eq_chatbot_core.providers import param_learning # local: providers/__init__ imports this module
465
+
466
+ return param_learning.learned_adjustments(scope, self.resolve_model(model))
467
+
468
+ def seed_adjustments(self, model: str, adjustments: "list[str] | tuple[str, ...]") -> None:
469
+ """Restore adjustments persisted from an earlier ``check_model`` or ``learned_adjustments``."""
470
+ scope = self._limit_scope()
471
+ if scope is None or not adjustments:
472
+ return
473
+ from eq_chatbot_core.providers import param_learning # local: providers/__init__ imports this module
474
+
475
+ param_learning.seed_adjustments(scope, model, adjustments)
476
+
477
+ # --- check_model ----------------------------------------------------------------
478
+
479
+ def check_model(
480
+ self,
481
+ model: str | None = None,
482
+ *,
483
+ temperature: float | None = 0.7,
484
+ max_tokens: int | None = None,
485
+ tools: bool = True,
486
+ vision: bool = True,
487
+ probe_limit: bool = True,
488
+ **kwargs: Any,
489
+ ) -> ModelCheck:
490
+ """Find out what ``model`` accepts, with a few small requests, before a chat needs it.
491
+
492
+ Steps, each a streamed request shaped like a chat turn (system and user
493
+ message, the caller's ``temperature`` and extra ``kwargs``, an output limit
494
+ of at most ``CHECK_MAX_TOKENS``): plain text, then with one function tool
495
+ (``tools``), then with a small image (``vision``). Tools and image are
496
+ only tried once plain text works. Finally the output limit is asked for
497
+ (``probe_limit``, see ``probe_output_limit``).
498
+
499
+ A rejection the library does not recognise is explored: the request is
500
+ tried once more unchanged, then with each adjustment the error suggests
501
+ (see ``param_learning.exploring``). What works is remembered and returned
502
+ in ``ModelCheck.adjustments``. Adjustments learned earlier are forgotten
503
+ first, so a model the provider has changed is noticed.
504
+
505
+ Cost: the plain step and each accepted step generate at most a few
506
+ hundred tokens; refused requests are not generated at all.
507
+
508
+ Never raises for a provider's answer; a missing model raises
509
+ ``ModelNotSpecifiedError``.
510
+ """
511
+ model = self.resolve_model(model)
512
+ from eq_chatbot_core.providers import param_learning # local: providers/__init__ imports this module
513
+
514
+ scope = self._limit_scope()
515
+ if scope is not None:
516
+ param_learning.forget_adjustments(scope, model)
517
+ result = ModelCheck(model=model)
518
+ limit = min(max_tokens or CHECK_MAX_TOKENS, CHECK_MAX_TOKENS)
519
+ system = {"role": "system", "content": CHECK_SYSTEM}
520
+
521
+ def step(name: str, user_content: Any, step_tools: list[dict[str, Any]] | None) -> str:
522
+ messages = [system, {"role": "user", "content": user_content}]
523
+ state, message = self._check_step(model, messages, temperature, limit, step_tools, kwargs)
524
+ setattr(result, name, state)
525
+ if message:
526
+ result.messages[name] = message
527
+ return state
528
+
529
+ if step("text", "Reply with OK.", None) == "ok":
530
+ if tools:
531
+ step("tools", "What time is it in Berlin? Use the tool if you can.", [CHECK_TOOL])
532
+ if vision:
533
+ image = self._check_image_part(check_image_png())
534
+ step("vision", [{"type": "text", "text": "Which colour is this image?"}, image], None)
535
+ if probe_limit:
536
+ try:
537
+ self.probe_output_limit(model)
538
+ except Exception as error: # noqa: BLE001 - the limit simply stays unknown
539
+ result.messages["limit"] = self._check_message(error)
540
+ if scope is not None:
541
+ result.adjustments = param_learning.learned_adjustments(scope, model)
542
+ result.limits = param_learning.learned_limits(scope, model)
543
+ return result
544
+
545
+ def _check_step(
546
+ self,
547
+ model: str,
548
+ messages: list[dict[str, Any]],
549
+ temperature: float | None,
550
+ max_tokens: int,
551
+ tools: list[dict[str, Any]] | None,
552
+ kwargs: dict[str, Any],
553
+ ) -> tuple[str, str]:
554
+ """One check request, streamed to the end; ``(state, provider message)``."""
555
+ from eq_chatbot_core.providers import param_learning # local: providers/__init__ imports this module
556
+
557
+ call_kwargs = dict(kwargs)
558
+ if temperature is not None:
559
+ call_kwargs["temperature"] = temperature
560
+ with param_learning.exploring():
561
+ try:
562
+ for _chunk in self.stream_completion(
563
+ messages, model=model, max_tokens=max_tokens, tools=tools, **call_kwargs
564
+ ):
565
+ pass
566
+ except Exception as error: # noqa: BLE001 - the verdict is the result
567
+ state = "refused" if param_learning.is_rejection(error) else "error"
568
+ return state, self._check_message(error)
569
+ return "ok", ""
570
+
571
+ @staticmethod
572
+ def _check_message(error: BaseException) -> str:
573
+ from eq_chatbot_core.utils.secret_scrub import scrub_secrets
574
+
575
+ return scrub_secrets(str(error))[:500]
576
+
577
+ def _check_image_part(self, png_base64: str) -> dict[str, Any]:
578
+ """The image of the vision step, in the message format this provider expects."""
579
+ return {"type": "image_url", "image_url": {"url": f"data:image/png;base64,{png_base64}"}}
580
+
318
581
  def __repr__(self) -> str:
319
582
  return f"{self.__class__.__name__}(provider={self.provider_name})"
320
583
 
@@ -414,6 +677,7 @@ __all__ = [
414
677
  "StreamChunk",
415
678
  "ToolDefinition",
416
679
  "ModelInfo",
680
+ "ModelCheck",
417
681
  "BaseLLMProvider",
418
682
  "ProviderError",
419
683
  "ModelNotSpecifiedError",
@@ -272,6 +272,22 @@ class LangDockProvider(BaseLLMProvider):
272
272
  return f"{self.base_url}{pattern.format(region=self.region)}"
273
273
  return f"{self.base_url}{pattern}"
274
274
 
275
+ def _limit_scope(self) -> str | None:
276
+ # The agent backend's model is configured in LangDock; nothing is learned there.
277
+ return None if self.backend == "agent" else self._learning_scope(self._get_backend_url())
278
+
279
+ def _check_image_part(self, png_base64: str) -> dict[str, Any]:
280
+ """The anthropic backend takes the Messages API's image block, the others OpenAI's."""
281
+ if self.backend == "anthropic":
282
+ return {"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": png_base64}}
283
+ return super()._check_image_part(png_base64)
284
+
285
+ def probe_output_limit(self, model: str | None = None) -> int | None:
286
+ """Probe on the openai backend (see the base class); other backends return what was learned."""
287
+ if self.backend == "openai":
288
+ return self._get_openai_backend().probe_output_limit(model)
289
+ return super().probe_output_limit(model)
290
+
275
291
  @property
276
292
  def http_client(self) -> httpx2.Client:
277
293
  """Get or create HTTP client for direct API calls."""
@@ -51,16 +51,37 @@ def _prime_stream(stream: Any) -> Iterator[Any]:
51
51
  the first read fails, so a retry does not leave a connection open.
52
52
  """
53
53
  iterator = iter(stream)
54
+ read: list[Any] = []
54
55
  try:
55
- first = next(iterator)
56
+ while True:
57
+ chunk = next(iterator)
58
+ read.append(chunk)
59
+ # While a model is checked (param_learning.exploring), read on to the
60
+ # first chunk that carries an answer: some gateways report a refusal
61
+ # after an empty opening chunk, and only a refusal inside the retry
62
+ # loop can be explored.
63
+ if not param_learning.is_exploring() or _carries_answer(chunk):
64
+ break
56
65
  except StopIteration:
57
- return iter(())
66
+ pass
58
67
  except BaseException:
59
68
  close = getattr(stream, "close", None)
60
69
  if close is not None:
61
70
  close()
62
71
  raise
63
- return itertools.chain((first,), iterator)
72
+ return itertools.chain(read, iterator)
73
+
74
+
75
+ def _carries_answer(chunk: Any) -> bool:
76
+ for choice in getattr(chunk, "choices", None) or ():
77
+ delta = getattr(choice, "delta", None)
78
+ if (
79
+ getattr(choice, "finish_reason", None)
80
+ or getattr(delta, "content", None)
81
+ or getattr(delta, "tool_calls", None)
82
+ ):
83
+ return True
84
+ return False
64
85
 
65
86
 
66
87
  class OpenAICompatibleProvider(BaseLLMProvider):
@@ -254,6 +275,47 @@ class OpenAICompatibleProvider(BaseLLMProvider):
254
275
  logger=_logger,
255
276
  )
256
277
 
278
+ def _limit_scope(self) -> str | None:
279
+ return self._learning_scope(self._effective_base_url)
280
+
281
+ def probe_output_limit(self, model: str | None = None) -> int | None:
282
+ """Ask for the output limit with an oversized streaming request (see the base class).
283
+
284
+ Streaming, so that a provider which accepts the request is cut off after
285
+ the first chunk instead of generating up to ``PROBE_MAX_TOKENS``.
286
+ """
287
+ model = self.resolve_model(model)
288
+ known = super().probe_output_limit(model)
289
+ if known:
290
+ return known
291
+ params = self._build_params([{"role": "user", "content": "OK"}], model, 0.7, self.PROBE_MAX_TOKENS, None)
292
+ params["stream"] = True
293
+ opened: list[Any] = []
294
+
295
+ def send() -> Any:
296
+ response = self.client.chat.completions.create(**params)
297
+ opened.append(response)
298
+ return _prime_stream(response)
299
+
300
+ try:
301
+ param_learning.call_with_learning(
302
+ send,
303
+ self._limit_scope() or "",
304
+ params,
305
+ provider=self.provider_name,
306
+ logger=_logger,
307
+ cap=False,
308
+ )
309
+ except Exception as error:
310
+ return self._probe_outcome(model, error)
311
+ finally:
312
+ for response in opened:
313
+ close = getattr(response, "close", None)
314
+ if close is not None:
315
+ close()
316
+ _logger.info("%s: model %s accepted the probe's output limit; limit stays unknown", self.provider_name, model)
317
+ return None
318
+
257
319
  def chat_completion(
258
320
  self,
259
321
  messages: list[dict[str, Any]],