|
18 | 18 | from app.compiler import RustCompiler |
19 | 19 | from app.llm_client import LlamaEdgeClient |
20 | 20 | from app.vector_store import QdrantStore |
| 21 | +from app.mcp_service import RustCompilerMCP |
21 | 22 |
|
22 | 23 | app = FastAPI(title="Rust Project Generator API") |
23 | 24 |
|
@@ -65,6 +66,16 @@ class ProjectResponse(BaseModel): |
65 | 66 | build_output: Optional[str] = None |
66 | 67 | run_output: Optional[str] = None |
67 | 68 |
|
| 69 | +# Add the CompileAndFixRequest model |
| 70 | +class CompileAndFixRequest(BaseModel): |
| 71 | + code: str |
| 72 | + description: str |
| 73 | + max_attempts: int = 3 |
| 74 | + |
| 75 | +# Define the get_vector_store function |
| 76 | +def get_vector_store(): |
| 77 | + return vector_store |
| 78 | + |
68 | 79 | @app.post("/generate", response_model=ProjectResponse) |
69 | 80 | async def generate_project(request: ProjectRequest, background_tasks: BackgroundTasks): |
70 | 81 | """Generate a Rust project based on description""" |
@@ -144,6 +155,31 @@ async def compile_rust(request: dict): |
144 | 155 | "error_details": error_context |
145 | 156 | } |
146 | 157 |
|
| 158 | +@app.post("/compile-and-fix") |
| 159 | +async def compile_and_fix(request: CompileAndFixRequest): |
| 160 | + """Compile Rust code and fix errors with LLM""" |
| 161 | + code = request.code |
| 162 | + description = request.description |
| 163 | + max_attempts = request.max_attempts |
| 164 | + |
| 165 | + # Create MCP service instance |
| 166 | + mcp_service = RustCompilerMCP( |
| 167 | + vector_store=get_vector_store(), |
| 168 | + llm_client=llm_client, |
| 169 | + compiler=compiler, |
| 170 | + parser=parser, |
| 171 | + prompt_generator=prompt_gen |
| 172 | + ) |
| 173 | + |
| 174 | + # Compile and fix code |
| 175 | + result = mcp_service.compile_and_fix_rust_code( |
| 176 | + code_content=code, |
| 177 | + description=description, |
| 178 | + max_attempts=max_attempts |
| 179 | + ) |
| 180 | + |
| 181 | + return result |
| 182 | + |
147 | 183 | @app.post("/compile-and-fix") |
148 | 184 | async def compile_and_fix_rust(request: dict): |
149 | 185 | """Endpoint to compile and fix Rust code""" |
|
0 commit comments