| 
					
				 | 
			
			
				@@ -2,8 +2,9 @@ import { Component, OnInit } from '@angular/core'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import { CommonModule } from '@angular/common'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import { IonContent,IonButton,IonSegment,IonSegmentButton,IonLabel,IonList,IonItem,IonTextarea } from "@ionic/angular/standalone"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import { AgentStory, EmbedQuery, RetriveAllDocument } from '../story-loader/story.loader'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import { AgentStory, EmbedQuery, RetriveAllDocument } from '../../../lib/story'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import { CloudApi } from 'src/lib/ncloud'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import { FmodeChatCompletion,MarkdownPreviewModule } from 'fmode-ng'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 @Component({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   selector: 'app-page-hangzhou', 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -15,6 +16,7 @@ import { CloudApi } from 'src/lib/ncloud'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       IonContent,IonButton, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       IonSegment,IonSegmentButton,IonLabel, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       IonList,IonItem,IonTextarea, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      MarkdownPreviewModule 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     ] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 export class PageHangzhouComponent  implements OnInit { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -93,4 +95,41 @@ export class PageHangzhouComponent  implements OnInit { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     this.searchDocList = result?.data || result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   * 知识库问答 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  messageInput:string = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  messageResult:any; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  isComplete:boolean = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  messageChange(ev:any){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    this.messageInput = ev.detail.value 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  async sendMessage(){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // 通过RAG检索相关文本块 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let vector512 = await EmbedQuery(this.userInput) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let api = new CloudApi() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let result = await api.fetch("agent/retrive",{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      vector512:vector512 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    this.searchDocList = result?.data || result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let top10Doc = this.searchDocList.slice(0,10); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let docInsertion = `# 知识库文档\n${top10Doc.map(item=>item.pageContent).join("\n")}` 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let PromptTemplate = ` 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ${docInsertion} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    您是一名专业的人力资源顾问,帮助应届大学生解答当地政策问题,从政策及知识库文档中中寻找学生所需,并给予建议。 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    以下是学生的问题:${this.messageInput} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   ` 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let completion = new FmodeChatCompletion([ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      {role:"system",content:""}, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      {role:"user",content:PromptTemplate} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      ]) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      completion.sendCompletion().subscribe((message:any)=>{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          this.messageResult = message 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          if(message?.complete){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            this.isComplete = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |