This repository was archived by the owner on Jul 31, 2025. It is now read-only.
forked from opentensor/subtensor
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi.py
More file actions
63 lines (46 loc) · 1.61 KB
/
api.py
File metadata and controls
63 lines (46 loc) · 1.61 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
import uvicorn
from fastapi import FastAPI
from fastapi.templating import Jinja2Templates
from typing import Optional
from data_models import MinerConfig, BaseMiner, app
templates = Jinja2Templates(directory="templates")
@app.get("/")
def read_root():
"""
A function that handles the root GET request to the FastAPI application.
This function is decorated with `@app.get("/")` which means it will be called when a GET request is made to the root URL of the application.
Returns:
TemplateResponse: A response object that renders the "index.html" template.
"""
return templates.TemplateResponse("index.html")
def add_route(miner: BaseMiner, app: FastAPI):
"""
A function to add a route to the specified miner with the given FastAPI app.
Parameters:
- miner: BaseMiner - The miner object to add the route to.
- app: FastAPI - The FastAPI application to add the route to.
Returns:
- None
"""
miner.add_route(miner, app)
def serve_miner(
miner: BaseMiner, miner_config: MinerConfig, reload: Optional[bool] = True
):
"""
Serves the miner with the specified miner configuration.
Parameters:
- miner: BaseMiner - The miner object to serve.
- miner_config: MinerConfig - The configuration for the miner.
- reload: Optional[bool] - Whether to reload the miner. Defaults to True.
Returns:
- None
"""
miner.serve_miner(miner_config, reload=reload)
if __name__ == "__main__":
uvicorn.run(
"base.api:app",
host=os.getenv("MINER_HOST"),
port=os.getenv("MINER_PORT"),
reload=True,
)