Spaces:
Sleeping
Sleeping
| import { query } from '@/shared/api/query'; | |
| import { LlmPrompt } from './types'; | |
| export const fetchLlmPrompts = async (): Promise<LlmPrompt[]> => { | |
| const response = await query<LlmPrompt[]>({ | |
| url: '/llm_prompt/', | |
| method: 'get', | |
| }); | |
| if ('error' in response) { | |
| throw new Error(`Ошибка получения промптов: ${response.error.status}`); | |
| } | |
| return response.data; | |
| }; | |
| export const fetchLlmPromptById = async (id: number): Promise<LlmPrompt> => { | |
| const response = await query<LlmPrompt>({ | |
| url: `/llm_prompt/${id}`, | |
| method: 'get', | |
| }); | |
| if ('error' in response) { | |
| throw new Error(`Ошибка получения промпта: ${response.error.status}`); | |
| } | |
| return response.data; | |
| }; | |
| export const createLlmPrompt = async (config: Omit<LlmPrompt, 'id' | 'created_at'>): Promise<LlmPrompt> => { | |
| const response = await query<LlmPrompt>({ | |
| url: '/llm_prompt/', | |
| method: 'post', | |
| data: config, | |
| }); | |
| if ('error' in response) { | |
| throw new Error(`Ошибка создания промпта: ${response.error.status}`); | |
| } | |
| return response.data; | |
| }; | |
| export const updateLlmPrompt = async (config: LlmPrompt): Promise<void> => { | |
| const response = await query<void>({ | |
| url: `/llm_prompt/${config.id}`, | |
| method: 'put', | |
| data: config, | |
| }); | |
| if ('error' in response) { | |
| throw new Error(`Ошибка обновления промпта: ${response.error.status}`); | |
| } | |
| }; | |
| export const setDefaultLlmPrompt = async (id: number): Promise<void> => { | |
| const response = await query<void>({ | |
| url: `/llm_prompt/default/${id}`, | |
| method: 'put', | |
| }); | |
| if ('error' in response) { | |
| throw new Error(`Ошибка установки промпта по умолчанию: ${response.error.status}`); | |
| } | |
| }; | |
| export const deleteLlmPrompt = async (id: number): Promise<void> => { | |
| const response = await query<void>({ | |
| url: `/llm_prompt/${id}`, | |
| method: 'delete', | |
| }); | |
| if ('error' in response) { | |
| throw new Error(`Ошибка удаления промпта: ${response.error.status}`); | |
| } | |
| }; | |
| export const fetchDefaultLlmPrompt = async (): Promise<LlmPrompt | null> => { | |
| const response = await query<LlmPrompt>({ | |
| url: '/llm_prompt/default', | |
| method: 'get', | |
| }); | |
| if ('error' in response) { | |
| if (response.error.status === 404) return null; // Если дефолтной записи нет | |
| throw new Error(`Ошибка получения дефолтной промпта: ${response.error.status}`); | |
| } | |
| return response.data; | |
| }; |