MCPcopy
hub / github.com/mudler/LocalAI / serve

Function serve

backend/python/mlx/backend.py:682–708  ·  view source on GitHub ↗
(address)

Source from the content-addressed store, hash-verified

680 return text[:earliest] if earliest < len(text) else text
681
682async def serve(address):
683 # Start asyncio gRPC server
684 server = grpc.aio.server(migration_thread_pool=futures.ThreadPoolExecutor(max_workers=MAX_WORKERS),
685 options=[
686 ('grpc.max_message_length', 50 * 1024 * 1024), # 50MB
687 ('grpc.max_send_message_length', 50 * 1024 * 1024), # 50MB
688 ('grpc.max_receive_message_length', 50 * 1024 * 1024), # 50MB
689 ],
690 interceptors=get_auth_interceptors(aio=True),
691 )
692 # Add the servicer to the server
693 backend_pb2_grpc.add_BackendServicer_to_server(BackendServicer(), server)
694 # Bind the server to the address
695 server.add_insecure_port(address)
696
697 # Gracefully shutdown the server on SIGTERM or SIGINT
698 loop = asyncio.get_event_loop()
699 for sig in (signal.SIGINT, signal.SIGTERM):
700 loop.add_signal_handler(
701 sig, lambda: asyncio.ensure_future(server.stop(5))
702 )
703
704 # Start the server
705 await server.start()
706 print("Server started. Listening on: " + address, file=sys.stderr)
707 # Wait for the server to be terminated
708 await server.wait_for_termination()
709
710if __name__ == "__main__":
711 parser = argparse.ArgumentParser(description="Run the gRPC server.")

Callers 1

backend.pyFile · 0.70

Calls 3

get_auth_interceptorsFunction · 0.90
startMethod · 0.80
BackendServicerClass · 0.70

Tested by

no test coverage detected