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

Function serve

backend/python/transformers/backend.py:619–645  ·  view source on GitHub ↗
(address)

Source from the content-addressed store, hash-verified

617 return backend_pb2.Result(success=True)
618
619async def serve(address):
620 # Start asyncio gRPC server
621 server = grpc.aio.server(migration_thread_pool=futures.ThreadPoolExecutor(max_workers=MAX_WORKERS),
622 options=[
623 ('grpc.max_message_length', 50 * 1024 * 1024), # 50MB
624 ('grpc.max_send_message_length', 50 * 1024 * 1024), # 50MB
625 ('grpc.max_receive_message_length', 50 * 1024 * 1024), # 50MB
626 ],
627 interceptors=get_auth_interceptors(aio=True),
628 )
629 # Add the servicer to the server
630 backend_pb2_grpc.add_BackendServicer_to_server(BackendServicer(), server)
631 # Bind the server to the address
632 server.add_insecure_port(address)
633
634 # Gracefully shutdown the server on SIGTERM or SIGINT
635 loop = asyncio.get_event_loop()
636 for sig in (signal.SIGINT, signal.SIGTERM):
637 loop.add_signal_handler(
638 sig, lambda: asyncio.ensure_future(server.stop(5))
639 )
640
641 # Start the server
642 await server.start()
643 print("Server started. Listening on: " + address, file=sys.stderr)
644 # Wait for the server to be terminated
645 await server.wait_for_termination()
646
647if __name__ == "__main__":
648 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