mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-12 22:42:13 +02:00
fix: address code review feedback for STT implementation
- Add header to local STT transcription for consistency - Add empty text validation for external STT path - Refactor external STT to eliminate duplication in atranscription calls - Ensure both local and external paths have consistent error handling
This commit is contained in:
parent
15ba2b86f6
commit
9b72ec65b5
1 changed files with 16 additions and 12 deletions
|
|
@ -798,6 +798,11 @@ async def process_file_in_background(
|
||||||
|
|
||||||
if not transcribed_text:
|
if not transcribed_text:
|
||||||
raise ValueError("Transcription returned empty text")
|
raise ValueError("Transcription returned empty text")
|
||||||
|
|
||||||
|
# Add metadata about the transcription
|
||||||
|
transcribed_text = (
|
||||||
|
f"# Transcription of {filename}\n\n{transcribed_text}"
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=422,
|
status_code=422,
|
||||||
|
|
@ -817,23 +822,22 @@ async def process_file_in_background(
|
||||||
else:
|
else:
|
||||||
# Use LiteLLM for audio transcription
|
# Use LiteLLM for audio transcription
|
||||||
with open(file_path, "rb") as audio_file:
|
with open(file_path, "rb") as audio_file:
|
||||||
|
transcription_kwargs = {
|
||||||
|
"model": app_config.STT_SERVICE,
|
||||||
|
"file": audio_file,
|
||||||
|
"api_key": app_config.STT_SERVICE_API_KEY,
|
||||||
|
}
|
||||||
if app_config.STT_SERVICE_API_BASE:
|
if app_config.STT_SERVICE_API_BASE:
|
||||||
transcription_response = await atranscription(
|
transcription_kwargs["api_base"] = app_config.STT_SERVICE_API_BASE
|
||||||
model=app_config.STT_SERVICE,
|
|
||||||
file=audio_file,
|
transcription_response = await atranscription(**transcription_kwargs)
|
||||||
api_base=app_config.STT_SERVICE_API_BASE,
|
|
||||||
api_key=app_config.STT_SERVICE_API_KEY,
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
transcription_response = await atranscription(
|
|
||||||
model=app_config.STT_SERVICE,
|
|
||||||
api_key=app_config.STT_SERVICE_API_KEY,
|
|
||||||
file=audio_file,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Extract the transcribed text
|
# Extract the transcribed text
|
||||||
transcribed_text = transcription_response.get("text", "")
|
transcribed_text = transcription_response.get("text", "")
|
||||||
|
|
||||||
|
if not transcribed_text:
|
||||||
|
raise ValueError("Transcription returned empty text")
|
||||||
|
|
||||||
# Add metadata about the transcription
|
# Add metadata about the transcription
|
||||||
transcribed_text = (
|
transcribed_text = (
|
||||||
f"# Transcription of {filename}\n\n{transcribed_text}"
|
f"# Transcription of {filename}\n\n{transcribed_text}"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue