Skip to content

Commit 0348007

Browse files
use code
1 parent baf1530 commit 0348007

File tree

1 file changed

+45
-4
lines changed

1 file changed

+45
-4
lines changed

server/fastapi_server.py

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
Message,
2828
TokenMetadata,
2929
SolanaVerifyRequest,
30+
Context,
31+
UserMessage,
3032
)
3133
from agent.agent_executors import (
3234
create_investor_executor,
@@ -483,11 +485,50 @@ async def subnet_query_endpoint(
483485
# Parse the request data into QuantQuery object
484486
quant_query = QuantQuery(**request_data)
485487

486-
# Call the actual subnet query function
487-
quant_response = await asyncio.to_thread(subnet_query, quant_query)
488+
# Convert QuantQuery to AgentChatRequest format
489+
# Use userID as wallet address
490+
wallet_address = quant_query.userID
488491

489-
if quant_response is None:
490-
raise HTTPException(status_code=500, detail="Subnet query failed")
492+
# Create AgentChatRequest structure
493+
agent_request = AgentChatRequest(
494+
context=Context(
495+
address=wallet_address,
496+
conversationHistory=[],
497+
miner_token=None
498+
),
499+
message=UserMessage(
500+
message=quant_query.query
501+
),
502+
agent=None, # Let router decide
503+
captchaToken=None # No captcha for subnet
504+
)
505+
506+
# Get portfolio for the wallet address
507+
portfolio = await portfolio_fetcher.get_portfolio(
508+
wallet_address=wallet_address
509+
)
510+
511+
# Process the request using the same logic as run_agent
512+
response = await handle_agent_chat_request(
513+
token_metadata_repo=token_metadata_repo,
514+
protocol_registry=protocol_registry,
515+
request=agent_request,
516+
portfolio=portfolio,
517+
investor_agent=investor_agent,
518+
analytics_agent=analytics_agent,
519+
router_model=router_model,
520+
)
521+
522+
# Convert response to QuantResponse format
523+
quant_response = QuantResponse(
524+
response=response.message,
525+
signature=b"", # Empty signature for now
526+
proofs=[], # Empty proofs for now
527+
metadata={
528+
"pools": [pool.model_dump() for pool in response.pools],
529+
"tokens": [token.model_dump() for token in response.tokens]
530+
}
531+
)
491532

492533
return quant_response.model_dump()
493534

0 commit comments

Comments
 (0)