forked from Datura-ai/desearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
55 lines (46 loc) · 1.69 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import bittensor as bt
from datura.protocol import ScraperStreamingSynapse
import json
import asyncio
import sys # Import the sys module to access command-line arguments
wallet = bt.wallet(name="validator", hotkey="default")
if len(sys.argv) > 1:
uids = [int(sys.argv[1])] # Set uids from the command-line argument
else:
print("Error: Please provide a user ID as a command-line argument.")
sys.exit(1)
message = "What are news about in Georgia country?"
axon = bt.axon(wallet=wallet)
dendrite = bt.dendrite(wallet=wallet)
bt.debug(True)
# construct the synapse from the protocol using the message and whatever else we need
synapse = ScraperStreamingSynapse(
messages=message, model="gpt-4-1106-preview", seed=1234
)
meta = bt.metagraph(netuid=22)
axons = [meta.axons[uid] for uid in uids]
async def main():
bt.logging.debug(f"Connecting miner uids {uids}")
async with bt.dendrite(wallet=wallet) as dendrite:
async_responses = await dendrite.forward(
axons=axons,
synapse=synapse,
deserialize=False,
timeout=120,
streaming=True,
)
full_response = ""
response_received = False
for resp in async_responses:
async for chunk in resp:
if isinstance(chunk, str):
bt.logging.trace(chunk)
full_response += chunk
response_received = True
if not response_received:
bt.logging.debug("No response from miner")
break
bt.logging.debug(f"Full_response: {full_response}")
bt.logging.debug("Finished connecting miner")
if __name__ == "__main__":
asyncio.run(main())