1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- import { Injectable } from '@angular/core';
- import { TestCompletion, generateInterviewEvaluation } from './completion';
- export interface TestMessage {
- role: string;
- content: string;
- }
- @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
- );
-
- // 确保返回标准化的评估结果
- 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
- }
- };
- }
- async generateFollowUpQuestion(
- conversationHistory: TestMessage[],
- onMessage?: (content: string) => void
- ): Promise<string> {
- const prompt = `根据以下对话历史,生成一个有针对性的追问问题:
- ${conversationHistory.map(msg => `${msg.role}: ${msg.content}`).join('\n')}
- 要求:
- - 问题应针对候选人的回答深入挖掘
- - 问题应简洁明了
- - 只返回问题内容,不要包含其他说明`;
- const messages: TestMessage[] = [
- { role: "user", content: prompt }
- ];
- const completion = new TestCompletion(messages);
- const result = await completion.sendMessage(messages, onMessage);
- return result || "能否详细说明一下?";
- }
- }
|