Skip to content

Commit

Permalink
fix errors with upgrade.
Browse files Browse the repository at this point in the history
  • Loading branch information
acer-king committed Oct 14, 2024
1 parent 514fe78 commit 2801190
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
7 changes: 7 additions & 0 deletions cortext/dendrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
from bittensor import dendrite
import traceback
import time
from typing import Optional

from cortext import StreamPrompting


class CortexDendrite(dendrite):
def __init__(
self, wallet: Optional[Union[bt.wallet, bt.Keypair]] = None
):
super().__init__(wallet)
self.process_time = 0

async def call_stream(
self,
target_axon: Union[bt.AxonInfo, bt.axon],
Expand Down
6 changes: 3 additions & 3 deletions organic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import traceback

from cortext.protocol import StreamPrompting, Bandwidth, IsAlive
from cortext.dendrite import CortexDendrite



async def query_miner(dendrite: bt.dendrite, axon_to_use, synapse, timeout, streaming):
async def query_miner(dendrite: CortexDendrite, axon_to_use, synapse, timeout, streaming):
try:
# print(f"calling vali axon {axon_to_use} to miner uid {synapse.uid} for query {synapse.messages}")
if streaming is False:
Expand Down Expand Up @@ -51,7 +51,7 @@ async def main():

# This needs to be your validator wallet that is running your subnet 18 validator
wallet = bt.wallet(name="miner", hotkey="default")
dendrite = bt.dendrite(wallet=wallet)
dendrite = CortexDendrite(wallet=wallet)
vali_uid = meta.hotkeys.index(wallet.hotkey.ss58_address)
axon_to_use = meta.axons[vali_uid]
print(f"axon to use: {axon_to_use}")
Expand Down
30 changes: 15 additions & 15 deletions validators/weight_setter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import asyncio
import concurrent
import random
import traceback

import torch
import time

Expand Down Expand Up @@ -455,27 +457,26 @@ async def _prompt(query_synapse: StreamPrompting, send: Send):

synapse.deserialize_flag = False
synapse.streaming = True
synapse.validator_uid = self.my_uid
synapse.block_num = self.current_block
synapse.validator_uid = self.my_uid or 0
synapse.block_num = self.current_block or 0
uid = self.task_mgr.assign_task(query_synapse)
if uid is None:
bt.logging.error("Can't create task. no available uids for now")
await send({"type": "http.response.body", "body": b'', "more_body": False})
return
bt.logging.trace(f"task is created and uid is {uid}")

async def handle_response(responses):
async def handle_response(resp):
response_text = ''
for resp in responses:
async for chunk in resp:
if isinstance(chunk, str):
await send({
"type": "http.response.body",
"body": chunk.encode("utf-8"),
"more_body": True,
})
response_text += chunk
bt.logging.trace(f"Streamed text: {chunk}")
async for chunk in resp:
if isinstance(chunk, str):
await send({
"type": "http.response.body",
"body": chunk.encode("utf-8"),
"more_body": True,
})
response_text += chunk
bt.logging.trace(f"Streamed text: {chunk}")

# Store the query and response in the shared database
async with self.lock:
Expand All @@ -494,11 +495,10 @@ async def handle_response(responses):

axon = self.metagraph.axons[uid]
await self.dendrite.aclose_session()
responses = await self.dendrite.call_stream(
responses = self.dendrite.call_stream(
target_axon=axon,
synapse=synapse,
timeout=synapse.timeout,
streaming=True,
)
return await handle_response(responses)

Expand Down

0 comments on commit 2801190

Please sign in to comment.