3030
3131# Import AI models
3232try :
33- from ai_models .github_analyzer import GitHubAnalyzer
34- from ai_models .documentation_generator import DocumentationGenerator
35- from ai_models .rag_pipeline import RAGPipeline
33+ from ai_models .github_analyzer import GitHubAnalyzer as GitHubAnalyzerModel
34+ from ai_models .documentation_generator import DocumentationGenerator as DocumentationGeneratorModel
35+ from ai_models .rag_pipeline import RAGPipeline as RAGPipelineModel
3636 logger = logging .getLogger (__name__ )
3737 logger .info ("AI models imported successfully" )
3838except ImportError as e :
@@ -48,13 +48,15 @@ def parse_github_url(self, repo_url: str) -> Dict[str, str]:
4848 def analyze_repository (self , repo_url : str ) -> Dict [str , Any ]:
4949 raise Exception ("AI models not available - import failed" )
5050
51- class DocumentationGenerator :
52- def generate_documentation (self , analysis_result : Dict [str , Any ]) -> Dict [str , Any ]:
51+ class DummyDocumentationGenerator :
52+ def generate_documentation (self , analysis_result : Dict [str , Any ], rag_result : Optional [ Dict [ str , Any ]] = None ) -> Dict [str , Any ]:
5353 raise Exception ("AI models not available - import failed" )
5454
5555 class RAGPipeline :
5656 def process (self , analysis_result : Dict [str , Any ]) -> Dict [str , Any ]:
5757 raise Exception ("AI models not available - import failed" )
58+ def process_repository (self , analysis_result : Dict [str , Any ]) -> Dict [str , Any ]:
59+ raise Exception ("AI models not available - import failed" )
5860
5961# Load environment variables
6062load_dotenv ()
@@ -333,7 +335,7 @@ class DocumentationGenerator:
333335 def __init__ (self ):
334336 self .template_path = Path (__file__ ).parent / 'templates'
335337
336- def generate_documentation (self , analysis_result : Dict [str , Any ]) -> Dict [str , Any ]:
338+ def generate_documentation (self , analysis_result : Dict [str , Any ], rag_result : Optional [ Dict [ str , Any ]] = None ) -> Dict [str , Any ]:
337339 """Generate complete documentation package"""
338340 try :
339341 repo_info = analysis_result .get ('repository_info' , {})
@@ -1433,7 +1435,11 @@ def cleanup(self):
14331435
14341436# Initialize components with better error handling
14351437try :
1436- github_analyzer = GitHubAnalyzer ()
1438+ # Check if GitHubAnalyzerModel was successfully imported
1439+ if 'GitHubAnalyzerModel' in locals () or 'GitHubAnalyzerModel' in globals ():
1440+ github_analyzer = GitHubAnalyzerModel ()
1441+ else :
1442+ github_analyzer = GitHubAnalyzer ()
14371443 logger .info ("✅ GitHubAnalyzer initialized successfully" )
14381444except Exception as e :
14391445 logger .error (f"❌ Failed to initialize GitHubAnalyzer: { e } " )
@@ -1447,19 +1453,19 @@ def analyze_repository(self, repo_url: str) -> Dict[str, Any]:
14471453 github_analyzer = FallbackGitHubAnalyzer ()
14481454
14491455try :
1450- doc_generator = DocumentationGenerator ()
1456+ doc_generator = DocumentationGeneratorModel () if 'DocumentationGeneratorModel' in globals () else DocumentationGenerator ()
14511457 logger .info ("✅ DocumentationGenerator initialized successfully" )
14521458except Exception as e :
14531459 logger .error (f"❌ Failed to initialize DocumentationGenerator: { e } " )
14541460 logger .error (traceback .format_exc ())
14551461 # Create a fallback class
14561462 class FallbackDocumentationGenerator :
1457- def generate_documentation (self , analysis_result : Dict [str , Any ]) -> Dict [str , Any ]:
1463+ def generate_documentation (self , analysis_result : Dict [str , Any ], rag_result : Optional [ Dict [ str , Any ]] = None ) -> Dict [str , Any ]:
14581464 raise Exception (f"DocumentationGenerator initialization failed: { e } " )
14591465 doc_generator = FallbackDocumentationGenerator ()
14601466
14611467try :
1462- rag_pipeline = RAGPipeline ()
1468+ rag_pipeline = RAGPipelineModel () if 'RAGPipelineModel' in globals () else RAGPipeline ()
14631469 logger .info ("✅ RAGPipeline initialized successfully" )
14641470except Exception as e :
14651471 logger .error (f"❌ Failed to initialize RAGPipeline: { e } " )
@@ -1496,6 +1502,35 @@ def favicon():
14961502 """Handle favicon requests"""
14971503 return '' , 204 # No Content
14981504
1505+ # Handle malformed API URLs with double slashes
1506+ @app .route ('/api//<path:path>' , methods = ['GET' , 'POST' , 'PUT' , 'DELETE' ])
1507+ def handle_double_slash_api (path ):
1508+ """Redirect malformed API URLs with double slashes"""
1509+ logger .warning (f"Received malformed API URL with double slash: /api//{ path } " )
1510+
1511+ # For analyze endpoint, handle directly instead of redirecting
1512+ if path == 'analyze' :
1513+ if request .method == 'GET' :
1514+ return jsonify ({
1515+ 'message' : 'Repository analysis endpoint' ,
1516+ 'method' : 'POST' ,
1517+ 'required_fields' : ['repo_url' ],
1518+ 'description' : 'Submit a GitHub repository URL to generate AI documentation' ,
1519+ 'example' : {
1520+ 'repo_url' : 'https://github.com/owner/repository'
1521+ },
1522+ 'note' : 'URL was corrected from double slash'
1523+ })
1524+ elif request .method == 'POST' :
1525+ # Forward to the actual analyze function
1526+ return analyze_repository ()
1527+
1528+ # For other endpoints, redirect to the corrected URL
1529+ corrected_url = f"/api/{ path } "
1530+ logger .info (f"Redirecting to: { corrected_url } " )
1531+ from flask import redirect
1532+ return redirect (corrected_url )
1533+
14991534@app .route ('/api/health' )
15001535def health_check ():
15011536 """Enhanced health check endpoint with detailed system status"""
@@ -1575,6 +1610,7 @@ def health_check():
15751610 }), 500
15761611
15771612@app .route ('/api/analyze' , methods = ['GET' , 'POST' ])
1613+ @app .route ('/api/analyze/' , methods = ['GET' , 'POST' ])
15781614def analyze_repository ():
15791615 """Handle repository analysis requests"""
15801616 if request .method == 'GET' :
@@ -1680,10 +1716,29 @@ def analyze_repository():
16801716 }
16811717 }), 500
16821718
1683- # Step 2: Generate documentation
1719+ # Step 2: Process with RAG pipeline
1720+ try :
1721+ logger .info ("Step 2: Processing with RAG pipeline" )
1722+ rag_result = rag_pipeline .process_repository (analysis_result )
1723+ logger .info ("RAG pipeline processing completed successfully" )
1724+ except Exception as e :
1725+ logger .error (f"RAG pipeline processing failed: { e } " )
1726+ logger .error (traceback .format_exc ())
1727+ # Continue with empty rag_result as fallback
1728+ rag_result = {
1729+ 'processing_status' : 'failed' ,
1730+ 'error' : str (e ),
1731+ 'semantic_insights' : [],
1732+ 'code_patterns' : [],
1733+ 'knowledge_graph' : {},
1734+ 'document_count' : 0 ,
1735+ 'embedding_dimension' : 0
1736+ }
1737+
1738+ # Step 3: Generate documentation
16841739 try :
1685- logger .info ("Step 2 : Generating documentation" )
1686- documentation = doc_generator .generate_documentation (analysis_result )
1740+ logger .info ("Step 3 : Generating documentation" )
1741+ documentation = doc_generator .generate_documentation (analysis_result , rag_result )
16871742 logger .info ("Documentation generation completed successfully" )
16881743 except Exception as e :
16891744 logger .error (f"Documentation generation failed: { e } " )
0 commit comments