import asyncio
import json

import httpx

API_URL = "http://172.16.4.139:5001/v1/chat/completions"
# Lay key trong config.json (mac dinh la your-api-key-1)
API_KEY = "your-api-key-1"

async def main():
    # 1 cai anh base64 nho de test doc anh
    b64 = "/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAP//////////////////////////////////////////////////////////////////////////////////////wgALCAABAAEBAREA/8QAFBABAAAAAAAAAAAAAAAAAAAAAP/aAAgBAQABPxA="
    
    payload = {
        "model": "deepseek-v4-vision",
        "messages": [
            {
                "role": "user",
                "content": [
                    {
                        "type": "text",
                        "text": "Mô tả bức ảnh này bằng tiếng Việt."
                    },
                    {
                        "type": "image_url",
                        "image_url": {
                            "url": f"data:image/jpeg;base64,{b64}"
                        }
                    }
                ]
            }
        ],
        "max_tokens": 500
    }
    
    print(f"Testing DS2API VISION at: {API_URL} ...")
    try:
        async with httpx.AsyncClient(timeout=60) 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())
