Run a Miner
Description
The tor module serve
command is a powerful tool that allows you to effortlessly deploy your modules and embark on an exciting journey with Torus. By leveraging this command, you can quickly set up and expose your module’s endpoints, making it accessible to others within the Torus ecosystem.
Usage
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 torus-cli CLI installed, you can simply run:
qualified_path
: The dotted path to the class that should be served. For example,torus-cli.module.example.openai.OpenAI
.port
: The port that the API should run on your computer.key
: The name of the key file of your module.subnets
: The subnets that your module will serve. Calls from keys of any other subnet will be refused.
Additionally, you can optionally pass the following arguments:
whitelist
: A list of SS58Address. The API will only answer calls signed with the key referring to this address.blacklist
: A list of SS58Address that you won’t answer to.ip
: The IP address on which the API should be served. By default, it’s 127.0.0.1.
Running openai example
First make sure to set the environment variable OPENAI_API_KEY
with your OpenAI API key. And you are in the torus-cli root folder.
Then run the following command:
To run module using pm2, install it globally:
Then run the following command:
Communication
In torus-cli, 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:
- X-Signature: The signature as a hexadecimal.
- X-Key: Your public key as a hexadecimal.
- X-Crypto: The crypto type of the signature.
Register the miner on the network
follow the module registration section to register your miner on a subnet of your choice.