diff --git a/.env.validator.example b/.env.validator.example index 79bf81c4a..0e1bee89c 100644 --- a/.env.validator.example +++ b/.env.validator.example @@ -24,7 +24,9 @@ SN19_API_URL = "e.g. http://24.199.112.174:4051/" OPENAI_API_KEY = "your_openai_api_key_here" HF_TOKEN = "your_huggingface_token_here" -# Scoring API. +# Scoring API (optional). DEPLOY_SCORING_API = true SCORING_ADMIN_KEY = "123456" SCORING_API_PORT = 8094 +# Scoring key must match the scoring key in the .env.api. +# SCORING_KEY="..." diff --git a/prompting/llms/model_manager.py b/prompting/llms/model_manager.py index b0f516af2..135054a63 100644 --- a/prompting/llms/model_manager.py +++ b/prompting/llms/model_manager.py @@ -159,9 +159,9 @@ class AsyncModelScheduler(AsyncLoopRunner): interval: int = 14400 scoring_queue: list | None = None - async def start(self, scoring_queue: list): + async def start(self, scoring_queue: list, name: str | None = None): self.scoring_queue = scoring_queue - return await super().start() + return await super().start(name=name) async def initialise_loop(self): model_manager.load_always_active_models() diff --git a/prompting/rewards/scoring.py b/prompting/rewards/scoring.py index 5da5d2992..c314b6efa 100644 --- a/prompting/rewards/scoring.py +++ b/prompting/rewards/scoring.py @@ -27,10 +27,10 @@ class TaskScorer(AsyncLoopRunner): model_config = ConfigDict(arbitrary_types_allowed=True) - async def start(self, scoring_queue, reward_events): + async def start(self, scoring_queue, reward_events, name: str | None = None): self.scoring_queue = scoring_queue self.reward_events = reward_events - return await super().start() + return await super().start(name=name) def add_to_queue( self, diff --git a/prompting/weight_setting/weight_setter.py b/prompting/weight_setting/weight_setter.py index 12fc97c0f..f37102409 100644 --- a/prompting/weight_setting/weight_setter.py +++ b/prompting/weight_setting/weight_setter.py @@ -146,7 +146,7 @@ class WeightSetter(AsyncLoopRunner): class Config: arbitrary_types_allowed = True - async def start(self, reward_events): + async def start(self, reward_events, name: str | None = None): self.reward_events = reward_events global PAST_WEIGHTS @@ -159,7 +159,7 @@ async def start(self, reward_events): PAST_WEIGHTS = [] except Exception as ex: logger.error(f"Couldn't load weights from file: {ex}") - return await super().start() + return await super().start(name=name) async def run_step(self): await asyncio.sleep(0.01) diff --git a/scripts/test_api.py b/scripts/test_api.py index 07fc75806..0d6a265ba 100644 --- a/scripts/test_api.py +++ b/scripts/test_api.py @@ -30,7 +30,7 @@ async def make_completion(client: openai.AsyncOpenAI, prompt: str, stream: bool "do_sample": True, "seed": None, }, - "task": "QuestionAnsweringTask", + "task": "InferenceTask", "mixture": False, }, ) @@ -50,11 +50,12 @@ async def main(): # Example API key, replace with yours: API_KEY = "0566dbe21ee33bba9419549716cd6f1f" client = openai.AsyncOpenAI( - base_url=f"http://localhost:{PORT}/v1", + base_url=f"http://0.0.0.0:{PORT}/v1", max_retries=0, timeout=Timeout(90, connect=30, read=60), api_key=API_KEY, ) + client._client.headers["api-key"] = API_KEY response = await make_completion(client=client, prompt="Say 10 random numbers between 1 and 100", stream=True) print(response) diff --git a/shared/loop_runner.py b/shared/loop_runner.py index 636f2205f..af63570ee 100644 --- a/shared/loop_runner.py +++ b/shared/loop_runner.py @@ -104,14 +104,14 @@ async def run_loop(self): logger.info("Loop has been cleaned up.") logger.debug("Exiting run_loop") - async def start(self): + async def start(self, name: str | None = None): """Start the loop.""" if self.running: logger.warning("Loop is already running.") return self.running = True logger.debug(f"{self.name}: Starting loop with {'synchronized' if self.sync else 'non-synchronized'} mode") - self._task = asyncio.create_task(self.run_loop()) + self._task = asyncio.create_task(self.run_loop(), name=name) async def stop(self): """Stop the loop.""" diff --git a/shared/settings.py b/shared/settings.py index 1be9d5ea4..8f650099a 100644 --- a/shared/settings.py +++ b/shared/settings.py @@ -28,9 +28,6 @@ class SharedSettings(BaseSettings): _instance: Optional["SharedSettings"] = None _instance_mode: Optional[str] = None - # API - VALIDATOR_API: str = Field("0.0.0.0:8094", env="VALIDATOR_API") - VALIDATOR_SCORING_KEY: str = Field("1234567890", env="VALIDATOR_SCORING_KEY") mode: Literal["api", "validator", "miner", "mock"] = Field("validator", env="MODE") MOCK: bool = False @@ -87,19 +84,28 @@ class SharedSettings(BaseSettings): HF_TOKEN: Optional[str] = Field(None, env="HF_TOKEN") DEPLOY_VALIDATOR: bool = Field(True, env="DEPLOY_VALDITAOR") + # ==== API ===== + # API key used to access validator organic scoring mechanism (both .env.validator and .env.api). + SCORING_KEY: str | None = Field(None, env="SCORING_KEY") + + # Validator scoring API (.env.validator). DEPLOY_SCORING_API: bool = Field(False, env="DEPLOY_SCORING_API") SCORING_API_PORT: int = Field(8094, env="SCORING_API_PORT") SCORING_ADMIN_KEY: str | None = Field(None, env="SCORING_ADMIN_KEY") + SCORE_ORGANICS: bool = Field(False, env="SCORE_ORGANICS") + + # API Management (.env.api). API_PORT: int = Field(8005, env="API_PORT") API_HOST: str = Field("0.0.0.0", env="API_HOST") - - # API Management. + # Validator scoring API address. + VALIDATOR_API: str = Field("0.0.0.0:8094", env="VALIDATOR_API") + # File with keys used to access API. API_KEYS_FILE: str = Field("api_keys.json", env="API_KEYS_FILE") + # Admin key used to generate API keys. ADMIN_KEY: str | None = Field(None, env="ADMIN_KEY") - SCORING_KEY: str | None = Field(None, env="SCORING_KEY") - SCORE_ORGANICS: bool = Field(False, env="SCORE_ORGANICS") + # ============== - # Additional Fields. + # Additional Validator Fields. NETUID: Optional[int] = Field(61, env="NETUID") TEST: bool = False OPENAI_API_KEY: Optional[str] = Field(None, env="OPENAI_API_KEY")