refac
This commit is contained in:
@@ -639,13 +639,14 @@ def transcription_handler(request, file_path, metadata, user=None):
|
|||||||
if user and ENABLE_FORWARD_USER_INFO_HEADERS:
|
if user and ENABLE_FORWARD_USER_INFO_HEADERS:
|
||||||
headers = include_user_info_headers(headers, user)
|
headers = include_user_info_headers(headers, user)
|
||||||
|
|
||||||
r = requests.post(
|
with open(file_path, "rb") as audio_file:
|
||||||
url=f"{request.app.state.config.STT_OPENAI_API_BASE_URL}/audio/transcriptions",
|
r = requests.post(
|
||||||
headers=headers,
|
url=f"{request.app.state.config.STT_OPENAI_API_BASE_URL}/audio/transcriptions",
|
||||||
files={"file": (filename, open(file_path, "rb"))},
|
headers=headers,
|
||||||
data=payload,
|
files={"file": (filename, audio_file)},
|
||||||
timeout=AIOHTTP_CLIENT_TIMEOUT,
|
data=payload,
|
||||||
)
|
timeout=AIOHTTP_CLIENT_TIMEOUT,
|
||||||
|
)
|
||||||
|
|
||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
# Successful transcription
|
# Successful transcription
|
||||||
|
|||||||
@@ -228,22 +228,23 @@ async def upload_pipeline(
|
|||||||
headers = {"Authorization": f"Bearer {key}"}
|
headers = {"Authorization": f"Bearer {key}"}
|
||||||
|
|
||||||
async with aiohttp.ClientSession(trust_env=True) as session:
|
async with aiohttp.ClientSession(trust_env=True) as session:
|
||||||
form_data = aiohttp.FormData()
|
with open(file_path, "rb") as f:
|
||||||
form_data.add_field(
|
form_data = aiohttp.FormData()
|
||||||
"file",
|
form_data.add_field(
|
||||||
open(file_path, "rb"),
|
"file",
|
||||||
filename=filename,
|
f,
|
||||||
content_type="application/octet-stream",
|
filename=filename,
|
||||||
)
|
content_type="application/octet-stream",
|
||||||
|
)
|
||||||
|
|
||||||
async with session.post(
|
async with session.post(
|
||||||
f"{url}/pipelines/upload",
|
f"{url}/pipelines/upload",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
data=form_data,
|
data=form_data,
|
||||||
ssl=AIOHTTP_CLIENT_SESSION_SSL,
|
ssl=AIOHTTP_CLIENT_SESSION_SSL,
|
||||||
) as response:
|
) as response:
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
data = await response.json()
|
data = await response.json()
|
||||||
|
|
||||||
return {**data}
|
return {**data}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user