Open-WebUI API Call Python
This revision is from 2024/10/09 06:30. You can Restore it.
import requests
import json
# API endpointurl = "http://192.168.x.x:3000/api/chat/completions"
# Your API keyapi_key = "sk-xxxxxxxxxxxxxxxxxxxxxxx"
# Headersheaders = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
} # Request payloadpayload = {
"model": "pivot-0.1-evil-a.Q8_0.gguf:latest",
"messages": [
{
"role": "user",
"content": "Why is the sky blue?"
}
]
} # Make the POST requestresponse = requests.post(url, headers=headers, data=json.dumps(payload))
# Check if the request was successfulif response.status_code == 200:
# Parse the JSON response
result = response.json()
print(json.dumps(result, indent=2))
else:
print(f"Error: {response.status_code}")
print(response.text)