The comx module serve command is a powerful tool that allows you to effortlessly deploy your modules and embark on an exciting journey with Commune. By leveraging this command, you can quickly set up and expose your module's endpoints, making it accessible to others within the Commune ecosystem.
To serve a Python module, ensure that it's a class inheriting from our Module class. Then, use our endpoint decorator on the methods that you want to expose as endpoints. You can refer to the example folder to see this being done.
With a class that inherits from Module and the communex CLI installed, you can simply run:
communex.module.example.openai.OpenAI
.Additionally, you can optionally pass the following arguments:
First make sure to set the environment variable OPENAI_API_KEY with your OpenAI API key. And you are in the Communex root folder.
Then run the following command:
To run module using pm2, install it globally:
Then run the following command:
In Communex, we provide the ModuleClient class that you can use to communicate with APIs served using this command. However, if you prefer, you can implement your own. Just make sure that you sign the request using your private key and pass the following fields as headers:
follow the module registration section to register your miner on a subnet of your choice