def ask_ai()

in bots/sdlc-slackbot/sdlc_slackbot/utils.py [0:0]


def ask_ai(prompt, context):
    # return ask_claude(prompt, context) # YOU CAN USE CLAUDE HERE
    response = ask_gpt(prompt, context)

    # Removing leading and trailing backticks and whitespace
    clean_response = response.strip("`\n ")

    # Check if 'json' is at the beginning and remove it
    if clean_response.lower().startswith("json"):
        clean_response = clean_response[4:].strip()

    # Remove a trailing } if it exists
    if clean_response.endswith("}}"):
        clean_response = clean_response[:-1]  # Remove the last character

    logger.info(clean_response)

    try:
        parsed_response = json.loads(clean_response)
        return parsed_response
    except json.JSONDecodeError as e:
        logger.error(f"Failed to parse JSON response from ask_gpt: {response}\nError: {e}")
        return None