Open-WebUI API Call Python

This revision is from 2024/10/09 06:30. You can Restore it.

import requests

import json

# API endpoint

url = "http://192.168.x.x:3000/api/chat/completions"

# Your API key

api_key = "sk-xxxxxxxxxxxxxxxxxxxxxxx"

# Headers

headers = {

"Authorization": f"Bearer {api_key}",

"Content-Type": "application/json"

} # Request payload

payload = {

"model": "pivot-0.1-evil-a.Q8_0.gguf:latest",

"messages": [

{

"role": "user",

"content": "Why is the sky blue?"

}

]

} # Make the POST request

response = requests.post(url, headers=headers, data=json.dumps(payload))

# Check if the request was successful

if 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)

  

📝 📜 ⏱️ ⬆️