Repository navigation
Conversation
|
Mistral provider has been tested on the same snippet as https://python.useinstructor.com/concepts/batch/#in-memory-processing: import time
from instructor.batch import BatchProcessor, extract_results
from pydantic import BaseModel
class User(BaseModel):
name: str
age: int
processor = BatchProcessor("mistral/mistral-small-latest", User)
messages_list = [
[
{"role": "system", "content": "Extract user information from text."},
{"role": "user", "content": "Hi, I'm Alice and I'm 28 years old."},
],
[
{"role": "system", "content": "Extract user information from text."},
{"role": "user", "content": "Hello, I'm Bob, 35 years old."},
],
]
# Create batch file
processor.create_batch_from_messages(
file_path="batch_requests.jsonl",
messages_list=messages_list,
max_tokens=100000,
temperature=0.1,
)
# Submit batch job
batch_id = processor.submit_batch("batch_requests.jsonl")
print(f"Batch job submitted: {batch_id}")
# Check status and retrieve results
status = processor.get_batch_status(batch_id)
while status["status"] not in ["SUCCESS", "FAILED", "CANCELLED"]:
status = processor.get_batch_status(batch_id)
time.sleep(10)
print(f"Job status {status['status']}")
all_results = processor.retrieve_results(batch_id)
extracted_results = extract_results(all_results)
for user in extracted_results:
print(f"Name: {user.name}, Age: {user.age}")
# Name: Alice, Age: 28
# Name: Bob, Age: 35 |
## Summary - accumulate declared, nested, and unknown numeric OpenAI/Anthropic usage fields across retries while preserving non-numeric metadata - add corrective feedback when a Responses API retry receives no tool call - preserve raw iterable type hints through sync and async v2 parallel-tool wrappers - strengthen API-key-free coverage for current and future SDK usage counters ## Consolidated and superseded items - closes #2493 - consolidates contributor work from #2498, #2500, and #2501 with original commit authorship preserved - supersedes #2497 because it drops unknown `model_extra` counters - supersedes #2499 because its hand-maintained provider field lists would drift as SDKs evolve ## Validation - focused changed-surface suite: `110 passed` - broad offline v2/coverage suite: `2368 passed, 91 skipped, 73 deselected` - Ruff check and format check: passed - scoped `ty check`: passed - `uv lock --check`: passed - pre-commit hooks and `git diff --check`: passed The 73 deselected tests require live provider credentials. An unfiltered local run confirmed its 22 failures were provider network connections in the restricted environment; GitHub provider jobs remain the authoritative validation for those paths. ## Intentionally skipped - provider additions or expansions: #2436, #2435, #2423, #2409, #2384, #2322, #2306, #2298, #2283, #2168, #2086; issues #2408, #2383, #2365, #2260, #2084, #2076 - broad architecture, product, security, or streaming decisions: #2394, #2392, #2357, #2356, #2355, #2351, #2321, #2307, #2287, #2263; issues #2479, #2403, #2393, #2391, #2316, #2272, #2056 - dependency batch: #2433 - nontrivial examples and editorial/resource additions: #2468, #2405, #2401, #2354, #2346, #2311, #2305; issue #2404 These remain open because they need dedicated product, architecture, provider, security, dependency, or editorial review and are not required for the `1.15.5` patch release. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Changes retry usage totals and reask message content on failure paths; scope is limited and heavily covered by tests, with no auth or data-store changes. > > **Overview** > Bundles three v2 retry and wrapper fixes for a patch release. > > **Retry usage accounting** replaces hand-maintained token field sums with generic `_accumulate_models` on Pydantic usage objects. Numeric fields (including nested models and `model_extra` counters) add across retries; booleans and other non-numeric metadata are not treated as billable. OpenAI and Anthropic paths share this logic. > > **OpenAI Responses reask** appends a user correction when `RESPONSES_TOOLS` validation fails but the output has no tool calls (e.g. reasoning-only), so retries include feedback instead of repeating the same request. > > **Parallel tools** in `patch_v2` skips `prepare_response_model` and does not replace `response_model` with the handler’s prepared wrapper for parallel modes, keeping raw `Iterable[...]` hints so schemas and parsed results include every member type. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit bbddca1. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
|
Closing this PR as a stale patch that would regress the current provider matrix. It is explicitly limited to |
|
ok thanks for your feedback I will take them into account and do the PR again. |
Supports for calling MistralAI batch API. The modification does not impact other aspects of the library.
Usage is similar as openai/anthropic
Currently only support
mistralai<2.0.0as mentionned in #2137Tested with
instructor==1.14.5