mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
DOCS: add OpenAI-compatible http and python api reference (#5374)
### What problem does this PR solve? Add OpenAI-compatible http and python api reference ### Type of change - [x] Documentation Update --------- Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com> Co-authored-by: writinwaters <93570324+writinwaters@users.noreply.github.com>
This commit is contained in:
@ -13,10 +13,63 @@ Run the following command to download the Python SDK:
|
||||
```bash
|
||||
pip install ragflow-sdk
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
## OpenAI-Compatible API
|
||||
|
||||
---
|
||||
|
||||
### Create chat completion
|
||||
|
||||
Creates a model response for the given historical chat conversation via OpenAI's API.
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### model: `str`, *Required*
|
||||
|
||||
The model used to generate the response. The server will parse this automatically, so you can set it to any value for now.
|
||||
|
||||
##### messages: `list[object]`, *Required*
|
||||
|
||||
A list of historical chat messages used to generate the response. This must contain at least one message with the `user` role.
|
||||
|
||||
##### stream: `boolean`
|
||||
|
||||
Whether to receive the response as a stream. Set this to `false` explicitly if you prefer to receive the entire response in one go instead of as a stream.
|
||||
|
||||
#### Returns
|
||||
|
||||
- Success: Respose [message](https://platform.openai.com/docs/api-reference/chat/create) like OpenAI
|
||||
- Failure: `Exception`
|
||||
|
||||
#### Examples
|
||||
|
||||
```python
|
||||
from openai import OpenAI
|
||||
|
||||
model = "model"
|
||||
client = OpenAI(api_key="ragflow-api-key", base_url=f"http://ragflow_address/api/v1/chats_openai/<chat_id>")
|
||||
|
||||
completion = client.chat.completions.create(
|
||||
model=model,
|
||||
messages=[
|
||||
{"role": "system", "content": "You are a helpful assistant."},
|
||||
{"role": "user", "content": "Who are you?"},
|
||||
],
|
||||
stream=True
|
||||
)
|
||||
|
||||
stream = True
|
||||
if stream:
|
||||
for chunk in completion:
|
||||
print(chunk)
|
||||
else:
|
||||
print(completion.choices[0].message.content)
|
||||
```
|
||||
|
||||
## DATASET MANAGEMENT
|
||||
|
||||
---
|
||||
|
||||
Reference in New Issue
Block a user