Spaces:
Sleeping
Sleeping
change: admin page llm config base url follows provider
Browse files18 unmodified lines192021222324252627282930313233343536222324189 unmodified lines2142152162322332172182197 unmodified lines22722822924723023123223343 unmodified lines2772782792972802812822831 unmodified line28528628730530630728828929029129229329429578 unmodified lines37437537637737837938038138238338438538638738838939039139239385 unmodified lines4794804814834844854864874884894904914924934944824834844854864874995005015025035045054884894904914924935094944954965125135144974984995005015028 unmodified lines51151251352951451551618 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 lines const 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>(''); const [selectedTemplate, setSelectedTemplate] = useState<string>(initialSystemPromptKey);
function setField<K extends keyof LlmForm>( key: K,43 unmodified lines payload.temperature = parseFloat(formData.temperature); if (formData.system_prompt) { payload.system_prompts = { [systemPromptKeyRef.current]: formData.system_prompt, [selectedTemplate]: formData.system_prompt, }; }
1 unmodified line
const savedProviders = result.providers ?? {}; const savedSystemPrompts = result.system_prompts ?? {}; const savedKeys = Object.keys(savedSystemPrompts); const savedKey = savedKeys[0] ?? systemPromptKeyRef.current; systemPromptKeyRef.current = savedKey; 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"> <Field hint="URL endpoint API provider. Pilih dari daftar atau masukkan custom URL." label="Base URL" > <CreatableBaseUrlSelect key={formData.active_provider} options={baseUrlOptions} value={formData.base_url} onChange={(v) => setField('base_url', v)} /> </Field> </div>
<Field hint="Tingkat kreativitas jawaban (0–1). Rendah = konsisten, tinggi = lebih variatif." label="Temperature"85 unmodified lines </div>
<Field hint="URL endpoint API provider. Pilih dari daftar atau masukkan custom URL." label="Base URL" > <CreatableBaseUrlSelect options={baseUrlOptions} value={formData.base_url} onChange={(v) => setField('base_url', v)} /> </Field>
<Field hint="Pilih template untuk mengisi sistem prompt secara otomatis." hint="Pilih key system prompt yang ingin diedit. Setiap key menyimpan instruksi berbeda." label="Template System Prompt" > <Select disabled={systemPromptKeys.length === 0} value={selectedTemplate} onValueChange={(label) => { setSelectedTemplate(label); const template = SYSTEM_PROMPT_TEMPLATES.find( (t) => t.label === label, ); if (template) setField('system_prompt', template.value); onValueChange={(key) => { setSelectedTemplate(key); setField('system_prompt', systemPromptsMap[key] ?? ''); }} > <SelectTrigger className="w-full"> <SelectValue placeholder="Pilih template..." /> <SelectValue placeholder="Pilih key..." /> </SelectTrigger> <SelectContent> {SYSTEM_PROMPT_TEMPLATES.map((t) => ( <SelectItem key={t.label} value={t.label}> {t.label} {systemPromptKeys.map((key) => ( <SelectItem key={key} value={key}> {key} </SelectItem> ))} </SelectContent>8 unmodified lines className="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); }} />resources/js/components/admin/admin-llm-form.tsx+30-46