-
Notifications
You must be signed in to change notification settings - Fork 540
Expand file tree
/
Copy pathphi4mm_audio.py
More file actions
45 lines (39 loc) · 1.35 KB
/
phi4mm_audio.py
File metadata and controls
45 lines (39 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from mistralrs import Runner, Which, ChatCompletionRequest, VisionArchitecture
# Choose a Vision model that supports both modalities
runner = Runner(
which=Which.VisionPlain(
model_id="microsoft/Phi-4-multimodal-instruct",
arch=VisionArchitecture.Phi4MM,
),
)
# Remote media assets (swap for anything you like)
IMAGE_URL = "https://www.allaboutbirds.org/guide/assets/og/528129121-1200px.jpg"
AUDIO_URL = "https://upload.wikimedia.org/wikipedia/commons/4/42/Bird_singing.ogg"
response = runner.send_chat_completion_request(
ChatCompletionRequest(
model="default",
messages=[
{
"role": "user",
"content": [
{ # Audio clip
"type": "audio_url",
"audio_url": {"url": AUDIO_URL},
},
{ # Image
"type": "image_url",
"image_url": {"url": IMAGE_URL},
},
{
"type": "text",
"text": "Describe in detail what is happening, referencing both what you hear and what you see.",
},
],
}
],
max_tokens=256,
temperature=0.2,
top_p=0.9,
)
)
print(response.choices[0].message.content)