Spaces:
Sleeping
Sleeping
Jatin Mehra
commited on
Commit
Β·
3da73e5
1
Parent(s):
ba907cd
Refactor FastAPI application structure and update test imports for backward compatibility
Browse files- app_refactored.py β app.py +1 -1
- preprocessing_refactored.py +0 -78
- test_refactored.py +4 -4
app_refactored.py β app.py
RENAMED
|
@@ -100,7 +100,7 @@ def main():
|
|
| 100 |
"""
|
| 101 |
Main entry point for running the application.
|
| 102 |
"""
|
| 103 |
-
uvicorn.run("
|
| 104 |
|
| 105 |
|
| 106 |
if __name__ == "__main__":
|
|
|
|
| 100 |
"""
|
| 101 |
Main entry point for running the application.
|
| 102 |
"""
|
| 103 |
+
uvicorn.run("app:app", host="0.0.0.0", port=8000, reload=True)
|
| 104 |
|
| 105 |
|
| 106 |
if __name__ == "__main__":
|
preprocessing_refactored.py
DELETED
|
@@ -1,78 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Refactored preprocessing module for PDF Insight Beta.
|
| 3 |
-
|
| 4 |
-
This module provides the core preprocessing functionality with improved organization.
|
| 5 |
-
The original logic has been preserved while breaking it into more maintainable components.
|
| 6 |
-
|
| 7 |
-
This module maintains backward compatibility with the original preprocessing.py interface.
|
| 8 |
-
"""
|
| 9 |
-
|
| 10 |
-
# Re-export everything from the new modular structure for backward compatibility
|
| 11 |
-
from configs.config import Config
|
| 12 |
-
from services import (
|
| 13 |
-
create_llm_model as model_selection,
|
| 14 |
-
create_tavily_search_tool,
|
| 15 |
-
rag_service
|
| 16 |
-
)
|
| 17 |
-
from utils import (
|
| 18 |
-
process_pdf_file,
|
| 19 |
-
chunk_text,
|
| 20 |
-
create_embeddings,
|
| 21 |
-
build_faiss_index,
|
| 22 |
-
retrieve_similar_chunks,
|
| 23 |
-
estimate_tokens
|
| 24 |
-
)
|
| 25 |
-
|
| 26 |
-
# Create global tools for backward compatibility
|
| 27 |
-
def create_global_tools():
|
| 28 |
-
"""Create global tools list for backward compatibility."""
|
| 29 |
-
tavily_tool = create_tavily_search_tool()
|
| 30 |
-
return [tavily_tool] if tavily_tool else []
|
| 31 |
-
|
| 32 |
-
# Global tools instance (for backward compatibility)
|
| 33 |
-
tools = create_global_tools()
|
| 34 |
-
|
| 35 |
-
# Alias for the main RAG function to maintain original interface
|
| 36 |
-
def agentic_rag(llm, agent_specific_tools, query, context_chunks, memory, Use_Tavily=False):
|
| 37 |
-
"""
|
| 38 |
-
Main RAG function with original interface for backward compatibility.
|
| 39 |
-
|
| 40 |
-
Args:
|
| 41 |
-
llm: Language model instance
|
| 42 |
-
agent_specific_tools: List of tools for the agent
|
| 43 |
-
query: User query
|
| 44 |
-
context_chunks: Context chunks from retrieval
|
| 45 |
-
memory: Conversation memory
|
| 46 |
-
Use_Tavily: Whether to use web search
|
| 47 |
-
|
| 48 |
-
Returns:
|
| 49 |
-
Dictionary with 'output' key containing the response
|
| 50 |
-
"""
|
| 51 |
-
# Convert parameters to work with new RAG service
|
| 52 |
-
return rag_service.generate_response(
|
| 53 |
-
llm=llm,
|
| 54 |
-
query=query,
|
| 55 |
-
context_chunks=context_chunks,
|
| 56 |
-
faiss_index=None, # Will be handled internally by tools
|
| 57 |
-
document_chunks=[], # Will be handled internally by tools
|
| 58 |
-
embedding_model=None, # Will be handled internally by tools
|
| 59 |
-
memory=memory,
|
| 60 |
-
use_tavily=Use_Tavily
|
| 61 |
-
)
|
| 62 |
-
|
| 63 |
-
# Re-export the vector search tool creator for backward compatibility
|
| 64 |
-
from services.rag_service import create_vector_search_tool
|
| 65 |
-
|
| 66 |
-
# Maintain all original exports
|
| 67 |
-
__all__ = [
|
| 68 |
-
'model_selection',
|
| 69 |
-
'process_pdf_file',
|
| 70 |
-
'chunk_text',
|
| 71 |
-
'create_embeddings',
|
| 72 |
-
'build_faiss_index',
|
| 73 |
-
'retrieve_similar_chunks',
|
| 74 |
-
'agentic_rag',
|
| 75 |
-
'tools',
|
| 76 |
-
'create_vector_search_tool',
|
| 77 |
-
'estimate_tokens'
|
| 78 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test_refactored.py
CHANGED
|
@@ -39,7 +39,7 @@ def test_imports():
|
|
| 39 |
print("β API module imported successfully")
|
| 40 |
|
| 41 |
# Test backward compatibility
|
| 42 |
-
from
|
| 43 |
print("β Backward compatibility import successful")
|
| 44 |
|
| 45 |
return True
|
|
@@ -85,7 +85,7 @@ def test_backward_compatibility():
|
|
| 85 |
|
| 86 |
try:
|
| 87 |
# Test original preprocessing interface
|
| 88 |
-
from
|
| 89 |
|
| 90 |
# These should work without errors
|
| 91 |
assert callable(model_selection)
|
|
@@ -95,7 +95,7 @@ def test_backward_compatibility():
|
|
| 95 |
print("β Original preprocessing interface preserved")
|
| 96 |
|
| 97 |
# Test that we can still access the original functions
|
| 98 |
-
from
|
| 99 |
process_pdf_file, chunk_text, create_embeddings,
|
| 100 |
build_faiss_index, retrieve_similar_chunks, agentic_rag
|
| 101 |
)
|
|
@@ -114,7 +114,7 @@ def test_app_creation():
|
|
| 114 |
print("\nTesting app creation...")
|
| 115 |
|
| 116 |
try:
|
| 117 |
-
from
|
| 118 |
|
| 119 |
app = create_app()
|
| 120 |
assert app is not None
|
|
|
|
| 39 |
print("β API module imported successfully")
|
| 40 |
|
| 41 |
# Test backward compatibility
|
| 42 |
+
from preprocessing import model_selection, chunk_text, agentic_rag
|
| 43 |
print("β Backward compatibility import successful")
|
| 44 |
|
| 45 |
return True
|
|
|
|
| 85 |
|
| 86 |
try:
|
| 87 |
# Test original preprocessing interface
|
| 88 |
+
from preprocessing import model_selection, tools, estimate_tokens
|
| 89 |
|
| 90 |
# These should work without errors
|
| 91 |
assert callable(model_selection)
|
|
|
|
| 95 |
print("β Original preprocessing interface preserved")
|
| 96 |
|
| 97 |
# Test that we can still access the original functions
|
| 98 |
+
from preprocessing import (
|
| 99 |
process_pdf_file, chunk_text, create_embeddings,
|
| 100 |
build_faiss_index, retrieve_similar_chunks, agentic_rag
|
| 101 |
)
|
|
|
|
| 114 |
print("\nTesting app creation...")
|
| 115 |
|
| 116 |
try:
|
| 117 |
+
from app import create_app
|
| 118 |
|
| 119 |
app = create_app()
|
| 120 |
assert app is not None
|