| 18 | |
| 19 | // Uploads a file |
| 20 | export const uploadFile = async (file) => { |
| 21 | console.log('Uploading file...'); |
| 22 | const fileData = new FormData(); |
| 23 | fileData.append('file', file); |
| 24 | const response = await fetch('/api/upload', { |
| 25 | method: 'POST', |
| 26 | body: fileData, |
| 27 | }); |
| 28 | if (!response.ok) { |
| 29 | console.error('File upload failed'); |
| 30 | throw new Error('File upload failed'); |
| 31 | } |
| 32 | console.log('File uploaded successfully'); |
| 33 | const jsonResponse = await response.json(); |
| 34 | console.log('Server response:', jsonResponse); // Add this line |
| 35 | return { fileId: jsonResponse.fileId }; // return only the fileId |
| 36 | }; |
| 37 | |
| 38 | // Creates an assistant |
| 39 | export const createAssistant = async (assistantName, assistantModel, assistantDescription, fileIds) => { |