build: merging main into full-stack dev#36
Conversation
summarisation function added (call local llm) fixing the variables that are unbound to reduce errors
Added feature for using locally hosted LLMs for summarisation. Fixed existing unbound variables.
There was a problem hiding this comment.
Summary of Changes
Hello @ThePrunerator, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces a significant new feature: the ability to summarize audio transcripts using a Large Language Model (LLM). It adds a new API endpoint to trigger this summarization and includes necessary configuration updates and dependency additions. Additionally, several existing backend functions have been made more robust with improved error handling and data parsing. The PR title build: merging main into full-stack dev appears to be a misnomer, as this is clearly a feature addition rather than a simple merge.
Highlights
- LLM-Powered Transcript Summarization: Implemented a new
summarise_transcriptfunction and exposed it via a new/jobs/{uuid}/summariseAPI endpoint, allowing users to obtain concise summaries of their audio transcripts. - External LLM Configuration: Introduced new environment variables (
LLM_API_URL,LLM_MODEL_NAME) in.env.exampleto configure the external LLM service used for summarization. - Backend Robustness Improvements: Enhanced error handling and data validation across several existing API routes (
get_jobs,get_job_status,get_file_transcript) to improve the stability and reliability of the backend. - Forced CUDA Device Usage: Modified the
whispermodel's device selection to explicitly usecuda:0, removing the CPU fallback.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
The pull request introduces a new transcript summarization feature and includes several refactorings and bug fixes. The review focuses on correctness, robustness, and maintainability. Several critical and high-severity issues have been identified, such as hardcoding the compute DEVICE without a fallback and potential KeyError exceptions from unsafe dictionary access. Additionally, medium-severity suggestions cover API response consistency and safer parsing of LLM responses.
| csv_lock = Lock() | ||
| csv_file = "audiofiles/audiofiles.csv" | ||
| DEVICE = "cuda:0" if whisper.is_cuda_available() else "cpu" | ||
| DEVICE = "cuda:0" |
| Summarises the transcript for the given UUID using a defined LLM. | ||
| """ | ||
| try: | ||
| file_name = get_file_name(uuid)["file_name"] |
There was a problem hiding this comment.
The get_file_name(uuid) function can return a dictionary containing an "error" key. Directly accessing ["file_name"] without checking for the "error" key will lead to a KeyError.
file_name_response = get_file_name(uuid)
if "error" in file_name_response:
logging.error(f"Failed to get file name for UUID {uuid} in summarise_job: {file_name_response['error']}")
return {"error": f"Failed to retrieve file details for UUID {uuid} to start summarisation."}
file_name = file_name_response["file_name"]|
|
||
| except Exception as e: | ||
| timestamp = get_timestamp() | ||
| file_name = get_file_name(uuid)["file_name"] |
There was a problem hiding this comment.
| url = str(os.getenv("LLM_API_URL")) | ||
| model_name = str(os.getenv("LLM_MODEL_NAME")) |
There was a problem hiding this comment.
os.getenv() returns None if an environment variable is not set. Casting None to a string can lead to runtime errors. Check if these environment variables are set.
url = os.getenv("LLM_API_URL")
model_name = os.getenv("LLM_MODEL_NAME")
if url is None:
logging.error("LLM_API_URL environment variable is not set.")
return "Error: LLM API URL is not configured."
if model_name is None:
logging.error("LLM_MODEL_NAME environment variable is not set.")
return "Error: LLM Model Name is not configured."| resp = requests.post(url, json=payload) | ||
| resp.raise_for_status() | ||
| data = resp.json() | ||
| summary = data["choices"][0]["message"]["content"].strip() |
There was a problem hiding this comment.
Directly accessing nested keys like data["choices"][0]["message"]["content"] is prone to KeyError or IndexError if the LLM API response structure deviates. Handle potential errors.
try:
summary = data["choices"][0]["message"]["content"].strip()
except (KeyError, IndexError, TypeError) as parse_error:
logging.error(f"Error parsing LLM response: {parse_error}. Data: {data}", exc_info=True)
return "Error: Could not extract summary from LLM response."| if row and len(row) >= 2: | ||
| list_of_files[row[0]] = row[1] | ||
| if len(list_of_files) == 0: | ||
| return {"csv_list": "No audio files found."} |
| file_name = get_file_name(uuid).get("file_name", "unknown") | ||
| file_path = f"transcripts/{file_name}.txt" | ||
| if os.path.exists(file_path): | ||
| full_transcript = [] |
| logging.info(f"{timestamp}: Summarised transcript for UUID: {uuid}, file name: {file_name}") | ||
| return {"status": "success", "summary": summary} |
There was a problem hiding this comment.
The summarise_transcript function may return a string prefixed with "Error:". However, summarise_job currently returns this error string with "status": "success". The status should accurately reflect the outcome.
timestamp = get_timestamp()
if summary.startswith("Error:"):
logging.error(f"{timestamp}: Summarisation failed for UUID {uuid}, file name: {file_name}. Details: {summary}")
return {"status": "error", "message": summary}
logging.info(f"{timestamp}: Summarised transcript for UUID: {uuid}, file name: {file_name}")
return {"status": "success", "summary": summary}
No description provided.