Skip to content

Commit

Permalink
fix: added support for wav files using urls
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanleomk committed Oct 20, 2024
1 parent 8e50684 commit 930b34b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion instructor/multimodal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path
from pydantic import BaseModel, Field
from .mode import Mode
import requests


class Image(BaseModel):
Expand Down Expand Up @@ -90,7 +91,10 @@ class Audio(BaseModel):
def from_url(cls, url: str) -> Audio:
"""Create an Audio instance from a URL."""
assert url.endswith(".wav"), "Audio must be in WAV format"
return cls(source=url, data=None)

response = requests.get(url)
data = base64.b64encode(response.content).decode("utf-8")
return cls(source=url, data=data)

@classmethod
def from_path(cls, path: str | Path) -> Audio:
Expand Down

0 comments on commit 930b34b

Please sign in to comment.