Skip to content

build: merging main into full-stack dev#36

Merged
xenoblade246 merged 4 commits intofeat/full-stackfrom
main
Jun 19, 2025
Merged

build: merging main into full-stack dev#36
xenoblade246 merged 4 commits intofeat/full-stackfrom
main

Conversation

@xenoblade246
Copy link
Copy Markdown
Collaborator

No description provided.

incizm added 4 commits June 18, 2025 14:48
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.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_transcript function and exposed it via a new /jobs/{uuid}/summarise API 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.example to 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 whisper model's device selection to explicitly use cuda: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

  1. 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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread backend/main.py
csv_lock = Lock()
csv_file = "audiofiles/audiofiles.csv"
DEVICE = "cuda:0" if whisper.is_cuda_available() else "cpu"
DEVICE = "cuda:0"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

Hardcoding DEVICE = "cuda:0" removes the previous dynamic selection. This can cause the application to fail on systems without CUDA.

Suggested change
DEVICE = "cuda:0"
DEVICE = "cuda:0" if whisper.is_cuda_available() else "cpu"

Comment thread backend/main.py
Summarises the transcript for the given UUID using a defined LLM.
"""
try:
file_name = get_file_name(uuid)["file_name"]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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"]

Comment thread backend/main.py

except Exception as e:
timestamp = get_timestamp()
file_name = get_file_name(uuid)["file_name"]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This line re-fetches file_name by calling get_file_name(uuid)["file_name"] again within the except block. This is unsafe and redundant.

        # file_name should be sourced from the try block's scope for logging if available.
        # This redundant and unsafe call should be removed.

Comment thread backend/main.py
Comment on lines +118 to +119
url = str(os.getenv("LLM_API_URL"))
model_name = str(os.getenv("LLM_MODEL_NAME"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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."

Comment thread backend/main.py
resp = requests.post(url, json=payload)
resp.raise_for_status()
data = resp.json()
summary = data["choices"][0]["message"]["content"].strip()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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."

Comment thread backend/main.py
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."}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The csv_list field in the response dictionary changes its data type. It's better for an API field to maintain a consistent type.

            return {"csv_list": {}} # Client can check if the dict is empty

Comment thread backend/main.py
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 = []
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

full_transcript is initialized as an empty list [] but is immediately overwritten. This initialization is misleading.

        full_transcript = "" # Initialize as an empty string, or define only when read

Comment thread backend/main.py
Comment on lines +341 to +342
logging.info(f"{timestamp}: Summarised transcript for UUID: {uuid}, file name: {file_name}")
return {"status": "success", "summary": summary}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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}

@xenoblade246 xenoblade246 merged commit e898810 into feat/full-stack Jun 19, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants