text requestの練習
import requests
API_SERVER_URL = "http://localhost:11434/api/chat"
def main():
headers = {"Content-Type": "application/json"}
json = {
"model": "qwen3-vl:2b",
"stream": False,
"messages": [
{"role": "user", "content": "日本の首都はどこ?"}
],
"options": {
"hide_thinking": True
}
}
response = requests.post(API_SERVER_URL, headers=headers, json=json, timeout=60)
response.raise_for_status()
data = response.json()
print( data["message"]["content"] )
if __name__ == '__main__':
main()
image requestの練習
import requests
import base64
API_SERVER_URL = "http://localhost:11434/api/chat"
def main():
image_path = "house_floor_plan_1f.png"
with open(image_path, "rb") as f:
image_base64 = base64.b64encode(f.read()).decode("utf-8")
payload = {
"model": "qwen3-vl:2b",
"stream": False,
"messages": [
{"role": "user",
"content": "この画像の内容を日本語で説明してください",
"images": [image_base64]
}
],
"options": { "hide_thinking": True}
}
response = requests.post(API_SERVER_URL, json=payload)
response.raise_for_status()
result = response.json()
print(result["message"]["content"])
if __name__ == '__main__':
main()