Files
vueapp/api/assessment.ts
T
2026-06-09 17:00:23 +08:00

54 lines
1.2 KiB
TypeScript

import { FASTAPI_BASE_URL, authHeaders, readError, type ApiEnvelope, type ScoreType } from './session'
export type DimensionScore = {
dimension: string
score: number
max_score: number
comment?: string
evidence?: string[]
deductions?: string[]
improvement?: string
}
export type ScoreDetail = {
dimension: string
score: number
deducted_reason?: string
ai_confidence?: number
comment?: string
}
export type EvaluationResult = {
evaluation_id: number
score_type: ScoreType
total_score: number
dimension_scores: DimensionScore[]
score_details: ScoreDetail[]
errors: string[]
improvement_plan: string[]
evidence_summary: string[]
guideline_refs: string[]
overall_comment: string
}
export async function generateEvaluation(sessionId: number, scoreType: ScoreType = 'percentage') {
const response = await fetch(`${FASTAPI_BASE_URL}/sessions/${sessionId}/evaluation`, {
method: 'POST',
headers: authHeaders(),
body: JSON.stringify({
score_type: scoreType
})
})
if (!response.ok) {
throw new Error(await readError(response))
}
const result = (await response.json()) as ApiEnvelope<EvaluationResult>
if (result.code !== 'OK' || !result.data) {
throw new Error(result.message || '评价生成失败')
}
return result.data
}