From 472ba83ef85a4ea056cd670cf0aa10d60371b530 Mon Sep 17 00:00:00 2001 From: Dmytro Bobrenko <17252809+dbobrenko@users.noreply.github.com> Date: Fri, 20 Dec 2024 15:01:13 +0000 Subject: [PATCH] Revert debug mode --- neurons/miners/epistula_miner/miner.py | 6 +- neurons/test_vanilla_post.py | 6 +- prompting/settings.py | 134 ------------------------- scripts/client.py | 6 +- 4 files changed, 9 insertions(+), 143 deletions(-) delete mode 100644 prompting/settings.py diff --git a/neurons/miners/epistula_miner/miner.py b/neurons/miners/epistula_miner/miner.py index 7e918830..d6887954 100644 --- a/neurons/miners/epistula_miner/miner.py +++ b/neurons/miners/epistula_miner/miner.py @@ -1,8 +1,8 @@ # ruff: noqa: E402 -from prompting import settings +from shared import settings -settings.settings = settings.Settings.load(mode="miner") -settings = settings.settings +settings.shared_settings = settings.SharedSettings.load(mode="miner") +shared_settings = settings.shared_settings import asyncio import json diff --git a/neurons/test_vanilla_post.py b/neurons/test_vanilla_post.py index ecd45878..31e6adeb 100644 --- a/neurons/test_vanilla_post.py +++ b/neurons/test_vanilla_post.py @@ -1,10 +1,10 @@ import openai from httpx import Timeout -from prompting import settings +from shared import settings -settings.settings = settings.Settings.load(mode="validator") -settings = settings.settings +settings.shared_settings = settings.SharedSettings.load(mode="validator") +shared_settings = settings.shared_settings from shared.epistula import create_header_hook diff --git a/prompting/settings.py b/prompting/settings.py deleted file mode 100644 index 01ce347d..00000000 --- a/prompting/settings.py +++ /dev/null @@ -1,134 +0,0 @@ -import os -from functools import cached_property -from typing import Any, Literal, Optional - -import bittensor as bt -import dotenv -from loguru import logger -from pydantic import Field, model_validator -from pydantic_settings import BaseSettings - - -class Settings(BaseSettings): - mode: Literal["miner", "validator", "mock"] - MOCK: bool = False - NO_BACKGROUND_THREAD: bool = True - SAVE_PATH: Optional[str] = Field("./storage", env="SAVE_PATH") - model_config = {"frozen": True, "arbitrary_types_allowed": False} - - # Class variables for singleton. - _instance: Optional["Settings"] = None - _instance_mode: Optional[str] = None - - @classmethod - def load_env_file(cls, mode: Literal["miner", "validator", "mock"]): - """Load the appropriate .env file based on the mode.""" - if mode == "miner": - dotenv_file = ".env.miner" - elif mode == "validator": - dotenv_file = ".env.validator" - # For mock testing, still make validator env vars available where possible. - elif mode == "mock": - dotenv_file = ".env.validator" - else: - raise ValueError(f"Invalid mode: {mode}") - - if dotenv_file: - if not dotenv.load_dotenv(dotenv.find_dotenv(filename=dotenv_file)): - logger.warning( - f"No {dotenv_file} file found. The use of args when running a {mode} will be deprecated " - "in the near future." - ) - - @classmethod - def load(cls, mode: Literal["miner", "validator", "mock"]) -> "Settings": - """Load or retrieve the Settings instance based on the mode.""" - if cls._instance is not None and cls._instance_mode == mode: - return cls._instance - else: - cls.load_env_file(mode) - cls._instance = cls(mode=mode) - cls._instance_mode = mode - return cls._instance - - @model_validator(mode="before") - 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 - if values.get("TEST_MINER_IDS"): - values["TEST_MINER_IDS"] = str(values["TEST_MINER_IDS"]).split(",") - if mode == "mock": - values["MOCK"] = True - values["NEURON_DEVICE"] = "cpu" - 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: - raise Exception("You must provide an admin key to access the API.") - 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 - def WALLET(self): - wallet_name = self.WALLET_NAME # or config().wallet.name - hotkey = self.HOTKEY # or config().wallet.hotkey - logger.info(f"Instantiating wallet with name: {wallet_name}, hotkey: {hotkey}") - return bt.wallet(name=wallet_name, hotkey=hotkey) - - @cached_property - def SUBTENSOR(self) -> bt.subtensor: - subtensor_network = self.SUBTENSOR_NETWORK or os.environ.get("SUBTENSOR_NETWORK", "local") - # bt_config = config() - if subtensor_network.lower() == "local": - subtensor_network = os.environ.get("SUBTENSOR_CHAIN_ENDPOINT") # bt_config.subtensor.chain_endpoint or - else: - subtensor_network = subtensor_network.lower() # bt_config.subtensor.network or - logger.info(f"Instantiating subtensor with network: {subtensor_network}") - return bt.subtensor(network=subtensor_network) - - @cached_property - def METAGRAPH(self) -> bt.metagraph: - logger.info(f"Instantiating metagraph with NETUID: {self.NETUID}") - return self.SUBTENSOR.metagraph(netuid=self.NETUID) - - @cached_property - def DENDRITE(self) -> bt.dendrite: - logger.info(f"Instantiating dendrite with wallet: {self.WALLET}") - return bt.dendrite(wallet=self.WALLET) - - -logger.info("Settings class instantiated.") -settings: Optional[Settings] = None -try: - settings: Optional[Settings] = Settings.load(mode="mock") - pass -except Exception as e: - logger.exception(f"Error loading settings: {e}") - settings = None -logger.info("Settings loaded.") diff --git a/scripts/client.py b/scripts/client.py index aabe7e43..3ef6d36c 100644 --- a/scripts/client.py +++ b/scripts/client.py @@ -1,7 +1,7 @@ -from prompting import settings +from shared import settings -settings.settings = settings.Settings.load(mode="validator") -settings = settings.settings +settings.shared_settings = settings.SharedSettings.load(mode="validator") +shared_settings = settings.shared_settings import asyncio import json