Files
arsam 9d0c5768c3 Import source: axon/routers/research
Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality.
2026-09-18 23:06:25 +03:30

50 lines
1.5 KiB
Python

import logging
import time
from fastapi import APIRouter
from axon.models import ResearchRequest, ResearchResponse, SearchRequest
from axon.routers.search import deduplicate_results, search
from axon.services.synthesizer import generate_sub_queries, synthesize_report
router = APIRouter()
logger = logging.getLogger(__name__)
@router.post("/research", response_model=ResearchResponse)
async def research(request: ResearchRequest) -> ResearchResponse:
start = time.monotonic()
sub_query_count = 5 if request.depth == "deep" else 3
sub_queries = await generate_sub_queries(request.query, sub_query_count)
search_requests = [
SearchRequest(
query=sub_query,
max_results=request.max_results_per_query,
search_depth=request.search_depth,
include_answer=False,
include_raw_content=True,
topic="general",
)
for sub_query in sub_queries
]
all_results = []
for search_request in search_requests:
try:
response = await search(search_request)
all_results.extend(response.results)
except Exception as exc:
logger.warning("Research sub-search failed: %s", exc)
sources = deduplicate_results(all_results)
report = await synthesize_report(request.query, sources, request.output_format)
return ResearchResponse(
query=request.query,
report=report,
sources=sources,
sub_queries=sub_queries,
response_time=round(time.monotonic() - start, 3),
)