A sophisticated system that automates the generation of Java source code from cURL commands using LLM-powered agents for planning, code generation, and validation.
This project leverages multiple specialized agents to convert cURL commands into fully functional Java code implementations. The system follows a modular architecture where each agent is responsible for a specific part of the code generation pipeline.
The system consists of the following components:
- Parses cURL commands into structured REST operation plans
- Extracts HTTP method, headers, URL path, and request body
- Infers appropriate operation names and DTO schemas
- Uses the Qwen model for planning
- Generates Java source files from structured operation plans
- Creates domain classes, interfaces, and implementation classes
- Uses the CodeLlama model for code generation
- Leverages LangChain's FileManagementToolkit for file operations
- Compiles and validates the generated Java code
- Provides detailed feedback on compilation and runtime errors
- Uses the Gemma model for error analysis
- Utilizes LangChain's ShellTool for executing commands
- Coordinates the planning, code generation, and validation processes
- Manages the workflow and data flow between agents
- Handles error recovery and feedback loops
The system uses the following LangChain tools:
- Shell Tool: Executes whitelisted commands (javac, java, mvn, gradle, ls, cat)
- File System Tool: Reads and writes Java files
- Clone the repository:
git clone https://github.com/yourusername/java-code-generator.git
cd java-code-generator
- Create a virtual environment and install dependencies:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
- Ensure you have Ollama installed and the required models available:
- Qwen for planning
- CodeLlama for code generation
- Gemma for validation
from orchestrator import Orchestrator
# Initialize the orchestrator
orchestrator = Orchestrator()
# Example cURL command
curl_command = '''
curl -X POST "https://api.example.com/users"
-H "Content-Type: application/json"
-d '{"name": "John Doe", "email": "john@example.com"}'
'''
# Generate and validate Java code
result = orchestrator.process_curl_command(curl_command)
# Print the results
print(f"Generation successful: {result['success']}")
print(f"Generated files: {list(result['files'].keys())}")
You can also use the agents individually:
# Example: Using the Code Generation Agent
from agents.code_generation_agent import CodeGenerationAgent
agent = CodeGenerationAgent()
operation_plan = """
# API: `http://example.com/users`
# Operation: `createUser`
# HTTP Method: `POST`
# Request Body: `{ "name": "John Doe", "email": "john@example.com" }`
# Response Body: `{ "id": 123, "name": "John Doe", "email": "john@example.com" }`
"""
java_files = agent.generate_code(operation_plan)
- The system currently supports simple RESTful endpoints
- Field types in DTOs must be inferrable from the cURL command
- The system uses a maximum of 3 feedback loops for self-correction
This project is licensed under the MIT License - see the LICENSE file for details.