Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion quant/utils/questions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import bittensor as bt
import requests
import random


"""
List of questions that can be answered by the crypto analysis document.
"""
Expand Down Expand Up @@ -50,4 +55,36 @@
"What are the top 3 safest memecoins to buy on Sui?",
"What are the top 3 safest memecoins to buy on Base?",
"What are the top 3 safest memecoins to buy on Ethereum?",
]
]


def fetch_question_once(
api_url: str = "https://quant-api.opengradient.ai/api/subnet/question",
timeout: float = 60.0,
) -> str:
response_obj = requests.get(
api_url,
timeout=timeout
)

response_obj.raise_for_status()
question_result = response_obj.json()
return question_result["question"]


def fetch_question(
api_url: str = "https://quant-api.opengradient.ai/api/subnet/question",
timeout: float = 60.0,
retry_count: int = 3,
) -> str:
for i in range(retry_count + 1):
try:
question = fetch_question_once(api_url, timeout=timeout)
bt.logging.info(f"Fetched question: '{question}'")
return question
except Exception as ex:
bt.logging.warning(f"Question fetch failed during try no. {i + 1} on: {ex}")

question = random.choice(questions)
bt.logging.warning(f"Fetching question failed too many times; returning one of the default questions: '{question}'")
return question
5 changes: 2 additions & 3 deletions quant/validator/forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@

import os
import time
import random
import bittensor as bt

from quant.protocol import QuantQuery, QuantSynapse
from quant.validator.reward import get_rewards
from quant.utils.uids import get_random_uids
from quant.utils.questions import questions
from quant.utils.questions import fetch_question


async def forward(self):
Expand All @@ -46,7 +45,7 @@ async def forward(self):
wallet_address = "5HHSqMvTCvgtzdqFb5BbtYjB8cEiJjf8UZ6p5rQczagL"

query = QuantQuery(
query=random.choice(questions),
query=fetch_question(),
userID=wallet_address,
metadata={
"Create_Proof": "True",
Expand Down