import requests
import json
# 定义 API 端点 URL
url = "http://localhost:11434/api/generate"
# 定义请求数据
data = {
"model": "qwen:1.8b",
"prompt": "Why is the sky blue?",
"stream": False
}
# 发送 POST 请求
response = requests.post(url, json=data)
# 检查响应状态码
if response.status_code == 200:
# 如果请求成功, 打印响应的 JSON 数据
result = response.json()
print("Response:", result)
else:
# 如果请求失败, 打印状态码和错误信息
print("Failed to generate response. Status code:", response.status_code)
print("Response:", response.text)