Repository: Pythagora-io/gpt-pilot
File: pilot/utils/describe.py (Python)

Code before:
    """
    return [
        {"role": "system", "content": DESCRIBE_PROMPT},
        {"role": "user", "content": f"Here's the `{fpath}` file:\n```\n{content}\n```\n"},
    ]


def describe_file(project, fpath: str, content: str) -> str:
    if os.getenv('FILTER_RELEVANT_FILES', '').lower().strip() not in ['true', '1', 'yes', 'on']:
        return ''

    model_name = os.getenv("MODEL_NAME")
    if model_name.startswith("gpt-4") or model_name.startswith("openai/gpt-4"):
        model_name = "gpt-3.5-turbo"
    elif model_name.startswith("claude-3") or model_name.startswith("anthropic/claude-3"):
        model_name = "claude-3-haiku-20240307"
    else:
        # Unknown default model (possibly local LLM), didsable file summaries
        return ''

    if not content or not content.strip():
        return "(empty)"

    logger.info("Calling LLM to summarize file %s", fpath)
    try:
        response_text = create_gpt_chat_completion(
            _get_describe_messages(fpath, content),
            'project_description',
            project,
            function_calls=DESCRIBE_FILE,
            temperature=0,
            model_name=model_name,
        )
        response = json.loads(response_text['text'])
        refs = (" [References: " + ", ".join(response["references"]) + "]") if response.get("references") else ""
        return f"{response['summary']}{refs}"
    except Exception as err:
        logger.error("Error summarizing %s: %s", fpath, err, exc_info=True)
        return '(unknown)'


Review comment (suggestion):
This is intentionally not using `AgentConvo` because it uses `replace_files` which saves file snapshots which calls this function...

Code after:
    """
    return [
        {"role": "system", "content": DESCRIBE_PROMPT},
        {"role": "user", "content": f"Here's the `{fpath}` file:\n```\n{content}\n```\n"},
    ]


def describe_file(project, fpath: str, content: str) -> str:
    if os.getenv('FILTER_RELEVANT_FILES', '').lower().strip() in ['false', '0', 'no', 'off']:
        return ''

    model_name = os.getenv("MODEL_NAME")
    if model_name.startswith("gpt-4") or model_name.startswith("openai/gpt-4"):
        model_name = "gpt-3.5-turbo"
    elif model_name.startswith("claude-3") or model_name.startswith("anthropic/claude-3"):
        model_name = "anthropic/claude-3-haiku-20240307"
    else:
        # Unknown default model (possibly local LLM), didsable file summaries
        return ''

    if not content or not content.strip():
        return "(empty)"

    logger.info("Calling %s to summarize file %s", model_name, fpath)
    try:
        response_text = create_gpt_chat_completion(
            _get_describe_messages(fpath, content),
            'project_description',
            project,
            function_calls=DESCRIBE_FILE,
            temperature=0,
            model_name=model_name,
        )
        response = json.loads(response_text['text'])
        refs = (" [References: " + ", ".join(response["references"]) + "]") if response.get("references") else ""
        return f"{response['summary']}{refs}"
    except Exception as err:
        logger.error("Error summarizing %s: %s", fpath, err, exc_info=True)
        return '(unknown)'