Skip to content

Here in this project, I have built an AI system that writes Python code as per user's question, fixes the errors of the user's code and also explain the error.

Notifications You must be signed in to change notification settings

NavinBondade/Python-Code-Writer-Code-Fixer-Error-Explainer-and-Code-Commenter

Repository files navigation

Python Code Writer, Code Fixer, Error Explainer and Code Commenter Powered By CodeLLAMA and Zephyr

The development of functional Python code often presents significant challenges, demanding a deep understanding of the language and exceptional debugging abilities. Developers frequently encounter difficulties in crafting efficient code or resolving complex errors, leading to time-consuming and frustrating experiences. To address these hurdles, we have developed an innovative AI system capable of generating Python code based on user-provided prompts. Furthermore, this system excels at identifying and rectifying errors within existing Python code, offering clear explanations and potential solutions. By automating these tasks, our AI system significantly streamlines the development process, enabling developers to focus on higher-level problem-solving and enhancing overall productivity.

Libraries Used

  • LangChain
  • Hugging Face
  • Streamlit

Methodology

Python Code Fixer and Error Explaine

In the “Python Code Fixer and Error Explainer System” I have used CodeLlama and Zephyr models. CodeLlama is utilized to fix the errored code of the user. With prompt engineering, I crafted a custom prompt that incorporates instructions about what the CodeLlama should do. The prompt also includes the user’s error code and the error message generated by the Python interpreter. This prompt acts as input to the CodeLlama model. Considering the error message with respect to the user's code, the CodeLlama model fixes the error and produces the error-free fixed code. The Zephyr model also takes a custom prompt mentioning “explain the error.” After understanding the error, the model outputs a short but accurate explanation of the error message to make the user understand what causes the error.

Python Code Writer

In the “Python Code Writer System” I have used the CodeLlama mode. A custom prompt has been crafted and tested mentioning that the model is an expert Python programmer and its job is to write error-free Python code as per the user's question. This prompt plus user’s question is given to the model to generate an accurate and optimized Python code.

Code Llama

Code Llama is a code-specialized version of Llama 2 that was created by further training Llama 2 on its code-specific datasets, sampling more data from that same dataset for longer. Essentially, Code Llama features enhanced coding capabilities, built on top of Llama 2. It can generate code, and natural language about code, from both code and natural language prompts. It can also be used for code completion and debugging.

Zephyr 7B Beta

Zephyr is a series of language models that are trained to act as helpful assistants. Zephyr-7B-β is the second model in the series, and is a fine-tuned version of mistralai/Mistral-7B-v0.1 that was trained on on a mix of publicly available, synthetic datasets using Direct Preference Optimization (DPO).

Demo Video

Python Code Fixer and Error Explaine

code_fixer.mp4

Python Code Writer

code_generator.mp4

Python Comment Writer

Commenting.the.code.mp4

Python Code Written By The AI

Data Science & Machine Learning Questions:

How to train neural network in tensorflow?

Write an example of linear regression in scikit learn?

How to convert numpy array into tensor?

How to split dataset in train and test using scikit learn?

General Python Questions

Write a program to print the given number is odd or even.

Write a program to find a fibonacci of a number.

Write a program to remove duplicates from a list.

Write a program to find the second largest number in a list.

Errors Fixed & Explained By The AI

Module Not Found Error:

Named Error:

Index Out of Range Error:

Attribute Error:

Comments Added By The AI To Python Code

Python Program to Find Armstrong Number in an Interval

Python Program to Create a Countdown Timer

Python Program to Transpose a Matrix

Python Program to Reverse a Number

Python Program to Find Sum of Array

Conclusion

Here in this project, I have built an AI system that writes Python code as per user's question, fixes the errors of the user's code, explain the error and also comment out the code using two large language modes, i.e. CodeLlama and Zephyr.

About

Here in this project, I have built an AI system that writes Python code as per user's question, fixes the errors of the user's code and also explain the error.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages