Skip to content

Commit baf1530

Browse files
adambaloghbalogh.adam@icloud.com
andauthored
Add query endpoint (#104)
* expose * path --------- Co-authored-by: balogh.adam@icloud.com <adambalogh@Adams-MacBook-Pro.local>
1 parent fb9bccb commit baf1530

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

server/fastapi_server.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
create_investor_agent_toolkit,
4545
create_analytics_agent_toolkit,
4646
)
47-
from subnet.subnet_methods import subnet_evaluation
47+
from subnet.subnet_methods import subnet_evaluation, subnet_query
4848
from subnet.api_types import QuantQuery, QuantResponse
4949
from langchain_openai import ChatOpenAI
5050
from server.invitecode import InviteCodeManager
@@ -448,6 +448,57 @@ async def evaluate_subnet_response(
448448
logging.error(f"Traceback: {traceback.format_exc()}")
449449
raise HTTPException(status_code=500, detail="Internal server error")
450450

451+
@app.post("/api/subnet/query")
452+
async def subnet_query_endpoint(
453+
request: Request,
454+
):
455+
"""
456+
Handle subnet queries without authentication.
457+
458+
Expected request body:
459+
{
460+
"query": "string",
461+
"userID": "string",
462+
"metadata": {}
463+
}
464+
465+
Returns:
466+
{
467+
"response": "string",
468+
"signature": "bytes",
469+
"proofs": [],
470+
"metadata": {}
471+
}
472+
"""
473+
try:
474+
request_data = await request.json()
475+
476+
# Validate required fields
477+
if "query" not in request_data:
478+
raise HTTPException(
479+
status_code=400,
480+
detail="Query is required"
481+
)
482+
483+
# Parse the request data into QuantQuery object
484+
quant_query = QuantQuery(**request_data)
485+
486+
# Call the actual subnet query function
487+
quant_response = await asyncio.to_thread(subnet_query, quant_query)
488+
489+
if quant_response is None:
490+
raise HTTPException(status_code=500, detail="Subnet query failed")
491+
492+
return quant_response.model_dump()
493+
494+
except ValidationError as e:
495+
logging.error(f"Validation error in subnet query: {e}")
496+
raise HTTPException(status_code=400, detail=str(e))
497+
except Exception as e:
498+
logging.error(f"Error in subnet query: {e}")
499+
logging.error(f"Traceback: {traceback.format_exc()}")
500+
raise HTTPException(status_code=500, detail="Internal server error")
501+
451502
# @app.post("/api/sentient/assist")
452503
async def sentient_assist(
453504
request: Request,

subnet/subnet_methods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def subnet_query(quant_query: QuantQuery) -> QuantResponse:
175175
}
176176

177177
# Set the endpoint
178-
endpoint = "http://127.0.0.1:5000/api/agent/run"
178+
endpoint = "http://127.0.0.1:5000/api/v2/agent/run"
179179

180180
# Format the message
181181
message = {"type": "user", "message": quant_query.query}

0 commit comments

Comments
 (0)