@@ -280,6 +280,8 @@ async def update_servers(servers: List[str], authenticated: bool = Depends(authe
280280 async def balance_api (inputs : self ._input_type ):
281281 return await self .process_request (inputs )
282282
283+ logger .info (f"Your load balancer has started. The endpoint is 'http://{ self .host } :{ self .port } { self .endpoint } '" )
284+
283285 uvicorn .run (
284286 fastapi_app ,
285287 host = self .host ,
@@ -332,6 +334,51 @@ def send_request_to_update_servers(self, servers: List[str]):
332334 response = requests .put (f"{ self .url } /system/update-servers" , json = servers , headers = headers , timeout = 10 )
333335 response .raise_for_status ()
334336
337+ @staticmethod
338+ def _get_sample_dict_from_datatype (datatype : Any ) -> dict :
339+ if hasattr (datatype , "_get_sample_data" ):
340+ return datatype ._get_sample_data ()
341+
342+ datatype_props = datatype .schema ()["properties" ]
343+ out : Dict [str , Any ] = {}
344+ for k , v in datatype_props .items ():
345+ if v ["type" ] == "string" :
346+ out [k ] = "data string"
347+ elif v ["type" ] == "number" :
348+ out [k ] = 0.0
349+ elif v ["type" ] == "integer" :
350+ out [k ] = 0
351+ elif v ["type" ] == "boolean" :
352+ out [k ] = False
353+ else :
354+ raise TypeError ("Unsupported type" )
355+ return out
356+
357+ def configure_layout (self ) -> None :
358+ try :
359+ from lightning_api_access import APIAccessFrontend
360+ except ModuleNotFoundError :
361+ logger .warn ("APIAccessFrontend not found. Please install lightning-api-access to enable the UI" )
362+ return
363+
364+ try :
365+ request = self ._get_sample_dict_from_datatype (self ._input_type )
366+ response = self ._get_sample_dict_from_datatype (self ._output_type )
367+ except (AttributeError , TypeError ):
368+ return
369+
370+ return APIAccessFrontend (
371+ apis = [
372+ {
373+ "name" : self .__class__ .__name__ ,
374+ "url" : f"{ self .url } { self .endpoint } " ,
375+ "method" : "POST" ,
376+ "request" : request ,
377+ "response" : response ,
378+ }
379+ ]
380+ )
381+
335382
336383class AutoScaler (LightningFlow ):
337384 """The ``AutoScaler`` can be used to automatically change the number of replicas of the given server in
@@ -574,5 +621,5 @@ def autoscale(self) -> None:
574621 self ._last_autoscale = time .time ()
575622
576623 def configure_layout (self ):
577- tabs = [{ "name" : "Swagger" , "content" : self .load_balancer .url }]
578- return tabs
624+ layout = self .load_balancer .configure_layout ()
625+ return layout if layout else super (). configure_layout ()
0 commit comments