import { query } from '@/shared/api/query'; import { LLMConfig } from './types'; export const fetchLLMConfigs = async (): Promise => { const response = await query({ url: '/llm_config/', method: 'get', }); if ('error' in response) { throw new Error(`Ошибка получения конфигураций: ${response.error.status}`); } return response.data; }; export const fetchLLMConfigById = async (id: number): Promise => { const response = await query({ url: `/llm_config/${id}`, method: 'get', }); if ('error' in response) { throw new Error(`Ошибка получения конфигурации: ${response.error.status}`); } return response.data; }; export const createLLMConfig = async (config: Omit): Promise => { const response = await query({ url: '/llm_config/', method: 'post', data: config, }); if ('error' in response) { throw new Error(`Ошибка создания конфигурации: ${response.error.status}`); } return response.data; }; export const updateLLMConfig = async (config: LLMConfig): Promise => { const response = await query({ url: `/llm_config/${config.id}`, method: 'put', data: config, }); if ('error' in response) { throw new Error(`Ошибка обновления конфигурации: ${response.error.status}`); } }; export const setDefaultLLMConfig = async (id: number): Promise => { const response = await query({ url: `/llm_config/default/${id}`, method: 'put', }); if ('error' in response) { throw new Error(`Ошибка установки конфигурации по умолчанию: ${response.error.status}`); } }; export const deleteLLMConfig = async (id: number): Promise => { const response = await query({ url: `/llm_config/${id}`, method: 'delete', }); if ('error' in response) { throw new Error(`Ошибка удаления конфигурации: ${response.error.status}`); } }; export const fetchDefaultLLMConfig = async (): Promise => { const response = await query({ url: '/llm_config/default', method: 'get', }); if ('error' in response) { if (response.error.status === 404) return null; // Если дефолтной записи нет throw new Error(`Ошибка получения дефолтной конфигурации: ${response.error.status}`); } return response.data; };