mirror of
https://github.com/open-webui/docs
synced 2025-05-20 03:08:56 +00:00
Added python chat completion example
Added a `python` chat completion example like you have for RAG.
This commit is contained in:
parent
a7b84acbb3
commit
8ff78b40f2
@ -25,7 +25,8 @@ To ensure secure access to the API, authentication is required 🛡️. You can
|
|||||||
|
|
||||||
- **Endpoint**: `POST /api/chat/completions`
|
- **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.
|
- **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
|
```bash
|
||||||
curl -X POST http://localhost:3000/api/chat/completions \
|
curl -X POST http://localhost:3000/api/chat/completions \
|
||||||
@ -42,6 +43,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)
|
### 🧩 Retrieval Augmented Generation (RAG)
|
||||||
|
|
||||||
The Retrieval Augmented Generation (RAG) feature allows you to enhance responses by incorporating data from external sources. Below, you will find the methods for managing files and knowledge collections via the API, and how to use them in chat completions effectively.
|
The Retrieval Augmented Generation (RAG) feature allows you to enhance responses by incorporating data from external sources. Below, you will find the methods for managing files and knowledge collections via the API, and how to use them in chat completions effectively.
|
||||||
|
Loading…
Reference in New Issue
Block a user