ROLE="You are an experienced python software developer responsible for code review and feedback." TASK="Review the following python code by considering the best practices given in the guidelines below and provide your Observations and Suggestions." INSTRUCTIONS="""Identify the code. If no code is present then say 'No code given'. Take a deep breath before providing the feedback and thoroughly understand the code logic. Avoid verbosity and repetition in your feedback, focussing on essential points and offering valuable suggestions. Add your own observations and suggestions as needed, and only include comments that are neccessary for clarity and improvement. If you have specific code suggestions, ensure they are correct and aligned with the best practices. """ GUIDELINES = f""" Use Intention-Revealing Names. Pick one word per concept Use Solution/Problem Domain Names Classes should be small Functions should be small Do one Thing Declare constants as applicable Don't Repeat Yourself (Avoid Duplication) Explain yourself in code Make sure the code formatting is applied Use Exceptions rather than Return codes Don't return Null Favor the use of standard exceptions Don't ignore exceptions Check parameters for validity Return empty arrays or collections, not nulls Minimize the accessibility of classes and members In public classes, use accessor methods, not public fields Minimize the scope of local variables Refer to objects by their interfaces Adhere to generally accepted naming conventions Avoid finalizers Synchronize access to shared mutable data Valid unit test cases exist Objects accessed by multiple threads are accessed only through a lock, or synchronized methods. Race conditions have been handled Locks are acquired and released in the right order to prevent deadlocks, even in error handling code. All methods are commented in clear language """ #First check whether the given input contains any code snippet or not. STEPS="""Follow the steps in the same order: 1. Understand the code logic and structure. 2. Notedown the observations based on the guidelines given above. 3. Give suggestions for improving the code. 4. Give an example of Final improved code. """ def default_review_prompt1(code, guidelines=None): if guidelines is None: guidelines=GUIDELINES prompt=f""": {ROLE} {TASK} : {INSTRUCTIONS} : {guidelines} : {STEPS} : {code} """ return prompt def default_review_prompt2(code): prompt=f""": {ROLE} {TASK} : Analyze the provided code and identify the key components (classes, functions, modules). 1. Analyze each key component following chain of thoughts. Consider the purpose of the component, its readability, efficiency, and adherence to the listed custom guidelines. 2. Break down your review into a step-by-step process, explaining your reasoning at each point. Maintain a clear and concise tone throughout the review. 3. Add your own observations and suggestions as needed, and only include comments that are neccessary for clarity and improvement. 4. Highlight serious violations. 5. Give suggestions for improving the code. 6. Give an example of Final improved code. : {GUIDELINES} : {STEPS} : {code} """ promptt=f""" : {ROLE} Review the following code by considering the best practices given in the guidelines below. : {GUIDELINES} : {code} """ return prompt def default_review_prompt3(code): prompt= f"""Conduct a comprehensive code review of the provided Python script, focusing on its structure, functionality, and adherence to best practices.\ The script is designed to automate a specific task, and your review should assess its efficiency, readability, and maintainability. : - Understand the script: Check whether the script contains a python script or not. - Structure and Organization: Evaluate the script's overall structure and organization. Is the code logically divided into functions or sections? Are there any redundant or unnecessary sections? - Declare constants as applicable: Make sure constants are declared whenever applicable. - Functionality and Correctness: Assess the script's functionality and correctness. Does it perform the intended task correctly? Are there any potential errors or edge cases that could cause issues? - Readability and Code Quality: Evaluate the script's readability and code quality. Are the variable names descriptive and consistent? Are there any unnecessary comments or redundant code? - Efficiency and Performance: Analyze the script's efficiency and performance. Are there any opportunities to optimize the code for better performance or reduce computational complexity? - Best Practices and Conventions: Check the script's adherence to best practices and coding conventions. Are there any deviations from standard Python coding conventions or best practices? - Error Handling and Debugging: Evaluate the script's error handling and debugging capabilities. Are there any try-except blocks or logging statements to handle potential errors? - Code Duplication and Redundancy: Identify any duplicated or redundant code sections. Are there any opportunities to refactor the code to reduce duplication? - Security and Vulnerabilities: Assess the script's security and potential vulnerabilities. Are there any sensitive data or user input handling that could lead to security issues? - Documentation and Comments: Evaluate the script's documentation and comments. Are there any clear and concise comments explaining the code's purpose and functionality? - Testing and Validation: Suggest any additional testing or validation steps to ensure the script's correctness and reliability. : A detailed report summarizing the code review findings, including any suggestions for improvement. A revised version of the script incorporating the recommended changes and improvements.