|
@@ -0,0 +1,115 @@
|
|
|
+import { Component, OnInit } from '@angular/core';
|
|
|
+// 引用FmodeChatCompletion类
|
|
|
+import { TestRxjsChatCompletion,TestRxjsChatMessage } from '../../chat/class-rxjs-chat-completion';
|
|
|
+import Parse from "parse";
|
|
|
+import { ActivatedRoute, Router } from '@angular/router';
|
|
|
+@Component({
|
|
|
+ selector: 'app-agent-shige',
|
|
|
+ templateUrl: './agent-shige.page.html',
|
|
|
+ styleUrls: ['./agent-shige.page.scss'],
|
|
|
+})
|
|
|
+export class AgentShigePage implements OnInit {
|
|
|
+ messageList:Array<TestRxjsChatMessage> = []
|
|
|
+ jobTitle:string | undefined |null
|
|
|
+
|
|
|
+ constructor(
|
|
|
+ private route:ActivatedRoute,
|
|
|
+ private router:Router,
|
|
|
+ ) {
|
|
|
+ }
|
|
|
+
|
|
|
+ ngOnInit() {
|
|
|
+ this.loadAndGenJobMarkmind()
|
|
|
+ }
|
|
|
+
|
|
|
+ boleJob:Parse.Object | undefined
|
|
|
+ async loadAndGenJobMarkmind(){
|
|
|
+ let user = Parse.User.current();
|
|
|
+ if(!user?.id) return
|
|
|
+ this.jobTitle = this.route.snapshot.paramMap.get("keyword");
|
|
|
+ if(!this.jobTitle) return
|
|
|
+ let query = new Parse.Query("BoleJob");
|
|
|
+ query.equalTo("user",user?.id);
|
|
|
+ query.equalTo("title",this.jobTitle);
|
|
|
+ this.boleJob = await query.first();
|
|
|
+
|
|
|
+ if(!this.boleJob?.id){
|
|
|
+ // 生成
|
|
|
+ this.sendMessage();
|
|
|
+ }else{
|
|
|
+
|
|
|
+ if(this.boleJob?.get("markmind")){
|
|
|
+ this.router.navigate(["/test","skill-tree",this.boleJob?.id])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sendMessage(){
|
|
|
+ /*
|
|
|
+4. 风格:选择风格,例如“豪放”或“婉约”。
|
|
|
+5. 情感:描述诗中应表达的情感,例如“喜悦”、“忧愁”、“思念”等。
|
|
|
+
|
|
|
+ */
|
|
|
+ let GuhiPromoptTemplate = `
|
|
|
+你是一位资深职业教育者,擅长对职业前景评估,了解职业所需技能,和职业所需技能的具体的学科课程:
|
|
|
+1. 职业:${this.jobTitle}。
|
|
|
+请根据要求给出职业学习建议,并且格式要严格,符合markmind语法
|
|
|
+请开始创作:
|
|
|
+ `
|
|
|
+ this.messageList.push({
|
|
|
+ role:"user",
|
|
|
+ content: GuhiPromoptTemplate
|
|
|
+ })
|
|
|
+
|
|
|
+ // messageList在competion内部,已经赋予了完整的message
|
|
|
+ // 下方暴露出来的可订阅内容,主要是用于关键字过滤,或者其他开发逻辑的续写
|
|
|
+ let resultStr = ""
|
|
|
+ let testChatCompletion = new TestRxjsChatCompletion(this.messageList);
|
|
|
+ testChatCompletion.createCompletionByStream({model:"fmode-3.6-16k"}).subscribe({
|
|
|
+ next: ({ content, cumulativeContent, done }) => {
|
|
|
+ resultStr = cumulativeContent
|
|
|
+ console.log(`Content: ${content}`);
|
|
|
+ console.log(`Cumulative Content: ${cumulativeContent}`);
|
|
|
+ if (done) {
|
|
|
+ console.log('Stream completed');
|
|
|
+ }
|
|
|
+ },
|
|
|
+ error: err => console.error(err),
|
|
|
+ complete: async () => {
|
|
|
+ // 诗歌创建完成:正则表达式,匹配诗歌json内容
|
|
|
+ console.log("结果",resultStr)
|
|
|
+ let BoleJob = Parse.Object.extend("BoleJob");
|
|
|
+ let job = new BoleJob();
|
|
|
+ job.set("title",this.jobTitle);
|
|
|
+ job.set("user",Parse.User.current()?.toPointer());
|
|
|
+ job.set("markmind",resultStr);
|
|
|
+ job = await job.save();
|
|
|
+ if(job?.id){
|
|
|
+ if(job?.get("markmind")){
|
|
|
+ this.router.navigate(["/test","skill-tree",job?.id])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let pattern = /前景:\s*(.*?)\s*内容:\s*(.*?)/;
|
|
|
+ let match = resultStr.match(pattern);
|
|
|
+
|
|
|
+ if (match) {
|
|
|
+ let suggest:any = {}
|
|
|
+ suggest.title = match[1];
|
|
|
+ suggest.content = match[2];
|
|
|
+ suggest.source = "AI创作";
|
|
|
+ console.log(`前景: ${suggest.title}`);
|
|
|
+ console.log(`内容: ${suggest.content}`);
|
|
|
+ console.log(suggest);
|
|
|
+ //let Shige = Parse.Object.extend("Shige");
|
|
|
+ //let sg = new Shige();
|
|
|
+ //sg.set(suggest);
|
|
|
+ //sg.save();
|
|
|
+ } else {
|
|
|
+ console.log("未能匹配到任何内容");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|