12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- import { Injectable } from '@angular/core';
- import { TestCompletion, generateInterviewEvaluation } from './completion';
- @Injectable({
- providedIn: 'root'
- })
- export class AiApiService {
- private positionRequirements = `
- 岗位要求:
- - 3年以上相关工作经验
- - 精通至少一种主流编程语言
- - 良好的沟通能力和团队协作精神
- - 解决问题的能力
- `;
- constructor() { }
- async evaluateInterviewAnswer(
- question: string,
- answer: string,
- onMessage?: (content: string) => void
- ) {
- try {
- const evaluation = await generateInterviewEvaluation(
- question,
- answer,
- this.positionRequirements,
- onMessage
- );
-
- // 增强相关性检查
- if (question.includes("介绍") && evaluation.metrics.relevance < 40) {
- evaluation.metrics.relevance = 40; // 自我介绍最低保证40分相关性
- }
-
- return {
- score: evaluation.score || 0,
- feedback: evaluation.feedback || "回答基本符合要求",
- followUpQuestion: evaluation.followUpQuestion || "能否详细说明一下?",
- metrics: {
- expressiveness: evaluation.metrics?.expressiveness || 0,
- professionalism: evaluation.metrics?.professionalism || 0,
- relevance: evaluation.metrics?.relevance || 0
- }
- };
- } catch (error) {
- console.error('评估失败:', error);
- return this.getDefaultEvaluation();
- }
- }
- private getDefaultEvaluation() {
- return {
- score: 70,
- feedback: "回答基本符合要求,但缺乏具体细节",
- followUpQuestion: "能否详细说明一下?",
- metrics: {
- expressiveness: 70,
- professionalism: 65,
- relevance: 60
- }
- };
- }
- }
|