import React, { useState, useEffect } from 'react'; import Modal from 'react-modal'; import { GoTrash, GoStar, GoStarFill } from 'react-icons/go'; import { useQuery } from '@tanstack/react-query'; import { useLLMConfigs, } from "@/api/llmConfigs/hooks"; import { LLMConfig } from "@/api/llmConfigs/types"; import './LlmConfigList.scss'; import LLMConfigModal from './LlmConfigModal'; import { fetchDefaultLLMConfig } from '@/api/llmConfigs/llmConfigApi'; Modal.setAppElement('#root'); const LLMConfigList: React.FC = () => { const { configs, isLoading, error, createConfig, updateConfig, setAsDefaultConfig, deleteConfig } = useLLMConfigs(); const [sortField, setSortField] = useState('id'); const [sortDirection, setSortDirection] = useState<'asc' | 'desc'>('asc'); const [selectedConfig, setSelectedConfig] = useState(null); const [isModalOpen, setIsModalOpen] = useState(false); const [isEditMode, setIsEditMode] = useState(false); // Функция для форматирования параметров в короткую строку const formatParameters = (config: LLMConfig) => { return `T:${config.temperature}, TP:${config.top_p}, MP:${config.min_p}, FP:${config.frequency_penalty}, PP:${config.presence_penalty}, S:${config.seed}, M:${config.model}`; }; const handleSort = (field: keyof LLMConfig | 'created_at') => { const newDirection = sortField === field && sortDirection === 'asc' ? 'desc' : 'asc'; setSortField(field); setSortDirection(newDirection); const sortedConfigs = [...configs].sort((a, b) => { const aValue = field === 'created_at' ? a.created_at || '' : a[field]; const bValue = field === 'created_at' ? b.created_at || '' : b[field]; return newDirection === 'asc' ? (aValue > bValue ? 1 : -1) : (aValue < bValue ? 1 : -1); }); configs.splice(0, configs.length, ...sortedConfigs); }; const openEditModal = (config: LLMConfig) => { setSelectedConfig(config); setIsEditMode(true); setIsModalOpen(true); }; const openCreateModal = () => { setSelectedConfig(null); // Ничего не передаем, запрос будет в модалке setIsEditMode(false); setIsModalOpen(true); }; const closeModal = () => { setSelectedConfig(null); setIsModalOpen(false); }; const handleSave = async (config: LLMConfig | Omit) => { if (isEditMode && 'id' in config) { await updateConfig(config as LLMConfig); } else { await createConfig(config as Omit); } }; const handleDelete = async (id: number) => { if (window.confirm('Are you sure you want to delete this config?')) { await deleteConfig(id); } }; const handleSetDefault = async (id: number) => { await setAsDefaultConfig(id); }; if (isLoading) return
Loading...
; if (error) return
Error: {error}
; return (

Настройки LLM

handleSort('created_at')}> Настройки
{configs.map(config => (
openEditModal(config)}> {formatParameters(config)} {/* Отображение параметров */}
{/*
openEditModal(config)}> {config.created_at || 'N/A'}
*/}
))}
); }; export default LLMConfigList;