Browse Source

'update:实现广场基本页面和模拟面试的逻辑'

abstract001 1 year ago
parent
commit
5b30829301

+ 7 - 3
app-angular/src/modules/home/mock-interviews/mock-interviews.component.html

@@ -54,6 +54,7 @@
         <div class="input-container">
         <textarea [nzSize]="'large'" nz-input [(ngModel)]="inputText" placeholder="请输入消息"
                   (keydown)="handleKeyDown($event)"></textarea>
+          <button nz-button nzType="primary" (click)="scrollToBottom()" [disabled]="createReport">滚动</button>
           <button nz-button nzType="primary" (click)="handleButton()" [disabled]="createReport">发送</button>
           <nz-modal [(nzVisible)]="isVisible" nzTitle="The first Modal" (nzOnCancel)="handleCancel()"
                     (nzOnOk)="handleOk()">
@@ -68,12 +69,15 @@
   </nz-tab>
   <nz-tab [nzTitle]="'阿里面试官'">
     <!-- 选择页面的内容 -->
-    <ng-container *ngTemplateOutlet="contentTemplate"></ng-container>
+    <div #chatContainer>
+      <ng-container *ngTemplateOutlet="contentTemplate"></ng-container>
+    </div>
   </nz-tab>
   <nz-tab [nzTitle]="'华为面试官'">
     <!-- 选择页面的内容 -->
-    <ng-container *ngTemplateOutlet="contentTemplate"></ng-container>
-
+    <div #chatContainer>
+      <ng-container *ngTemplateOutlet="contentTemplate"></ng-container>
+    </div>
   </nz-tab>
 </nz-tabset>
 

+ 60 - 9
app-angular/src/modules/home/mock-interviews/mock-interviews.component.ts

@@ -31,7 +31,7 @@ export class MockInterviewsComponent {
   }
 
   completion: TestChatCompletion
-  @ViewChild('chatWindow', {static: false}) chatWindow!: ElementRef;
+
 
   nzOptions: NzCascaderOption[];
   options = [
@@ -155,7 +155,7 @@ export class MockInterviewsComponent {
   }
 
   handleShiftEnter() {
-    this.inputText += '?';
+    this.inputText += '\n';
   }
 
   async handleEnter() {
@@ -175,19 +175,21 @@ export class MockInterviewsComponent {
   isStart: number = 0
   typeQuestion: number = 0;
 
+  @ViewChild('chatWindow') chatWindowRef!: ElementRef;
+  @ViewChild('chatContainer') chatContainerRef!: ElementRef;
 
   // 滚动到底部
   scrollToBottom() {
-    const chatWindow = this.chatWindow.nativeElement;
+    console.log(1)
+    const chatWindow = this.chatWindowRef.nativeElement;
     chatWindow.scrollTop = chatWindow.scrollHeight;
+    const chatContainer = this.chatContainerRef.nativeElement;
+    const chatWindowOther = chatContainer.querySelector('.chat-window');
+    chatWindowOther.scrollTop = chatWindowOther.scrollHeight;
   }
 
   createReport: boolean = false
 
-  // 在视图检查后滚动到底部
-  ngAfterViewChecked() {
-    this.scrollToBottom();
-  }
 
   async handleButton() {
     try {
@@ -233,12 +235,22 @@ export class MockInterviewsComponent {
     if (this.typeQuestion == 9) {
       this.typeQuestion = 0
       this.createReport = true
+      this.messagesListUser.push({
+        role: "user",
+        content: this.inputText += '回答完毕',
+      });
+      await this.scrollToBottom()
       this.messagesListUser.push(
         {
           role: 'user',
           content: "感谢您的回答,请稍等,正在生成报告.....",
         }
       )
+      await this.scrollToBottom()
+      setTimeout(async () => {
+        await this.createAiReport()
+      }, 1000)
+
 
     } else {
       if (this.isStart == 0) {
@@ -250,6 +262,8 @@ export class MockInterviewsComponent {
             role: "assistant",
             content: "请等待,对话生成中....."
           });
+        await this.scrollToBottom()
+
 
         await this.getQuestion();
 
@@ -260,6 +274,8 @@ export class MockInterviewsComponent {
           role: "assistant",
           content: this.finalResult[this.typeQuestion].question
         });
+        await this.scrollToBottom()
+
 
         this.isStart++;
         this.typeQuestion++;
@@ -273,6 +289,7 @@ export class MockInterviewsComponent {
             role: "user",
             content: this.inputText += '回答完毕',
           });
+          await this.scrollToBottom()
           this.resultAnswers.push(this.inputText);
 
           this.messagesListUser.push(
@@ -281,11 +298,12 @@ export class MockInterviewsComponent {
               content: this.finalResult[this.typeQuestion].question
             }
           );
-          this.typeQuestion
           console.log(this.resultAnswers);
           this.inputText = "";
           // 将滚动条滚动到底部
-          this.scrollToBottom();
+          await this.scrollToBottom()
+
+          this.typeQuestion++;
         } else {
           this.showModal()
           return
@@ -297,6 +315,39 @@ export class MockInterviewsComponent {
     }
   }
 
+  allAnswerStr: String = '';
+
+  async createAiReport() {
+    return new Promise(async (resolve, reject) => {
+      //所有回答字符串
+      for (let str of this.resultAnswers) {
+        this.allAnswerStr += str + '\n';
+      }
+      console.log(this.allAnswerStr);
+      this.messagesList.push(
+        {
+          role: "user",
+          content: "下列是我对您提出的问题的回答," +
+            this.allAnswerStr + '\n' +
+            "请帮我针对每个回答进行评分,然后支出每条回答里面存在的问题和可以改进的地方,请十分详细的给出,并且严格按照下面的格式" +
+            "提出的问题......" +
+            "我的回答........" +
+            "我的回答存在的问题" +
+            "我的回答可以改进的地方" + '\n',
+        });
+      await this.completion.createCompletionByStream();
+      console.log(this.messagesList[this.messagesList.length - 1]);
+      this.messagesListUser.splice(this.messagesListUser.length - 1, 1);
+      this.messagesListUser.push(
+        {
+          role: 'assistant',
+          content: this.messagesList[this.messagesList.length - 1].content,
+        }
+      );
+      await this.scrollToBottom()
+      resolve(undefined);
+    });
+  }
 
   async getQuestion() {
     return new Promise(async (resolve, reject) => {

+ 1 - 1
app-angular/src/modules/home/nav-menu/nav-menu.component.html

@@ -43,7 +43,7 @@
       <li nz-submenu nzOpen nzTitle="实操测试" nzIcon="tag">
         <ul>
           <li nz-menu-item nzMatchRouter>
-            <a [routerLink]="['/home/minterviews/1']" [queryParams]="{ tabIndex: 1 }">模拟面试_文字</a>
+            <a [routerLink]="['/home/minterviews/0']" [queryParams]="{ tabIndex: 0 }">模拟面试_文字</a>
           </li>
           <!--          <li nz-menu-item nzMatchRouter>-->
           <!--            <a routerLink="">模拟面试_语音</a>-->