Add chat image upload support

This commit is contained in:
Xin Wang
2026-06-01 13:39:22 +08:00
parent a55ca37c39
commit 96d685da91
7 changed files with 951 additions and 4 deletions

View File

@@ -58,6 +58,82 @@ print(result['choices'][0]['message']['content'])
---
### upload_chat_image
Upload an image to FastGPT's chat file storage and return a normalized file reference.
```python
image = client.upload_chat_image(
appId="app-123",
chatId="chat-123",
file_path="example.png"
)
response = client.create_chat_completion(
chatId="chat-123",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "Describe this image"},
{"type": "image_url", "image_url": {"url": image["url"]}},
],
}
],
)
```
Returned file reference:
```python
{
"type": "img",
"name": "example.png",
"key": "chat/...",
"url": "https://...",
"previewUrl": "https://..."
}
```
---
### upload_chat_file
Upload a generic chat file. This is the lower-level helper used by `upload_chat_image`.
```python
file_ref = client.upload_chat_file(
appId="app-123",
chatId="chat-123",
file_path="document.pdf",
file_type="doc"
)
```
---
### presign_chat_file_post_url
Request a presigned upload URL for a chat file. The SDK supports both FastGPT response shapes:
- Presigned POST: `{ "url": "...", "fields": {...}, "maxSize": ... }`
- Presigned PUT: `{ "url": "...", "headers": {...}, "key": "...", "previewUrl": "..." }`
---
### presign_chat_file_get_url
Request a temporary preview/download URL by file `key`.
```python
preview_url = client.presign_chat_file_get_url(
appId="app-123",
key="chat/..."
)
```
---
### get_chat_histories
Get chat histories for an application.