feat(batch): support for mistral api#2168
Open
vcharvet wants to merge 3 commits into567-labs:mainfrom
Open
Conversation
Author
|
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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