|
18 | 18 | ) |
19 | 19 | from models import ( |
20 | 20 | CreateProjectRequest, IndexProjectRequest, |
21 | | - QueryRequest, CodeCompletionRequest |
| 21 | + QueryRequest |
22 | 22 | ) |
23 | 23 |
|
24 | 24 | DATABASE = CFG.get("database_path", "codebase.db") |
@@ -180,62 +180,6 @@ def api_query(request: QueryRequest): |
180 | 180 | return JSONResponse({"error": "Query failed"}, status_code=500) |
181 | 181 |
|
182 | 182 |
|
183 | | -@app.post("/api/code") |
184 | | -def api_code_completion(request: CodeCompletionRequest): |
185 | | - """Get code suggestions using RAG + LLM (PyCharm-compatible).""" |
186 | | - import logging |
187 | | - logger = logging.getLogger(__name__) |
188 | | - try: |
189 | | - project = get_project_by_id(request.project_id) |
190 | | - if not project: |
191 | | - return JSONResponse({"error": "Project not found"}, status_code=404) |
192 | | - |
193 | | - db_path = project["database_path"] |
194 | | - |
195 | | - # Get context from RAG if enabled |
196 | | - combined_context = request.context or "" |
197 | | - used_context = [] |
198 | | - |
199 | | - if request.use_rag: |
200 | | - analyses = list_analyses(db_path) |
201 | | - if analyses: |
202 | | - analysis_id = analyses[0]["id"] |
203 | | - try: |
204 | | - retrieved = search_semantic(request.prompt, db_path, analysis_id=analysis_id, top_k=request.top_k) |
205 | | - context_parts = [] |
206 | | - total_len = len(combined_context) |
207 | | - for r in retrieved: |
208 | | - part = f"File: {r.get('path')} (score: {r.get('score', 0):.4f})\n" |
209 | | - if total_len + len(part) > TOTAL_CONTEXT_LIMIT: |
210 | | - break |
211 | | - context_parts.append(part) |
212 | | - total_len += len(part) |
213 | | - used_context.append({"path": r.get("path"), "score": r.get("score")}) |
214 | | - if context_parts: |
215 | | - retrieved_text = "\n".join(context_parts) |
216 | | - if combined_context: |
217 | | - combined_context = combined_context + "\n\nRetrieved:\n" + retrieved_text |
218 | | - else: |
219 | | - combined_context = "Retrieved:\n" + retrieved_text |
220 | | - except Exception: |
221 | | - pass |
222 | | - |
223 | | - # Call coding model |
224 | | - try: |
225 | | - response = call_coding_model(request.prompt, combined_context) |
226 | | - except Exception as e: |
227 | | - logger.error(f"Coding model call failed: {e}") |
228 | | - return JSONResponse({"error": "Code generation failed"}, status_code=500) |
229 | | - |
230 | | - return JSONResponse({ |
231 | | - "response": response, |
232 | | - "used_context": used_context, |
233 | | - "project_id": request.project_id |
234 | | - }) |
235 | | - except Exception as e: |
236 | | - logger.exception(f"Error in code completion: {e}") |
237 | | - return JSONResponse({"error": "Code completion failed"}, status_code=500) |
238 | | - |
239 | 183 |
|
240 | 184 | @app.get("/api/health") |
241 | 185 | def api_health(): |
|
0 commit comments