import asyncio
import io
import json
import sys

import httpx

sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')

async def main():
    payload = {"user_query": "tìm sịp nam cực sinh", "user_insight": None, "chat_history_summary": ""}
    async with httpx.AsyncClient(timeout=60.0) as client:
        resp = await client.post("http://localhost:5000/api/agent/lead-stage", json=payload)
        with open("out2.txt", "w", encoding="utf-8") as f:
            f.write(json.dumps(resp.json(), indent=2, ensure_ascii=False))

if __name__ == "__main__":
    asyncio.run(main())
