Fawern AI, A Python Developer AI Assistant
Project description
fawern
fawern is a Python library designed to assist developers with various AI-powered tools for code generation, analysis, refactoring, and more. It utilizes advanced models to provide a wide range of functionalities, from generating Python code based on prompts to analyzing and fixing code, generating documentation, and even converting code from other languages to Python.
Features
- ChatPython: Generate Python code based on a given input prompt.
- CodeAnalyzer: Analyze, refactor, and optimize Python code.
- CodeFormatter: Format Python code according to PEP8 standards.
- ErrorLogAnalyzer: Log and analyze Python errors, providing suggestions for fixes.
- CodeReviewer: Review Python code and provide feedback on structure, clarity, and quality.
- DocumentationGenerator: Generate detailed docstrings and inline comments for Python code.
- ConvertToPython: Convert code from other programming languages to Python.
- CodeVisualizer: Generate visual representations such as flowcharts or class diagrams for Python code.
- BugFixer: Automatically identify and fix bugs in Python code.
- UnitTestGenerator: Generate unit tests for Python code to ensure correctness.
Installation
You can install Fawern using pip:
pip install fawern
Usage
ChatPython
Generate Python code based on a prompt:
from fawern import ChatPython
assistant = ChatPython()
prompt = '''Create a snake game using Pygame. Include a snake that moves around the screen and eats food. Display the score and end the game when the snake collides with the wall or itself. Use arrow keys to control the snake' movement '''
code = assistant.generate_code(prompt)
print(code)
This will generate Python code for a snake game using Pygame based on the given prompt. To write the generated code to a file, you can use the following code:
assistant.write_code_to_file(path='./')
This will write the generated code to a file named generated_file_name.py in the current directory.
You can use run_generated_code() method to run the generated code:
assistant.run_generated_code()
This will run the generated code using the Python interpreter.
CodeAnalyzer
Here's an example of how to use the CodeAnalyzer feature to analyze and refactor Python code:
from fawern import CodeAnalyzer
analyzer = CodeAnalyzer()
code = """
def add_numbers(a, b):
return a + b
print(add_numbers(5, '10'))
"""
# Analyze the code
analysis = analyzer.analyze_code(code)
print(analysis)
# Find and fix syntax errors
fixed_code = analyzer.find_syntax_errors(code)
print(fixed_code)
# Suggest optimizations
optimizations = analyzer.suggest_optimizations(code)
print(optimizations)
This will analyze the given Python code, find syntax errors, and suggest optimizations to improve the code.
CodeFormatter
Format Python code according to PEP8 standards:
from fawern import CodeFormatter
formatter = CodeFormatter()
code = """
def addNumbers(a,b):
return a + b
"""
# Format the code
formatted_code = formatter.format_code(code)
print(formatted_code)
This will format the given Python code according to PEP8 standards.
ErrorLogAnalyzer
Log and analyze Python errors, providing suggestions for fixes:
from fawern import ErrorLogAnalyzer
error_analyzer = ErrorLogAnalyzer()
# Log an error
error_message = "TypeError: unsupported operand type(s) for +: 'int' and 'str'"
error_analyzer.log_error(error_message)
# Analyze logged errors
analysis = error_analyzer.analyze_errors()
print(analysis)
This will log the given error message and analyze it to provide suggestions for fixes.
CodeReviewer
Review Python code and provide feedback on structure, clarity, and quality:
from fawern import CodeReviewer
reviewer = CodeReviewer()
code = """
def add_numbers(a, b):
return a + b
"""
# Review the code
review = reviewer.review_code(code)
print(review)
This will review the given Python code and provide feedback on its structure, clarity, and quality.
DocumentationGenerator
Generate detailed docstrings and inline comments for Python code:
from fawern import DocumentationGenerator
doc_generator = DocumentationGenerator()
code = """
def add_numbers(a, b):
return a + b
"""
# Generate docstrings and comments
documentation = doc_generator.generate_docstrings(code)
print(documentation)
This will generate detailed docstrings and inline comments for the given Python code.
ConvertToPython
Convert code from other programming languages to Python:
from fawern import ConvertToPython
converter = ConvertToPython()
java_code = """
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
"""
# Convert Java code to Python
python_code = converter.convert_code(java_code)
print(python_code)
This will convert the given Java code to Python code.
CodeVisualizer
Generate visual representations such as flowcharts or class diagrams for Python code:
from fawern import CodeVisualizer
visualizer = CodeVisualizer()
code = """
class Animal:
def __init__(self, name):
self.name = name
def speak(self):
pass
class Dog(Animal):
def speak(self):
return "Woof!"
class Cat(Animal):
def speak(self):
return "Meow!"
"""
# Visualize the code
visualization = visualizer.visualize_code(code)
print(visualization)
This will generate a class diagram for
BugFixer
Automatically identify and fix bugs in Python code:
from fawern import BugFixer
bug_fixer = BugFixer()
code = """
def add_numbers(a, b):
return a + b
print(add_numbers(5, '10'))
"""
# Fix bugs in the code
fixed_code = bug_fixer.fix_bugs(code)
print(fixed_code)
This will automatically identify and fix bugs in the given Python code.
UnitTestGenerator
Generate unit tests for Python code to ensure correctness:
from fawern import UnitTestGenerator
test_generator = UnitTestGenerator()
code = """
def add_numbers(a, b):
return a + b
"""
# Generate unit tests for the code
unit_tests = test_generator.generate_tests(code)
print(unit_tests)
This will generate unit tests for the given Python code to ensure its correctness.
Contributing
Contributions are welcome! But fawern is not public yet. We will make it public soon.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgements
- This project was inspired by the need for AI-powered tools to assist developers in various aspects of software development.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fawern-0.1.4.tar.gz.
File metadata
- Download URL: fawern-0.1.4.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d19be2dce2f692ac83c65700024e6f7c15b0206ac3e7547433f86f732454e36b
|
|
| MD5 |
ac375d734c332537eb548ebfb5fdc430
|
|
| BLAKE2b-256 |
cfbf9df01ecd2bd0f65d08eab00be8643e94de6c312d1cea9897f57031257c4c
|
File details
Details for the file fawern-0.1.4-py3-none-any.whl.
File metadata
- Download URL: fawern-0.1.4-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
64fa90ae76c7074120a64ef2982678e62af6d285143150f85592cc78388fccd0
|
|
| MD5 |
942fd761cfa662ae8c7bb4a1ae5f5cb3
|
|
| BLAKE2b-256 |
3ede41b95fa28e99ec0a7c4c3fa41e8f7351a86e122592729546f978758cd6cb
|