From 8ff78b40f2c45c343ee43b9f94f74d06a38fd8a1 Mon Sep 17 00:00:00 2001 From: JJ Asghar Date: Sat, 15 Feb 2025 16:41:48 -0600 Subject: [PATCH] Added python chat completion example Added a `python` chat completion example like you have for RAG. --- docs/getting-started/api-endpoints.md | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/getting-started/api-endpoints.md b/docs/getting-started/api-endpoints.md index a342e40..022b09b 100644 --- a/docs/getting-started/api-endpoints.md +++ b/docs/getting-started/api-endpoints.md @@ -25,7 +25,8 @@ To ensure secure access to the API, authentication is required 🛡️. You can - **Endpoint**: `POST /api/chat/completions` - **Description**: Serves as an OpenAI API compatible chat completion endpoint for models on Open WebUI including Ollama models, OpenAI models, and Open WebUI Function models. -- **Example**: + +- **Curl Example**: ```bash curl -X POST http://localhost:3000/api/chat/completions \ @@ -41,6 +42,29 @@ To ensure secure access to the API, authentication is required 🛡️. You can ] }' ``` + +- **Python Example**: + ```python + import requests + + def chat_with_model(token): + url = 'http://localhost:3000/api/chat/completions' + headers = { + 'Authorization': f'Bearer {token}', + 'Content-Type': 'application/json' + } + data = { + "model": "granite3.1-dense:8b", + "messages": [ + { + "role": "user", + "content": "Why is the sky blue?" + } + ] + } + response = requests.post(url, headers=headers, data=data) + return response.json() + ``` ### 🧩 Retrieval Augmented Generation (RAG)