|
44 | 44 | create_investor_agent_toolkit, |
45 | 45 | create_analytics_agent_toolkit, |
46 | 46 | ) |
47 | | -from subnet.subnet_methods import subnet_evaluation |
| 47 | +from subnet.subnet_methods import subnet_evaluation, subnet_query |
48 | 48 | from subnet.api_types import QuantQuery, QuantResponse |
49 | 49 | from langchain_openai import ChatOpenAI |
50 | 50 | from server.invitecode import InviteCodeManager |
@@ -448,6 +448,57 @@ async def evaluate_subnet_response( |
448 | 448 | logging.error(f"Traceback: {traceback.format_exc()}") |
449 | 449 | raise HTTPException(status_code=500, detail="Internal server error") |
450 | 450 |
|
| 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 | + |
451 | 502 | # @app.post("/api/sentient/assist") |
452 | 503 | async def sentient_assist( |
453 | 504 | request: Request, |
|
0 commit comments