UploadChatFile uploads a file for use in chat messages.
(ctx context.Context, organizationID uuid.UUID, contentType string, filename string, rd io.Reader)
| 3276 | |
| 3277 | // UploadChatFile uploads a file for use in chat messages. |
| 3278 | func (c *ExperimentalClient) UploadChatFile(ctx context.Context, organizationID uuid.UUID, contentType string, filename string, rd io.Reader) (UploadChatFileResponse, error) { |
| 3279 | res, err := c.Request(ctx, http.MethodPost, fmt.Sprintf("/api/experimental/chats/files?organization=%s", organizationID), rd, func(r *http.Request) { |
| 3280 | r.Header.Set("Content-Type", contentType) |
| 3281 | if filename != "" { |
| 3282 | r.Header.Set("Content-Disposition", mime.FormatMediaType("attachment", map[string]string{"filename": filename})) |
| 3283 | } |
| 3284 | }) |
| 3285 | if err != nil { |
| 3286 | return UploadChatFileResponse{}, err |
| 3287 | } |
| 3288 | defer res.Body.Close() |
| 3289 | if res.StatusCode != http.StatusCreated { |
| 3290 | return UploadChatFileResponse{}, ReadBodyAsError(res) |
| 3291 | } |
| 3292 | var resp UploadChatFileResponse |
| 3293 | return resp, json.NewDecoder(res.Body).Decode(&resp) |
| 3294 | } |
| 3295 | |
| 3296 | // GetChatFile retrieves a previously uploaded chat file by ID. |
| 3297 | func (c *ExperimentalClient) GetChatFile(ctx context.Context, fileID uuid.UUID) ([]byte, string, error) { |