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

@@ -69,6 +69,39 @@ with ChatClient(api_key="fastgpt-xxxxx") as client:
)
```
### Chat with an Image
Upload the image to FastGPT's chat file storage first, then reference the returned URL in a chat message.
```python
from fastgpt_client import ChatClient
app_id = "your-app-id"
chat_id = "my_conversation_123"
with ChatClient(api_key="fastgpt-xxxxx", base_url="http://localhost:3000") as client:
image = client.upload_chat_image(
appId=app_id,
chatId=chat_id,
file_path="example.png",
)
response = client.create_chat_completion(
chatId=chat_id,
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "Please describe this image."},
{"type": "image_url", "image_url": {"url": image["url"]}},
],
}
],
)
print(response.json()["choices"][0]["message"]["content"])
```
### Using Variables
```python