File size: 620 Bytes
c4070e8
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import google.generativeai as genai

def check_code(prompt, model):
    code_prefix = "check code:"
    if code_prefix in prompt.lower():
        code = prompt.lower().split(code_prefix, 1)[1].strip()
    else:
        return "Please provide the Python code after 'check code:'."

    try:
        response = model.generate_content(f"Analyze the following Python code for syntax errors, logical errors, and best practice violations. Provide detailed explanations and suggest fixes:\n\n```python\n{code}\n```")
        return response.text
    except Exception as e:
        return f"Error checking code with Gemini: {e}"