MCPcopy
hub / github.com/PromtEngineer/localGPT / main

Function main

backend/server.py:1082โ€“1139  ยท  view source on GitHub โ†—

Main function to initialize and start the server

()

Source from the content-addressed store, hash-verified

1080 print(f"[{self.date_time_string()}] {format % args}")
1081
1082def main():
1083 """Main function to initialize and start the server"""
1084 PORT = 8000 # ๐Ÿ†• Define port
1085 try:
1086 # Initialize the database
1087 print("โœ… Database initialized successfully")
1088
1089 # Initialize the PDF processor
1090 try:
1091 pdf_module.initialize_simple_pdf_processor()
1092 print("๐Ÿ“„ Initializing simple PDF processing...")
1093 if pdf_module.simple_pdf_processor:
1094 print("โœ… Simple PDF processor initialized")
1095 else:
1096 print("โš ๏ธ PDF processing could not be initialized.")
1097 except Exception as e:
1098 print(f"โŒ Error initializing PDF processor: {e}")
1099 print("โš ๏ธ PDF processing disabled - server will run without RAG functionality")
1100
1101 # Set a global reference to the initialized processor if needed elsewhere
1102 global pdf_processor
1103 pdf_processor = pdf_module.simple_pdf_processor
1104 if pdf_processor:
1105 print("โœ… Global PDF processor initialized")
1106 else:
1107 print("โš ๏ธ PDF processing disabled - server will run without RAG functionality")
1108
1109 # Cleanup empty sessions on startup
1110 print("๐Ÿงน Cleaning up empty sessions...")
1111 cleanup_count = db.cleanup_empty_sessions()
1112 if cleanup_count > 0:
1113 print(f"โœจ Cleaned up {cleanup_count} empty sessions")
1114 else:
1115 print("โœจ No empty sessions to clean up")
1116
1117 # Start the server
1118 with ReusableTCPServer(("", PORT), ChatHandler) as httpd:
1119 print(f"๐Ÿš€ Starting localGPT backend server on port {PORT}")
1120 print(f"๐Ÿ“ Chat endpoint: http://localhost:{PORT}/chat")
1121 print(f"๐Ÿ” Health check: http://localhost:{PORT}/health")
1122
1123 # Test Ollama connection
1124 client = OllamaClient()
1125 if client.is_ollama_running():
1126 models = client.list_models()
1127 print(f"โœ… Ollama is running with {len(models)} models")
1128 print(f"๐Ÿ“‹ Available models: {', '.join(models[:3])}{'...' if len(models) > 3 else ''}")
1129 else:
1130 print("โš ๏ธ Ollama is not running. Please start Ollama:")
1131 print(" Install: https://ollama.ai")
1132 print(" Run: ollama serve")
1133
1134 print(f"\n๐ŸŒ Frontend should connect to: http://localhost:{PORT}")
1135 print("๐Ÿ’ฌ Ready to chat!\n")
1136
1137 httpd.serve_forever()
1138 except KeyboardInterrupt:
1139 print("\n๐Ÿ›‘ Server stopped")

Callers 1

server.pyFile ยท 0.70

Calls 5

is_ollama_runningMethod ยท 0.95
list_modelsMethod ยท 0.95
OllamaClientClass ยท 0.90
cleanup_empty_sessionsMethod ยท 0.80
ReusableTCPServerClass ยท 0.70

Tested by

no test coverage detected