Skip to content

Commit 4752c54

Browse files
author
richwardle
committed
Fix miner
1 parent bff3d3c commit 4752c54

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

neurons/miners/epistula_miner/miner.py

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def __init__(self):
4848
print("OpenAI Key: ", settings.OPENAI_API_KEY)
4949

5050
async def format_openai_query(self, request: Request):
51-
# Read the JSON data once
5251
data = await request.json()
5352

5453
# Extract the required fields
@@ -111,18 +110,16 @@ async def create_chat_completion(self, request: Request):
111110

112111
async def check_availability(self, request: Request):
113112
print("Checking availability")
114-
# Parse the incoming JSON request
115113
data = await request.json()
116114
task_availabilities = data.get('task_availabilities', {})
117115
llm_model_availabilities = data.get('llm_model_availabilities', {})
118116

119117
# Set all task availabilities to True
120118
task_response = {key: True for key in task_availabilities}
121119

122-
# Set all model availabilities to False
120+
# Set all model availabilities to False (openai will not be able to handle seeded inference)
123121
model_response = {key: False for key in llm_model_availabilities}
124122

125-
# Construct the response dictionary
126123
response = {
127124
'task_availabilities': task_response,
128125
'llm_model_availabilities': model_response
@@ -142,35 +139,35 @@ async def verify_request(
142139
# But use some specific fields from the body
143140
signed_by = request.headers.get("Epistula-Signed-By")
144141
signed_for = request.headers.get("Epistula-Signed-For")
145-
if signed_for != self.wallet.hotkey.ss58_address:
142+
if signed_for != settings.WALLET.hotkey.ss58_address:
146143
raise HTTPException(
147144
status_code=400, detail="Bad Request, message is not intended for self"
148145
)
149-
if signed_by not in self.metagraph.hotkeys:
146+
if signed_by not in settings.METAGRAPH.hotkeys:
150147
raise HTTPException(status_code=401, detail="Signer not in metagraph")
151148

152-
uid = self.metagraph.hotkeys.index(signed_by)
153-
stake = self.metagraph.S[uid].item()
154-
if not self.config.no_force_validator_permit and stake < 10000:
149+
uid = settings.METAGRAPH.hotkeys.index(signed_by)
150+
stake = settings.METAGRAPH.S[uid].item()
151+
if not settings.NETUID == 61 and stake < 10000:
155152
bt.logging.warning(
156153
f"Blacklisting request from {signed_by} [uid={uid}], not enough stake -- {stake}"
157154
)
158155
raise HTTPException(status_code=401, detail="Stake below minimum: {stake}")
159-
160-
# If anything is returned here, we can throw
161-
body = await request.body()
162-
err = verify_signature(
163-
request.headers.get("Epistula-Request-Signature"),
164-
body,
165-
request.headers.get("Epistula-Timestamp"),
166-
request.headers.get("Epistula-Uuid"),
167-
signed_for,
168-
signed_by,
169-
now,
170-
)
171-
if err:
172-
bt.logging.error(err)
173-
raise HTTPException(status_code=400, detail=err)
156+
# TODO: Implement the optional epistula signature verification
157+
# # If anything is returned here, we can throw
158+
# body = await request.body()
159+
# err = verify_signature(
160+
# request.headers.get("Epistula-Request-Signature"),
161+
# body,
162+
# request.headers.get("Epistula-Timestamp"),
163+
# request.headers.get("Epistula-Uuid"),
164+
# signed_for,
165+
# signed_by,
166+
# now,
167+
# )
168+
# if err:
169+
# bt.logging.error(err)
170+
# raise HTTPException(status_code=400, detail=err)
174171

175172
def run(self):
176173

@@ -205,7 +202,7 @@ def run(self):
205202
router.add_api_route(
206203
"/v1/chat/completions",
207204
self.create_chat_completion,
208-
#dependencies=[Depends(self.verify_request)],
205+
dependencies=[Depends(self.verify_request)],
209206
methods=["POST"],
210207
)
211208
router.add_api_route(

0 commit comments

Comments
 (0)