Spaces:
Sleeping
Sleeping
change: admin page llm config base url follows provider
Browse files18 unmodified lines192021222324252627282930313233343536373839189 unmodified lines2292302312322332342352367 unmodified lines24424524624724824925043 unmodified lines2942952962972982993001 unmodified line30230330430530630730830931078 unmodified lines38939039139239339485 unmodified lines4804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165178 unmodified lines52652752852953053153218 unmodified linesimport { patchLlmConfig } from '@/lib/rag-client';import type { LlmConfig, LlmForm } from '@/types/admin';const SYSTEM_PROMPT_TEMPLATES = [{label: 'RAG Assistant (Default)',value: 'Kamu adalah asisten AI yang membantu menjawab pertanyaan berdasarkan dokumen yang tersedia. Jawab pertanyaan dengan jelas, ringkas, dan berdasarkan konteks dokumen yang diberikan. Jika informasi tidak tersedia dalam dokumen, sampaikan dengan jujur.',},{label: 'Academic Assistant',value: 'Kamu adalah asisten akademik yang membantu mahasiswa memahami materi kuliah. Berikan penjelasan yang mudah dipahami, gunakan contoh yang relevan, dan dorong pemahaman konseptual.',},{label: 'Customer Support',value: 'Kamu adalah agen layanan pelanggan yang ramah dan profesional. Bantu pengguna menyelesaikan masalah mereka dengan solusi yang praktis dan komunikasi yang jelas.',},];const REASONING_EFFORT_OPTIONS: Record<string, string[]> = {deepseek: ['high', 'max'],openai: ['none', 'minimal', 'low', 'medium', 'high', 'xhigh'],189 unmodified linesconst initialSystemPromptKey = systemPromptKeys[0] ?? 'default';const initialProviderInfo = providers[cfg.active_provider ?? ''];const systemPromptKeyRef = useRef(initialSystemPromptKey);const [formData, setFormData] = useState<LlmForm>({active_model: stringValue(cfg.active_model),active_provider: stringValue(cfg.active_provider),7 unmodified lines});const [isSubmitting, setIsSubmitting] = useState(false);const [error, setError] = useState<string | undefined>();const [selectedTemplate, setSelectedTemplate] = useState<string>('');function setField<K extends keyof LlmForm>(key: K,43 unmodified linespayload.temperature = parseFloat(formData.temperature);if (formData.system_prompt) {payload.system_prompts = {[systemPromptKeyRef.current]: formData.system_prompt,};}1 unmodified lineconst savedProviders = result.providers ?? {};const savedSystemPrompts = result.system_prompts ?? {};const savedKeys = Object.keys(savedSystemPrompts);const savedKey = savedKeys[0] ?? systemPromptKeyRef.current;systemPromptKeyRef.current = savedKey;const savedProviderInfo = savedProviders[result.active_provider ?? ''];setFormData({78 unmodified lines/></Field><Fieldhint="Tingkat kreativitas jawaban (0–1). Rendah = konsisten, tinggi = lebih variatif."label="Temperature"85 unmodified lines</div><Fieldhint="URL endpoint API provider. Pilih dari daftar atau masukkan custom URL."label="Base URL"><CreatableBaseUrlSelectoptions={baseUrlOptions}value={formData.base_url}onChange={(v) => setField('base_url', v)}/></Field><Fieldhint="Pilih template untuk mengisi sistem prompt secara otomatis."label="Template System Prompt"><Selectvalue={selectedTemplate}onValueChange={(label) => {setSelectedTemplate(label);const template = SYSTEM_PROMPT_TEMPLATES.find((t) => t.label === label,);if (template)setField('system_prompt', template.value);}}><SelectTrigger className="w-full"><SelectValue placeholder="Pilih template..." /></SelectTrigger><SelectContent>{SYSTEM_PROMPT_TEMPLATES.map((t) => (<SelectItem key={t.label} value={t.label}>{t.label}</SelectItem>))}</SelectContent>8 unmodified linesclassName="border-input ring-offset-background placeholder:text-muted-foreground focus-visible:ring-ring min-h-36 w-full rounded-md border px-3 py-2 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2"value={formData.system_prompt}onChange={(event) => {setSelectedTemplate('');setField('system_prompt', event.target.value);}}/>18 unmodified lines192021222324189 unmodified lines2142152162172182197 unmodified lines22722822923023123223343 unmodified lines2772782792802812822831 unmodified line28528628728828929029129229329429578 unmodified lines37437537637737837938038138238338438538638738838939039139239385 unmodified lines4794804814824834844854864874884894904914924934944954964974984995005015028 unmodified lines51151251351451551618 unmodified linesimport { patchLlmConfig } from '@/lib/rag-client';import type { LlmConfig, LlmForm } from '@/types/admin';const REASONING_EFFORT_OPTIONS: Record<string, string[]> = {deepseek: ['high', 'max'],openai: ['none', 'minimal', 'low', 'medium', 'high', 'xhigh'],189 unmodified linesconst initialSystemPromptKey = systemPromptKeys[0] ?? 'default';const initialProviderInfo = providers[cfg.active_provider ?? ''];const [formData, setFormData] = useState<LlmForm>({active_model: stringValue(cfg.active_model),active_provider: stringValue(cfg.active_provider),7 unmodified lines});const [isSubmitting, setIsSubmitting] = useState(false);const [error, setError] = useState<string | undefined>();const [selectedTemplate, setSelectedTemplate] = useState<string>(initialSystemPromptKey);function setField<K extends keyof LlmForm>(key: K,43 unmodified linespayload.temperature = parseFloat(formData.temperature);if (formData.system_prompt) {payload.system_prompts = {[selectedTemplate]: formData.system_prompt,};}1 unmodified lineconst savedProviders = result.providers ?? {};const savedSystemPrompts = result.system_prompts ?? {};const savedKey = savedSystemPrompts[selectedTemplate] !== undefined? selectedTemplate: (Object.keys(savedSystemPrompts)[0] ?? selectedTemplate);setSelectedTemplate(savedKey);const savedProviderInfo = savedProviders[result.active_provider ?? ''];setFormData({78 unmodified lines/></Field><div className="md:col-span-2"><Fieldhint="URL endpoint API provider. Pilih dari daftar atau masukkan custom URL."label="Base URL"><CreatableBaseUrlSelectkey={formData.active_provider}options={baseUrlOptions}value={formData.base_url}onChange={(v) => setField('base_url', v)}/></Field></div><Fieldhint="Tingkat kreativitas jawaban (0–1). Rendah = konsisten, tinggi = lebih variatif."label="Temperature"85 unmodified lines</div><Fieldhint="Pilih key system prompt yang ingin diedit. Setiap key menyimpan instruksi berbeda."label="Template System Prompt"><Selectdisabled={systemPromptKeys.length === 0}value={selectedTemplate}onValueChange={(key) => {setSelectedTemplate(key);setField('system_prompt', systemPromptsMap[key] ?? '');}}><SelectTrigger className="w-full"><SelectValue placeholder="Pilih key..." /></SelectTrigger><SelectContent>{systemPromptKeys.map((key) => (<SelectItem key={key} value={key}>{key}</SelectItem>))}</SelectContent>8 unmodified linesclassName="border-input ring-offset-background placeholder:text-muted-foreground focus-visible:ring-ring min-h-36 w-full rounded-md border px-3 py-2 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2"value={formData.system_prompt}onChange={(event) => {setField('system_prompt', event.target.value);}}/>
resources/js/components/admin/admin-llm-form.tsx+30-46