Spaces:
Running
Running
Commit ·
9f5a59f
1
Parent(s): 17601ad
support reset evaluation prompt
Browse files
src/app/admin/prompts/evaluation/[id]/page.tsx
CHANGED
|
@@ -20,6 +20,7 @@ export default function EditEvaluationPromptPage() {
|
|
| 20 |
const [name, setName] = useState('');
|
| 21 |
const [description, setDescription] = useState('');
|
| 22 |
const [systemPrompt, setSystemPrompt] = useState('');
|
|
|
|
| 23 |
|
| 24 |
// Load prompt data
|
| 25 |
useEffect(() => {
|
|
@@ -82,6 +83,33 @@ export default function EditEvaluationPromptPage() {
|
|
| 82 |
}
|
| 83 |
};
|
| 84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
if (loading) {
|
| 86 |
return (
|
| 87 |
<div className="min-h-screen bg-gray-50 p-4 md:p-8">
|
|
@@ -237,6 +265,11 @@ export default function EditEvaluationPromptPage() {
|
|
| 237 |
>
|
| 238 |
評估系統提示詞 <span className="text-red-500">*</span>
|
| 239 |
</label>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
<textarea
|
| 241 |
id="systemPrompt"
|
| 242 |
value={systemPrompt}
|
|
@@ -259,9 +292,18 @@ export default function EditEvaluationPromptPage() {
|
|
| 259 |
取消
|
| 260 |
</Link>
|
| 261 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
<button
|
| 263 |
type="submit"
|
| 264 |
-
disabled={saving}
|
| 265 |
className="flex-1 sm:flex-none px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:bg-gray-400 disabled:cursor-not-allowed transition-colors"
|
| 266 |
>
|
| 267 |
{saving ? '儲存中...' : '儲存變更'}
|
|
|
|
| 20 |
const [name, setName] = useState('');
|
| 21 |
const [description, setDescription] = useState('');
|
| 22 |
const [systemPrompt, setSystemPrompt] = useState('');
|
| 23 |
+
const [resetting, setResetting] = useState(false);
|
| 24 |
|
| 25 |
// Load prompt data
|
| 26 |
useEffect(() => {
|
|
|
|
| 83 |
}
|
| 84 |
};
|
| 85 |
|
| 86 |
+
const handleReset = async () => {
|
| 87 |
+
if (!confirm('確定要重設為預設值嗎?這將覆蓋目前的所有變更。')) {
|
| 88 |
+
return;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
setResetting(true);
|
| 92 |
+
setError(null);
|
| 93 |
+
|
| 94 |
+
try {
|
| 95 |
+
const response = await adminFetch(`/api/admin/evaluation-prompts/${promptId}/default`);
|
| 96 |
+
|
| 97 |
+
if (!response.ok) {
|
| 98 |
+
const data = await response.json();
|
| 99 |
+
throw new Error(data.error || '無法取得預設值');
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
const defaultPrompt = await response.json();
|
| 103 |
+
setName(defaultPrompt.name);
|
| 104 |
+
setDescription(defaultPrompt.description || '');
|
| 105 |
+
setSystemPrompt(defaultPrompt.systemPrompt);
|
| 106 |
+
} catch (err) {
|
| 107 |
+
setError(err instanceof Error ? err.message : '重設失敗');
|
| 108 |
+
} finally {
|
| 109 |
+
setResetting(false);
|
| 110 |
+
}
|
| 111 |
+
};
|
| 112 |
+
|
| 113 |
if (loading) {
|
| 114 |
return (
|
| 115 |
<div className="min-h-screen bg-gray-50 p-4 md:p-8">
|
|
|
|
| 265 |
>
|
| 266 |
評估系統提示詞 <span className="text-red-500">*</span>
|
| 267 |
</label>
|
| 268 |
+
<div className="mb-3 bg-amber-50 border border-amber-200 rounded-lg p-3">
|
| 269 |
+
<p className="text-sm text-amber-800">
|
| 270 |
+
<span className="font-semibold">⚠️ 重要:</span>提示詞必須要求 AI 回傳有效的 JSON 格式。如果回應格式不正確,系統將無法解析評估結果。
|
| 271 |
+
</p>
|
| 272 |
+
</div>
|
| 273 |
<textarea
|
| 274 |
id="systemPrompt"
|
| 275 |
value={systemPrompt}
|
|
|
|
| 292 |
取消
|
| 293 |
</Link>
|
| 294 |
|
| 295 |
+
<button
|
| 296 |
+
type="button"
|
| 297 |
+
onClick={handleReset}
|
| 298 |
+
disabled={resetting || saving}
|
| 299 |
+
className="flex-1 sm:flex-none px-6 py-2 text-center border border-orange-300 text-orange-700 rounded-lg hover:bg-orange-50 disabled:bg-gray-100 disabled:text-gray-400 disabled:border-gray-200 disabled:cursor-not-allowed transition-colors"
|
| 300 |
+
>
|
| 301 |
+
{resetting ? '重設中...' : '重設為預設'}
|
| 302 |
+
</button>
|
| 303 |
+
|
| 304 |
<button
|
| 305 |
type="submit"
|
| 306 |
+
disabled={saving || resetting}
|
| 307 |
className="flex-1 sm:flex-none px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:bg-gray-400 disabled:cursor-not-allowed transition-colors"
|
| 308 |
>
|
| 309 |
{saving ? '儲存中...' : '儲存變更'}
|
src/app/api/admin/evaluation-prompts/[id]/default/route.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { NextResponse } from 'next/server';
|
| 2 |
+
import { withAdminAuthParams } from '@/lib/auth';
|
| 3 |
+
import { getEvaluationPromptConfigFallback } from '@/lib/prompts/evaluation-prompts';
|
| 4 |
+
|
| 5 |
+
/**
|
| 6 |
+
* GET /api/admin/evaluation-prompts/:id/default
|
| 7 |
+
* Get the default evaluation prompt from TypeScript files (fallback)
|
| 8 |
+
* Requires admin authentication
|
| 9 |
+
*/
|
| 10 |
+
export const GET = withAdminAuthParams<{ id: string }>(
|
| 11 |
+
async (_request, _auth, { params }) => {
|
| 12 |
+
const { id } = await params;
|
| 13 |
+
|
| 14 |
+
const defaultPrompt = getEvaluationPromptConfigFallback(id);
|
| 15 |
+
|
| 16 |
+
if (!defaultPrompt) {
|
| 17 |
+
return NextResponse.json(
|
| 18 |
+
{ error: `No default evaluation prompt found for: ${id}` },
|
| 19 |
+
{ status: 404 }
|
| 20 |
+
);
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
return NextResponse.json({
|
| 24 |
+
id: defaultPrompt.id,
|
| 25 |
+
name: defaultPrompt.name,
|
| 26 |
+
description: defaultPrompt.description,
|
| 27 |
+
systemPrompt: defaultPrompt.systemPrompt,
|
| 28 |
+
});
|
| 29 |
+
}
|
| 30 |
+
);
|