Public Access
feat: add AI grading test endpoint and update connection logic
This commit is contained in:
1 parent
993265318b
commit
201d21a678
4 files changed
+52
-16
No files matched your search
@@ -96,14 +96,16 @@ export function sendTestEmail(to: string | undefined, smtp: SmtpConfig): Promise
|
||||
})
|
||||
}
|
||||
|
||||
export function testAiConnection(): Promise<GradingResult> {
|
||||
return apiFetch('/api/grade', {
|
||||
export interface AiTestPayload {
|
||||
provider: string
|
||||
apiKey: string
|
||||
model: string
|
||||
baseURL?: string
|
||||
}
|
||||
|
||||
export function testAiConnection(payload: AiTestPayload): Promise<GradingResult> {
|
||||
return apiFetch('/api/admin/test-ai', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
type: 'short-answer',
|
||||
question: { prompt: 'What is 2+2?', answer: '4' },
|
||||
answer: '4',
|
||||
language: 'en',
|
||||
}),
|
||||
body: JSON.stringify(payload),
|
||||
})
|
||||
}
|
||||
@@ -135,7 +135,12 @@ export default function AdminDashboard({ onExit }: Readonly<Props>) {
|
||||
setTestAiSending(true);
|
||||
setTestAiMsg(null);
|
||||
try {
|
||||
await adminApi.testAiConnection();
|
||||
await adminApi.testAiConnection({
|
||||
provider: settingsDraft.ai_provider,
|
||||
apiKey: settingsDraft.ai_api_key,
|
||||
model: settingsDraft.ai_model || 'gpt-4o-mini',
|
||||
baseURL: settingsDraft.ai_base_url || undefined,
|
||||
});
|
||||
setTestAiMsg({ ok: true, text: t("admin.aiGrading.testSuccess") });
|
||||
} catch (e) {
|
||||
setTestAiMsg({ ok: false, text: (e as Error).message });
|
||||
|
||||
Reference in new issue
Block a user