๐ฌ LLM-Powered Code GenerationJune 2, 2026โ
Tests passing
LLM Code Assistant
A CLI tool that integrates with OpenAI's API to provide inline code suggestions, refactorings, and debugging hints based on user queries. This tool helps developers streamline their coding process by leveraging LLMs to automate routine tasks and enhance productivity.
What It Does
- Generate code snippets based on natural language queries.
- Refactor and optimize existing Python code.
- Save generated or refactored code to a specified file.
Installation
Install the required dependencies:
pip install openai pytestUsage
Set the OPENAI_API_KEY environment variable with your OpenAI API key:
export OPENAI_API_KEY=your_openai_api_keyRun the tool with the following options:
Generate Code Snippets
python llm_code_assistant.py --query "Write a Python function to sort an array"Refactor Code
python llm_code_assistant.py --file path/to/your/code.pySave Output to a File
python llm_code_assistant.py --query "Write a Python function to sort an array" --output path/to/output.pySource Code
import argparse
import openai
import os
def llm_code_assistant(query=None, file=None, output=None):
"""
LLM Code Assistant: Generate code snippets, provide debugging suggestions, or refactor code.
"""
openai.api_key = os.getenv('OPENAI_API_KEY')
if not openai.api_key:
return "Error: OPENAI_API_KEY environment variable not set."
if not query and not file:
return "Error: Either --query or --file must be provided."
try:
if query:
response = openai.Completion.create(
engine="text-davinci-003",
prompt=f"{query}",
max_tokens=150
)
result = response.choices[0].text.strip()
if output:
with open(output, 'w') as f:
f.write(result)
return result
elif file:
if not os.path.exists(file):
return "Error: File not found."
with open(file, 'r') as f:
code_content = f.read()
response = openai.Completion.create(
engine="text-davinci-003",
prompt=f"Refactor and optimize the following Python code:\n{code_content}",
max_tokens=300
)
result = response.choices[0].text.strip()
if output:
with open(output, 'w') as f:
f.write(result)
return result
except openai.error.OpenAIError as e:
return f"Error communicating with OpenAI API: {e}"
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="LLM Code Assistant: Generate code snippets, provide debugging suggestions, or refactor code.")
parser.add_argument('--query', type=str, help='Natural language query for code generation or debugging.')
parser.add_argument('--file', type=str, help='Path to a code file for refactoring or optimization.')
parser.add_argument('--output', type=str, help='Path to save the generated or refactored code.')
args = parser.parse_args()
result = llm_code_assistant(query=args.query, file=args.file, output=args.output)
if result:
print(result)Community
Downloads
ยทยทยท
Rate this tool
No ratings yet โ be the first!
Details
- Tool Name
- llm_code_assistant
- Category
- LLM-Powered Code Generation
- Generated
- June 2, 2026
- Tests
- Passing โ
- Fix Loops
- 3
Quick Install
Clone just this tool:
git clone --depth 1 --filter=blob:none --sparse \ https://github.com/ptulin/autoaiforge.git cd autoaiforge git sparse-checkout set generated_tools/2026-06-02/llm_code_assistant cd generated_tools/2026-06-02/llm_code_assistant pip install -r requirements.txt 2>/dev/null || true python llm_code_assistant.py