import requests
import base64
import sys

if sys.argv[1] == "lms":
  URL = "http://localhost:1234/v1/chat/completions"
  MODEL = "qwen3.5-35b-a3b"
elif sys.argv[1] == "ollama":
  URL = "http://localhost:11434/v1/chat/completions" 
  MODEL = "qwen3-vl:8b" 

IMAGE_FILE = sys.argv[2]

headers = {
  "Content-Type": "application/json",
  "Authorization": "dummy"
}

# 画像をBase64エンコード
with open(IMAGE_FILE, "rb") as f:
  image_base64 = base64.b64encode(f.read()).decode("utf-8")

data = {
  "model": MODEL,
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "image_url",
          "image_url": {
            "url": f"data:image/png;base64,{image_base64}"
          }
        }
      ]
    }
  ],
  "temperature": 0.7
}

response = requests.post(URL, headers=headers, json=data)

if response.status_code == 200:
  result = response.json()
  print(result["choices"][0]["message"]["content"])
else:
  print("Error:", response.status_code)
  print(response.text)