54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
from __future__ import annotations
|
|
|
|
import argparse
|
|
import asyncio
|
|
import json
|
|
|
|
from ai_search_agent.agent import AISearchAgent
|
|
from ai_search_agent.config import Settings
|
|
from ai_search_agent.models import SearchRequest
|
|
|
|
|
|
async def _run_query(args: argparse.Namespace) -> None:
|
|
settings = Settings.from_env()
|
|
agent = AISearchAgent(settings)
|
|
result = await agent.run(
|
|
SearchRequest(
|
|
query=args.query,
|
|
top_k_pages=args.top_k_pages,
|
|
max_page_chars=args.max_page_chars,
|
|
)
|
|
)
|
|
|
|
if args.json:
|
|
print(json.dumps(result.model_dump(), ensure_ascii=False, indent=2))
|
|
return
|
|
|
|
print(result.answer.summary)
|
|
if result.answer.key_points:
|
|
print("\nKey Points:")
|
|
for item in result.answer.key_points:
|
|
print(f"- {item}")
|
|
if result.answer.caveats:
|
|
print("\nCaveats:")
|
|
for item in result.answer.caveats:
|
|
print(f"- {item}")
|
|
if result.answer.citations:
|
|
print("\nSources:")
|
|
for item in result.answer.citations:
|
|
print(f"- {item.title}: {item.url}")
|
|
|
|
|
|
def main() -> None:
|
|
parser = argparse.ArgumentParser(description="Standalone AI search agent")
|
|
parser.add_argument("query", help="Search query")
|
|
parser.add_argument("--json", action="store_true", help="Print full JSON output")
|
|
parser.add_argument("--top-k-pages", type=int, default=None, help="How many pages to fetch")
|
|
parser.add_argument("--max-page-chars", type=int, default=None, help="Max chars per page")
|
|
args = parser.parse_args()
|
|
asyncio.run(_run_query(args))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|