ai-api.service.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { Injectable } from '@angular/core';
  2. import { TestCompletion, generateInterviewEvaluation } from './completion';
  3. @Injectable({
  4. providedIn: 'root'
  5. })
  6. export class AiApiService {
  7. private positionRequirements = `
  8. 岗位要求:
  9. - 3年以上相关工作经验
  10. - 精通至少一种主流编程语言
  11. - 良好的沟通能力和团队协作精神
  12. - 解决问题的能力
  13. `;
  14. constructor() { }
  15. async evaluateInterviewAnswer(
  16. question: string,
  17. answer: string,
  18. onMessage?: (content: string) => void
  19. ) {
  20. try {
  21. const evaluation = await generateInterviewEvaluation(
  22. question,
  23. answer,
  24. this.positionRequirements,
  25. onMessage
  26. );
  27. // 增强相关性检查
  28. if (question.includes("介绍") && evaluation.metrics.relevance < 40) {
  29. evaluation.metrics.relevance = 40; // 自我介绍最低保证40分相关性
  30. }
  31. return {
  32. score: evaluation.score || 0,
  33. feedback: evaluation.feedback || "回答基本符合要求",
  34. followUpQuestion: evaluation.followUpQuestion || "能否详细说明一下?",
  35. metrics: {
  36. expressiveness: evaluation.metrics?.expressiveness || 0,
  37. professionalism: evaluation.metrics?.professionalism || 0,
  38. relevance: evaluation.metrics?.relevance || 0
  39. }
  40. };
  41. } catch (error) {
  42. console.error('评估失败:', error);
  43. return this.getDefaultEvaluation();
  44. }
  45. }
  46. private getDefaultEvaluation() {
  47. return {
  48. score: 70,
  49. feedback: "回答基本符合要求,但缺乏具体细节",
  50. followUpQuestion: "能否详细说明一下?",
  51. metrics: {
  52. expressiveness: 70,
  53. professionalism: 65,
  54. relevance: 60
  55. }
  56. };
  57. }
  58. }