|
| 1 | +import axios from 'axios'; |
| 2 | + |
| 3 | +const API_BASE_URL = 'https://www.branchify.site/api'; |
| 4 | + |
| 5 | +// 어시스턴트 생성 API (POST 요청) |
| 6 | +export const createAssistant = async ({ |
| 7 | + modelName, |
| 8 | + openaiApiKey, |
| 9 | + assistantName, |
| 10 | + prompt, |
| 11 | +}) => { |
| 12 | + const accessToken = localStorage.getItem('access_token'); |
| 13 | + |
| 14 | + const response = await axios.post( |
| 15 | + `${API_BASE_URL}/assistantlist`, |
| 16 | + { modelName, openaiApiKey, assistantName, prompt }, |
| 17 | + { |
| 18 | + headers: { |
| 19 | + Authorization: `Bearer ${accessToken}`, |
| 20 | + 'Content-Type': 'application/json', |
| 21 | + }, |
| 22 | + } |
| 23 | + ); |
| 24 | + |
| 25 | + return response.data; |
| 26 | +}; |
| 27 | + |
| 28 | +//어시스턴트 업데이트 (Step 3에서 호출) |
| 29 | +export const updateAssistant = async ({ assistantName, actionTags }) => { |
| 30 | + if ( |
| 31 | + !assistantName || |
| 32 | + typeof assistantName !== 'string' || |
| 33 | + assistantName.trim() === '' |
| 34 | + ) { |
| 35 | + throw new Error( |
| 36 | + '유효하지 않은 assistantName입니다. 요청을 보낼 수 없습니다.' |
| 37 | + ); |
| 38 | + } |
| 39 | + |
| 40 | + const accessToken = localStorage.getItem('access_token'); |
| 41 | + |
| 42 | + try { |
| 43 | + console.log( |
| 44 | + '최종 PATCH URL:', |
| 45 | + `${API_BASE_URL}/assistantlist/${assistantName}` |
| 46 | + ); |
| 47 | + console.log('보낼 데이터:', { actionTags }); |
| 48 | + |
| 49 | + const response = await axios.patch( |
| 50 | + `${API_BASE_URL}/assistantlist/${assistantName}`, |
| 51 | + { actionTag: actionTags }, |
| 52 | + { |
| 53 | + headers: { |
| 54 | + Authorization: `Bearer ${accessToken}`, |
| 55 | + 'Content-Type': 'application/json', |
| 56 | + }, |
| 57 | + } |
| 58 | + ); |
| 59 | + return response.data; |
| 60 | + } catch (error) { |
| 61 | + console.error( |
| 62 | + 'Error updating assistant:', |
| 63 | + error.response?.data || error.message |
| 64 | + ); |
| 65 | + throw error; |
| 66 | + } |
| 67 | +}; |
0 commit comments