1
+ """
2
+ Minimal FastAPI app for fallback when the main app fails to load.
3
+ This provides basic functionality to indicate that the server is running
4
+ but in a degraded state.
5
+ """
6
+
7
+ from fastapi import FastAPI , HTTPException
8
+ from pydantic import BaseModel
9
+ from typing import Dict , Any , List , Optional
10
+
11
+ # Create a minimal FastAPI app
12
+ app = FastAPI (
13
+ title = "LocalLab (Minimal Mode)" ,
14
+ description = "LocalLab server running in minimal mode due to initialization errors" ,
15
+ version = "0.4.18"
16
+ )
17
+
18
+ class StatusResponse (BaseModel ):
19
+ status : str
20
+ message : str
21
+ version : str
22
+
23
+ @app .get ("/" , response_model = StatusResponse )
24
+ async def root ():
25
+ """Root endpoint that returns basic server status."""
26
+ return {
27
+ "status" : "minimal" ,
28
+ "message" : "LocalLab server is running in minimal mode due to initialization errors. Check logs for details." ,
29
+ "version" : "0.4.18"
30
+ }
31
+
32
+ @app .get ("/health" , response_model = StatusResponse )
33
+ async def health ():
34
+ """Health check endpoint."""
35
+ return {
36
+ "status" : "minimal" ,
37
+ "message" : "LocalLab server is running in minimal mode. Limited functionality available." ,
38
+ "version" : "0.4.18"
39
+ }
40
+
41
+ @app .get ("/status" , response_model = StatusResponse )
42
+ async def status ():
43
+ """Status endpoint that provides more detailed information."""
44
+ return {
45
+ "status" : "minimal" ,
46
+ "message" : "LocalLab server is running in minimal mode. The main application failed to initialize. Check server logs for details." ,
47
+ "version" : "0.4.18"
48
+ }
49
+
50
+ class ErrorResponse (BaseModel ):
51
+ error : str
52
+ message : str
53
+
54
+ @app .get ("/generate" , response_model = ErrorResponse )
55
+ async def generate ():
56
+ """Generate endpoint that returns an error message."""
57
+ raise HTTPException (
58
+ status_code = 503 ,
59
+ detail = "Text generation is not available in minimal mode. Server is running with limited functionality due to initialization errors."
60
+ )
61
+
62
+ @app .get ("/models" , response_model = Dict [str , List [str ]])
63
+ async def models ():
64
+ """Models endpoint that returns an empty list."""
65
+ return {
66
+ "models" : [],
67
+ "message" : "Model information is not available in minimal mode."
68
+ }
69
+
70
+ @app .get ("/system" , response_model = Dict [str , Any ])
71
+ async def system ():
72
+ """System endpoint that returns minimal system information."""
73
+ import platform
74
+ import psutil
75
+
76
+ try :
77
+ return {
78
+ "status" : "minimal" ,
79
+ "python_version" : platform .python_version (),
80
+ "platform" : platform .platform (),
81
+ "cpu_count" : psutil .cpu_count (),
82
+ "memory_percent" : psutil .virtual_memory ().percent ,
83
+ "message" : "Server is running in minimal mode with limited functionality."
84
+ }
85
+ except Exception :
86
+ return {
87
+ "status" : "minimal" ,
88
+ "message" : "System information is not available in minimal mode."
89
+ }
0 commit comments