|
@@ -1,4 +1,4 @@
|
|
|
-import { Component, OnInit } from '@angular/core';
|
|
|
|
|
|
|
+import { Component} from '@angular/core';
|
|
|
import { Router } from '@angular/router';
|
|
import { Router } from '@angular/router';
|
|
|
import { CommonModule } from '@angular/common';
|
|
import { CommonModule } from '@angular/common';
|
|
|
import { IonHeader, IonToolbar, IonTitle, IonContent, ModalController, IonButton,
|
|
import { IonHeader, IonToolbar, IonTitle, IonContent, ModalController, IonButton,
|
|
@@ -13,12 +13,6 @@ import { ChatPanelOptions, FmChatModalInput, FmodeChat, FmodeChatMessage, openCh
|
|
|
import { CloudObject, CloudQuery, CloudUser } from 'src/lib/ncloud';
|
|
import { CloudObject, CloudQuery, CloudUser } from 'src/lib/ncloud';
|
|
|
import { openUserLoginModal } from 'src/lib/user/modal-user-login/modal-user-login.component';
|
|
import { openUserLoginModal } from 'src/lib/user/modal-user-login/modal-user-login.component';
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-import { IonSegment,IonSegmentButton,IonTextarea } from "@ionic/angular/standalone";
|
|
|
|
|
-import { AgentStory, EmbedQuery, RetriveAllDocument } from 'src/lib/story';
|
|
|
|
|
-import { CloudApi } from 'src/lib/ncloud';
|
|
|
|
|
-import { FmodeChatCompletion,MarkdownPreviewModule } from 'fmode-ng';
|
|
|
|
|
-
|
|
|
|
|
@Component({
|
|
@Component({
|
|
|
selector: 'app-tab3',
|
|
selector: 'app-tab3',
|
|
|
templateUrl: 'tab3.page.html',
|
|
templateUrl: 'tab3.page.html',
|
|
@@ -32,15 +26,9 @@ import { FmodeChatCompletion,MarkdownPreviewModule } from 'fmode-ng';
|
|
|
// ModalAudioMessageComponent
|
|
// ModalAudioMessageComponent
|
|
|
CommonModule, IonCard, IonCardHeader, IonCardTitle, IonCardContent,
|
|
CommonModule, IonCard, IonCardHeader, IonCardTitle, IonCardContent,
|
|
|
IonList, IonItem, IonLabel, IonAvatar, IonInput, IonIcon, IonThumbnail,
|
|
IonList, IonItem, IonLabel, IonAvatar, IonInput, IonIcon, IonThumbnail,
|
|
|
- IonSegment, IonSegmentButton, IonTextarea, MarkdownPreviewModule
|
|
|
|
|
]
|
|
]
|
|
|
})
|
|
})
|
|
|
-export class Tab3Page implements OnInit{
|
|
|
|
|
-
|
|
|
|
|
- tab:string = "vector"
|
|
|
|
|
- tabChange(ev:any){
|
|
|
|
|
- this.tab = ev.detail.value
|
|
|
|
|
- }
|
|
|
|
|
|
|
+export class Tab3Page{
|
|
|
|
|
|
|
|
constructor(
|
|
constructor(
|
|
|
private modalCtrl:ModalController,
|
|
private modalCtrl:ModalController,
|
|
@@ -49,7 +37,6 @@ export class Tab3Page implements OnInit{
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
/** 示例:搭子聊天面板 */
|
|
/** 示例:搭子聊天面板 */
|
|
|
async opendazi(filmpartner:CloudObject){
|
|
async opendazi(filmpartner:CloudObject){
|
|
|
//验证用户登录
|
|
//验证用户登录
|
|
@@ -209,168 +196,10 @@ export class Tab3Page implements OnInit{
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-// openChat(){
|
|
|
|
|
-// let options:ChatPanelOptions = {
|
|
|
|
|
-// roleId:"2DXJkRsjXK",
|
|
|
|
|
-// onChatSaved:(chat:FmodeChat)=>{
|
|
|
|
|
-// // chat?.chatSession?.id 本次会话的 chatId
|
|
|
|
|
-
|
|
|
|
|
-// console.log("onChatSaved",chat,chat?.chatSession,chat?.chatSession?.id)
|
|
|
|
|
-
|
|
|
|
|
-// },
|
|
|
|
|
-
|
|
|
|
|
-// }
|
|
|
|
|
-// openChatPanelModal(this.modalCtrl,options)
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// restoreChat(chatId:string){
|
|
|
|
|
-// let options:ChatPanelOptions = {
|
|
|
|
|
-// roleId:"2DXJkRsjXK",
|
|
|
|
|
-// chatId:chatId
|
|
|
|
|
-// }
|
|
|
|
|
-// openChatPanelModal(this.modalCtrl,options)
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// goChat(){
|
|
|
|
|
-// this.router.navigateByUrl("/chat/session/role/2DXJkRsjXK")
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- // audioModalHeightPoint:number = 0.35;
|
|
|
|
|
- // async startTalk(){
|
|
|
|
|
- // // 根据手机兼容性,适配组件弹出高度
|
|
|
|
|
- // let height = document.body.clientHeight || 960;
|
|
|
|
|
- // this.audioModalHeightPoint = Number((165/height).toFixed(2));
|
|
|
|
|
-
|
|
|
|
|
- // // 弹出组件
|
|
|
|
|
- // let modal:any
|
|
|
|
|
- // let chat:any
|
|
|
|
|
- // modal = await this.modalCtrl.create({
|
|
|
|
|
- // component:ModalAudioMessageComponent,
|
|
|
|
|
- // componentProps:{
|
|
|
|
|
- // chat:chat,
|
|
|
|
|
- // modal:modal,
|
|
|
|
|
- // onBreakPointSet:()=>{
|
|
|
|
|
- // modal?.setCurrentBreakpoint(this.audioModalHeightPoint)
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- // })
|
|
|
|
|
- // modal.present();
|
|
|
|
|
- // }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 文档加载、分割、向量存储
|
|
|
|
|
- */
|
|
|
|
|
- fileList:Array<any> = [
|
|
|
|
|
- {
|
|
|
|
|
- title:`市委办公厅 市政府办公厅印发《关于服务保障“抓防控促发展”落实“人才生态37条”的补充意见》的通知`,
|
|
|
|
|
- tags:["杭州","人才政策"],
|
|
|
|
|
- url:`https://app.fmode.cn/dev/jxnu/case/2020%E5%B9%B4%E6%9D%AD%E5%B7%9E%E5%B8%82%E4%BA%BA%E6%89%8D37%E6%9D%A1.docx`
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- title:"杭州市余杭区服务保障高层次人才创新创业政策实施细则",
|
|
|
|
|
- tags:["杭州","余杭","人才政策","创新创业","双创"],
|
|
|
|
|
- url:"https://app.fmode.cn/dev/jxnu/case/2022年杭州余杭.docx"
|
|
|
|
|
- }
|
|
|
|
|
- ]
|
|
|
|
|
- storyMap:any = {}
|
|
|
|
|
- preview(file:any){
|
|
|
|
|
- window.open(file.url,"_blank")
|
|
|
|
|
- }
|
|
|
|
|
- async loader(file:any){
|
|
|
|
|
- let story = new AgentStory(file);
|
|
|
|
|
- await story.loader(file.url);
|
|
|
|
|
- console.log(story);
|
|
|
|
|
- this.storyMap[file?.url] = story;
|
|
|
|
|
- }
|
|
|
|
|
- async splitter(story:AgentStory){
|
|
|
|
|
- await story.splitter();
|
|
|
|
|
- }
|
|
|
|
|
- async embedings(story:AgentStory){
|
|
|
|
|
- await story.embedings()
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 文本向量检索
|
|
|
|
|
- */
|
|
|
|
|
- userInput:string = "";
|
|
|
|
|
- searchDocList:Array<any> = []
|
|
|
|
|
- inputChange(ev:any){
|
|
|
|
|
- this.userInput = ev.detail.value
|
|
|
|
|
- }
|
|
|
|
|
- async retriveFrontEnd(){
|
|
|
|
|
- let storyList = Object.values(this.storyMap);
|
|
|
|
|
- let docList:any = []
|
|
|
|
|
- storyList.forEach((story:any)=>{
|
|
|
|
|
- docList = docList.concat(story.docList)
|
|
|
|
|
- })
|
|
|
|
|
- let vector512 = await EmbedQuery(this.userInput)
|
|
|
|
|
- console.log(this.userInput,vector512)
|
|
|
|
|
- console.log(docList)
|
|
|
|
|
- this.searchDocList = RetriveAllDocument(vector512,docList)
|
|
|
|
|
- console.log("searchDocList",this.searchDocList)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- async retriveBackEnd(){
|
|
|
|
|
- let vector512 = await EmbedQuery(this.userInput)
|
|
|
|
|
- console.log(this.userInput,vector512)
|
|
|
|
|
-
|
|
|
|
|
- let api = new CloudApi()
|
|
|
|
|
- let result = await api.fetch("agent/retrive",{
|
|
|
|
|
- vector512:vector512
|
|
|
|
|
- })
|
|
|
|
|
- console.log(result)
|
|
|
|
|
- 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;
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
ngOnInit() {
|
|
ngOnInit() {
|
|
|
// 生命周期:页面加载后,运行搭子和角色列表,加载函数
|
|
// 生命周期:页面加载后,运行搭子和角色列表,加载函数
|
|
|
this.loadFilmPartnerList()
|
|
this.loadFilmPartnerList()
|
|
|
this.loadFilmRoleList()
|
|
this.loadFilmRoleList()
|
|
|
- this.loader(this.fileList[0]);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 创建用于数据列表存储的属性
|
|
// 创建用于数据列表存储的属性
|