mirror of
https://github.com/hwchase17/langchain
synced 2024-11-10 01:10:59 +00:00
1adaa3c662
This is a follow up to #18371. These are the changes: - New **Azure AI Services** toolkit and tools to replace those of **Azure Cognitive Services**. - Updated documentation for Microsoft platform. - The image analysis tool has been rewritten to use the new package `azure-ai-vision-imageanalysis`, doing a proper replacement of `azure-ai-vision`. These changes: - Update outdated naming from "Azure Cognitive Services" to "Azure AI Services". - Update documentation to use non-deprecated methods to create and use agents. - Removes need to depend on yanked python package (`azure-ai-vision`) There is one new dependency that is needed as a replacement to `azure-ai-vision`: - `azure-ai-vision-imageanalysis`. This is optional and declared within a function. There is a new `azure_ai_services.ipynb` notebook showing usage; Changes have been linted and formatted. I am leaving the actions of adding deprecation notices and future removal of Azure Cognitive Services up to the LangChain team, as I am not sure what the current practice around this is. --- If this PR makes it, my handle is @galo@mastodon.social --------- Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com> Co-authored-by: Bagatur <baskaryan@gmail.com> Co-authored-by: ccurme <chester.curme@gmail.com>
30 lines
776 B
Python
30 lines
776 B
Python
import os
|
|
import tempfile
|
|
from urllib.parse import urlparse
|
|
|
|
import requests
|
|
|
|
|
|
def detect_file_src_type(file_path: str) -> str:
|
|
"""Detect if the file is local or remote."""
|
|
if os.path.isfile(file_path):
|
|
return "local"
|
|
|
|
parsed_url = urlparse(file_path)
|
|
if parsed_url.scheme and parsed_url.netloc:
|
|
return "remote"
|
|
|
|
return "invalid"
|
|
|
|
|
|
def download_audio_from_url(audio_url: str) -> str:
|
|
"""Download audio from url to local."""
|
|
ext = audio_url.split(".")[-1]
|
|
response = requests.get(audio_url, stream=True)
|
|
response.raise_for_status()
|
|
with tempfile.NamedTemporaryFile(mode="wb", suffix=f".{ext}", delete=False) as f:
|
|
for chunk in response.iter_content(chunk_size=8192):
|
|
f.write(chunk)
|
|
|
|
return f.name
|