| | import os |
| | import google.generativeai as generativeai |
| | from dotenv import load_dotenv |
| |
|
| | |
| | load_dotenv() |
| | generativeai.configure(api_key=os.getenv("GOOGLE_GEMINI_KEY")) |
| |
|
| | def get_correction_and_comments(code_snippet): |
| | """ |
| | Analyze, correct, and comment on the given Python code. |
| | """ |
| | prompt = [ |
| | "Analyze and correct the following Python code, add comments, and format it:", |
| | code_snippet |
| | ] |
| | response = generativeai.GenerativeModel('gemini-pro').generate_content(prompt) |
| | return response.text if response else "No suggestions available." |
| |
|
| | def generate_questions(code_snippet, question_type): |
| | """ |
| | Generate questions and answers based on the user's choice of question type. |
| | |
| | Parameters: |
| | - code_snippet: The Python code to generate questions for. |
| | - question_type: The type of questions to generate. |
| | |
| | Returns: |
| | - Generated questions and answers as text. |
| | """ |
| | if question_type == "Logical Questions": |
| | prompt = [ |
| | "Analyze the following Python code and generate logical reasoning questions and answers:", |
| | code_snippet |
| | ] |
| | elif question_type == "Interview-Based Questions": |
| | prompt = [ |
| | "Analyze the following Python code and generate interview-style questions and answers for developers:", |
| | code_snippet |
| | ] |
| | elif question_type == "Code Analysis Questions": |
| | prompt = [ |
| | "Analyze the following Python code and generate in-depth code analysis questions with answers:", |
| | code_snippet |
| | ] |
| | else: |
| | prompt = [ |
| | "Generate general Python questions and answers based on the given code:", |
| | code_snippet |
| | ] |
| | |
| | response = generativeai.GenerativeModel('gemini-pro').generate_content(prompt) |
| | return response.text if response else "No answer available." |
| |
|