Views
No views yet


vllm (recommended): See heretemperature=0.2 and top_p=0.95 for chat completion (e.g. Audio Understanding) and temperature=0.0 for transcriptionuv:uv pip install -U "vllm[audio]" --torch-backend=auto --extra-index-url https://wheels.vllm.ai/nightlymistral_common >= 1.8.1.python -c "import mistral_common; print(mistral_common.__version__)"git clone https://github.com/vllm-project/vllm && cd vllmpython examples/offline_inference/audio_language.py --num-audios 2 --model-type voxtralvllm serve mistralai/Voxtral-Mini-3B-2507 --tokenizer_mode mistral --config_format mistral --load_format mistralmistral-common with audio installed:pip install --upgrade mistral_common\[audio\]1from mistral_common.protocol.instruct.messages import TextChunk, AudioChunk, UserMessage, AssistantMessage, RawAudio
2from mistral_common.audio import Audio
3from huggingface_hub import hf_hub_download
4
5from openai import OpenAI
6
7# Modify OpenAI's API key and API base to use vLLM's API server.
8openai_api_key = "EMPTY"
9openai_api_base = "http://<your-server-host>:8000/v1"
10
11client = OpenAI(
12 api_key=openai_api_key,
13 base_url=openai_api_base,
14)
15
16models = client.models.list()
17model = models.data[0].id
18
19obama_file = hf_hub_download("patrickvonplaten/audio_samples", "obama.mp3", repo_type="dataset")
20bcn_file = hf_hub_download("patrickvonplaten/audio_samples", "bcn_weather.mp3", repo_type="dataset")
21
22def file_to_chunk(file: str) -> AudioChunk:
23 audio = Audio.from_file(file, strict=False)
24 return AudioChunk.from_audio(audio)
25
26text_chunk = TextChunk(text="Which speaker is more inspiring? Why? How are they different from each other?")
27user_msg = UserMessage(content=[file_to_chunk(obama_file), file_to_chunk(bcn_file), text_chunk]).to_openai()
28
29print(30 * "=" + "USER 1" + 30 * "=")
30print(text_chunk.text)
31print("\n\n")
32
33response = client.chat.completions.create(
34 model=model,
35 messages=[user_msg],
36 temperature=0.2,
37 top_p=0.95,
38)
39content = response.choices[0].message.content
40
41print(30 * "=" + "BOT 1" + 30 * "=")
42print(content)
43print("\n\n")
44# The speaker who is more inspiring is the one who delivered the farewell address, as they express
45# gratitude, optimism, and a strong commitment to the nation and its citizens. They emphasize the importance of
46# self-government and active citizenship, encouraging everyone to participate in the democratic process. In contrast,
47# the other speaker provides a factual update on the weather in Barcelona, which is less inspiring as it
48# lacks the emotional and motivational content of the farewell address.
49
50# **Differences:**
51# - The farewell address speaker focuses on the values and responsibilities of citizenship, encouraging active participation in democracy.
52# - The weather update speaker provides factual information about the temperature in Barcelona, without any emotional or motivational content.
53
54
55messages = [
56 user_msg,
57 AssistantMessage(content=content).to_openai(),
58 UserMessage(content="Ok, now please summarize the content of the first audio.").to_openai()
59]
60print(30 * "=" + "USER 2" + 30 * "=")
61print(messages[-1]["content"])
62print("\n\n")
63
64response = client.chat.completions.create(
65 model=model,
66 messages=messages,
67 temperature=0.2,
68 top_p=0.95,
69)
70content = response.choices[0].message.content
71print(30 * "=" + "BOT 2" + 30 * "=")
72print(content)mistral-common with audio installed:pip install --upgrade mistral_common\[audio\]1from mistral_common.protocol.transcription.request import TranscriptionRequest
2from mistral_common.protocol.instruct.messages import RawAudio
3from mistral_common.audio import Audio
4from huggingface_hub import hf_hub_download
5
6from openai import OpenAI
7
8# Modify OpenAI's API key and API base to use vLLM's API server.
9openai_api_key = "EMPTY"
10openai_api_base = "http://<your-server-host>:8000/v1"
11
12client = OpenAI(
13 api_key=openai_api_key,
14 base_url=openai_api_base,
15)
16
17models = client.models.list()
18model = models.data[0].id
19
20obama_file = hf_hub_download("patrickvonplaten/audio_samples", "obama.mp3", repo_type="dataset")
21audio = Audio.from_file(obama_file, strict=False)
22
23audio = RawAudio.from_audio(audio)
24req = TranscriptionRequest(model=model, audio=audio, language="en", temperature=0.0).to_openai(exclude=("top_p", "seed"))
25
26response = client.audio.transcriptions.create(**req)
27print(response)