diff --git a/.env.api.example b/.env.api.example index d2a046d7..eaf06982 100644 --- a/.env.api.example +++ b/.env.api.example @@ -1,3 +1,5 @@ -API_PORT = "8005" -API_HOST = "0.0.0.0" -# SCORING_KEY = "YOUR_SCORING_API_KEY_GOES_HERE" +API_PORT = "42170" # Port for the API server +API_HOST = "0.0.0.0" # Host for the API server +SCORING_KEY = "123" # The scoring key for the validator (must match the scoring key in the .env.validator file) +SCORE_ORGANICS = True # Whether to score organics +VALIDATOR_API = "0.0.0.0:8094" # The validator API to forward responses to for scoring \ No newline at end of file diff --git a/api.config.js b/api.config.js new file mode 100644 index 00000000..b0308f84 --- /dev/null +++ b/api.config.js @@ -0,0 +1,12 @@ +module.exports = { + apps: [ + { + name: 'api_server', + script: 'poetry', + interpreter: 'none', + args: ['run', 'python', 'validator_api/api.py'], + min_uptime: '5m', + max_restarts: 5 + } + ] +}; diff --git a/api_keys.json b/api_keys.json index 0967ef42..9e26dfee 100644 --- a/api_keys.json +++ b/api_keys.json @@ -1 +1 @@ -{} +{} \ No newline at end of file diff --git a/run_api.sh b/run_api.sh index 6614e20f..40dcc610 100644 --- a/run_api.sh +++ b/run_api.sh @@ -29,7 +29,7 @@ echo "module.exports = { name: 'api_server', script: 'poetry', interpreter: 'none', - args: ['run', 'python', 'api/api.py'], + args: ['run', 'python', 'validator_api/api.py'], min_uptime: '5m', max_restarts: 5 } diff --git a/shared/settings.py b/shared/settings.py index 9de9c091..1fb9f84d 100644 --- a/shared/settings.py +++ b/shared/settings.py @@ -212,7 +212,6 @@ def load(cls, mode: Literal["miner", "validator", "mock", "api"]) -> "SharedSett def complete_settings(cls, values: dict[str, Any]) -> dict[str, Any]: mode = values["mode"] netuid = values.get("NETUID", 61) - if netuid is None: raise ValueError("NETUID must be specified") values["TEST"] = netuid != 1 @@ -224,32 +223,6 @@ def complete_settings(cls, values: dict[str, Any]) -> dict[str, Any]: logger.info("Running in mock mode. Bittensor objects will not be initialized.") return values - # load slow packages only if not in mock mode - import torch - - if not values.get("NEURON_DEVICE"): - values["NEURON_DEVICE"] = "cuda" if torch.cuda.is_available() else "cpu" - - # Ensure SAVE_PATH exists. - save_path = values.get("SAVE_PATH", "./storage") - if not os.path.exists(save_path): - os.makedirs(save_path) - if values.get("SN19_API_KEY") is None or values.get("SN19_API_URL") is None: - logger.warning( - "It is strongly recommended to provide an SN19 API KEY + URL to avoid incurring OpenAI API costs." - ) - if mode == "validator": - if values.get("OPENAI_API_KEY") is None: - raise Exception( - "You must provide an OpenAI API key as a backup. It is recommended to also provide an SN19 API key + url to avoid incurring API costs." - ) - if values.get("SCORING_ADMIN_KEY") is None and values.get("DEPLOY_SCORING_API"): - logger.warning("You must provide a SCORING_ADMIN_KEY to access the API. Disabling scoring endpoint") - values["DEPLOY_SCORING_API"] = False - if values.get("PROXY_URL") is None: - logger.warning( - "You must provide a proxy URL to use the DuckDuckGo API - your vtrust might decrease if no DDG URL is provided." - ) return values @cached_property diff --git a/validator_api/API_docs.md b/validator_api/API_docs.md index 71030a30..bf609989 100644 --- a/validator_api/API_docs.md +++ b/validator_api/API_docs.md @@ -20,10 +20,15 @@ This document describes the API endpoints available for [Subnet 1](https://githu ## Getting Started -Follow these steps to set up and run the API server: +SN1 can run either in validator mode or in API mode. Both modes will require the validator hotkey. + +As a validator, you MUST be running one instance in validator mode and can launch an arbitrary number of API instances. These API instances will proxy the responses from miners to the validator for scoring. + +To set up and run the API server: 1. **Install dependencies**: Ensure all required dependencies are installed using Poetry. -2. **Run the API server**: Start the server to access the API endpoints. +2. **Set up the .env.api file**: Copy the .env.api.example file to .env.api and fill in the validator hotkey. +3. **Run the API server**: Start the server to access the API endpoints. Use the following command: