import asyncio
import json

import httpx

API_URL = "http://127.0.0.1:5001/v1/chat/completions"
# Lay key mac dinh trong config.example.json cua ds2api
API_KEY = "sk-ds2api-default-admin-key" 

async def main():
    payload = {
        "model": "deepseek-v4-flash",
        "messages": [
            {"role": "user", "content": "Chào bạn, hãy giới thiệu bản thân bằng 1 câu ngắn gọn!"}
        ]
    }
    
    print(f"Testing DS2API at: {API_URL} ...")
    try:
        async with httpx.AsyncClient(timeout=30) as client:
            resp = await client.post(
                API_URL, 
                json=payload,
                headers={"Authorization": f"Bearer {API_KEY}"}
            )
            
            print("Status:", resp.status_code)
            try:
                data = resp.json()
                print("Response Data:\n")
                print(json.dumps(data, indent=2, ensure_ascii=False))
            except Exception:
                print("Raw Response:", resp.text)
    except Exception as e:
        print(f"Connection Error: {e}")

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