prompting.baseminer.miner#

Module Contents#

Classes#

Miner

The Miner class is an abstract base class that defines the structure for Bittensor miners.

class prompting.baseminer.miner.Miner(config=None, axon=None, wallet=None, subtensor=None)#

Bases: abc.ABC

The Miner class is an abstract base class that defines the structure for Bittensor miners. Subclasses should implement the prompt method to define their own response logic. The blacklist and priority methods can also be overridden to provide custom logic.

abstract config()#

Abstract method for configuring the Miner.

Subclasses should implement this method to return a configuration object that dictates various settings and parameters for the miner’s operation. The returned configuration object will typically contain parameters like network settings, logging preferences, and other operational parameters.

Returns:

A configuration object specific to the miner subclass.

Return type:

bt.Config

abstract classmethod add_args(parser)#

Abstract class method to add miner-specific arguments to a command line parser.

This method should be implemented by subclasses to introduce any command-line arguments that the miner might require for operation.

Parameters:

parser (argparse.ArgumentParser) – The command line argument parser to which the miner-specific arguments should be added.

_prompt(synapse)#

A wrapper method around the prompt method that will be defined by the subclass.

This method acts as an intermediary layer to perform pre-processing before calling the actual prompt method implemented in the subclass. Specifically, it checks whether a prompt is in cache to avoid reprocessing recent requests. If the prompt is not in the cache, the subclass prompt method is called.

Parameters:

synapse (Prompting) – The incoming request object encapsulating the details of the request.

Returns:

The response object to be sent back in reply to the incoming request, essentially the filled synapse request object.

Return type:

Prompting

Raises:

ValueError – If the prompt is found in the cache indicating it was sent recently.

Example

This method is not meant to be called directly but is invoked internally when a request is received, and it subsequently calls the prompt method of the subclass.

abstract prompt(synapse)#

Abstract method to handle and respond to incoming requests to the miner.

Subclasses should implement this method to define their custom logic for processing and responding to requests. This method is designed to be overridden, and its behavior will be dependent on the specific implementation provided in the subclass.

Parameters:

synapse (Prompting) – The incoming request object encapsulating the details of the request. This must contain messages and roles as fields.

Returns:

The response object that should be sent back in reply to the

incoming request. This is essentially the filled synapse request object.

Return type:

Prompting

Example

class CustomMiner(Miner):
def prompt(self, synapse: Prompting) -> Prompting:

# Custom logic to process and respond to the request. synapse.completion = “The meaning of life is 42.” return synapse

blacklist(synapse)#

Default blacklist logic

Define how miners should blacklist requests. This Function Runs before the synapse data has been deserialized (i.e. before synapse.data is available). The synapse is instead contructed via the headers of the request. It is important to blacklist requests before they are deserialized to avoid wasting resources on requests that will be ignored.

Below: Check that the hotkey is a registered entity in the metagraph.

Parameters:

synapse (bittensor.synapse.Synapse, required) – synapse object containing the request headers.

Return type:

blacklisted (bool)

priority(synapse)#

Define how miners should prioritize requests.

Miners may recieve messages from multiple entities at once. This function determines which request should be processed first. Higher values indicate that the request should be processed first. Lower values indicate that the request should be processed later.

Below: simple logic, prioritize requests from entities with more stake.

Parameters:

synapse (bittensor.synapse.Synapse, required) – synapse object containing the request headers.

Return type:

priority (float)

run()#

Runs the miner logic. This method starts the miner’s operations, including listening for incoming requests and periodically updating the miner’s knowledge of the network graph.

run_in_background_thread()#

Starts the miner’s operations in a separate background thread. This is useful for non-blocking operations.

stop_run_thread()#

Stops the miner’s operations that are running in the background thread.

__enter__()#

Starts the miner’s operations in a background thread upon entering the context. This method facilitates the use of the miner in a ‘with’ statement.

__exit__(exc_type, exc_value, traceback)#

Stops the miner’s background operations upon exiting the context. This method facilitates the use of the miner in a ‘with’ statement.

Parameters:
  • exc_type – The type of the exception that caused the context to be exited. None if the context was exited without an exception.

  • exc_value – The instance of the exception that caused the context to be exited. None if the context was exited without an exception.

  • traceback – A traceback object encoding the stack trace. None if the context was exited without an exception.