-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathexample_inference_worker.py
More file actions
35 lines (27 loc) · 1.26 KB
/
example_inference_worker.py
File metadata and controls
35 lines (27 loc) · 1.26 KB
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
import asyncio
import logging
from allora_sdk import AlloraNetworkConfig, AlloraWalletConfig, AlloraWorker, RunContext, get_block_time
from datetime import datetime, timedelta
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
async def run_model(context: RunContext) -> float:
nonce_time = await get_block_time(context.client, context.nonce)
prediction_time = nonce_time.replace(second=0, microsecond=0) + timedelta(days = 1)
logger.info(f'Generate prediction for epoch starting at {nonce_time}')
logger.info(f'As this is a 1 day BTC/USD price prediction topic, we need to the predict the price of BTC at {prediction_time}')
# sophisticated machine learning model
prediction = 123.45
return prediction
async def main():
worker = AlloraWorker.inferer(
topic_id=69,
# wallet=AlloraWalletConfig(mnemonic="..."), # uncomment to use a specific wallet instead of generating one
network=AlloraNetworkConfig.testnet(),
run=run_model,
)
async for result in worker.run():
if isinstance(result, Exception):
logger.error("Inference worker error", exc_info=result)
continue
logger.info(f"Prediction submitted to Allora: {result.submission}")
asyncio.run(main())