| 
					
				 | 
			
			
				@@ -1,52 +1,135 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import { Component, OnInit } from '@angular/core'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import { Router } from '@angular/router'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import { IonicModule } from '@ionic/angular'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import { FormsModule } from '@angular/forms'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import { Router } from '@angular/router'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import { FmodeChatCompletion, MarkdownPreviewModule } from 'fmode-ng'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import { CompWordEntryComponent } from '../comp-word-entry/comp-word-entry.component'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 @Component({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   selector: 'app-short-generator', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   templateUrl: './short-generator.page.html', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   styleUrls: ['./short-generator.page.scss'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   standalone: true, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  imports: [IonicModule, FormsModule] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  imports: [ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    IonicModule, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    FormsModule, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    MarkdownPreviewModule, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    CompWordEntryComponent, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  ], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 export class ShortGeneratorPage implements OnInit { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  workTitle: string = ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  selectedStyle: string = ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  characterName: string = ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  characterGender: string = ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  characterDescription: string = ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  characters: Array<{ name: string; gender: string; description: string }> = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  constructor() { } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  constructor(private router: Router) { } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   ngOnInit() { } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  goBack() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // 实现返回逻辑,例如使用路由 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  navigateToContentGenerator() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    this.router.navigate(['/content-generator'], { queryParams: { outline: this.generatedOutline } }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // 用户输入提示词 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  title: string = "时空之旅"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  titleInput(ev: any) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    this.title = ev.detail.value; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  style: string = "玄幻"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  styleInput(ev: any) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    this.style = ev.detail.value; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  onStyleChange() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // 处理风格选择变化 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // 用户输入提示词 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  userPrompt: string = "人物名字:紫霄月;  人物角色:女主角;人物描述:一位来自古老时空的神秘女子。她自幼便拥有穿梭时空的奇异能力,能够自由穿梭于不同的历史与未来之间。这种能力不仅赋予了她非凡的见识与智慧,也让她背负上了沉重的使命——寻找失落的时空碎片,以维护时空的平衡与稳定。"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  promptInput(ev: any) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    this.userPrompt = ev.detail.value; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // 人物词条 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  entryList:Array<any> = [] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  onEntryListChange(ev:any){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    this.entryList = ev 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  showEntryList(){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    console.log(JSON.stringify(this.entryList)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // 生成的小说大纲 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  generatedOutline: string = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // 生成的小说内容 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  generatedContent: string = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // 属性:组件内用于展示消息内容的变量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  responseMsg: any = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // 方法:实例化completion对象,传入消息数组,并订阅生成的可观察对象。 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  isComplete: boolean = false; // 定义完成状态属性,用来标记是否补全完成 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  sendMessage() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    console.log("create"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let PromptTemplate = ` 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    您作为一名专业的${this.style}作者,请您根据用户提供的标题${this.title},给出短篇小说大纲。 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    以下是用户的口述:${this.userPrompt} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    `; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let completion = new FmodeChatCompletion([ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      { role: "system", content: "" }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      { role: "user", content: PromptTemplate } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    completion.sendCompletion().subscribe((message: any) => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      // 打印消息体 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      console.log(message.content); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      // 赋值消息内容给组件内属性 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      this.responseMsg = message.content; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      if (message?.complete) { // 判断message为完成状态,则设置isComplete为完成 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        this.isComplete = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 将生成的小说大纲放入文本框中 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        this.generatedOutline = this.responseMsg; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  addCharacter() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    console.log('人物创建:', { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      name: this.characterName, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      gender: this.characterGender, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      description: this.characterDescription 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  sendOutline() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    console.log("create"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let PromptTemplate = ` 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    根据短篇小说大纲${this.generatedOutline},生成一个短篇小说。 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    `; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let completion = new FmodeChatCompletion([ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      { role: "system", content: "" }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      { role: "user", content: PromptTemplate } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    completion.sendCompletion().subscribe((message: any) => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      // 打印消息体 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      console.log(message.content); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      // 赋值消息内容给组件内属性 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      this.responseMsg = message.content; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      if (message?.complete) { // 判断message为完成状态,则设置isComplete为完成 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        this.isComplete = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 将生成的小说内容放入文本框中 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        this.generatedContent = this.responseMsg; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if (this.characterName && this.characterGender && this.characterDescription) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      this.characters.push({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        name: this.characterName, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        gender: this.characterGender, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        description: this.characterDescription 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // 清空输入框 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    this.characterName = ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    this.characterGender = ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    this.characterDescription = ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  saveNovel() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if (this.generatedContent) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      const novelData = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        title: this.title, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        style: this.style, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        userPrompt: this.userPrompt, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        generatedOutline: this.generatedOutline, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        generatedContent: this.generatedContent 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      // 保存到本地存储 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      localStorage.setItem('novel', JSON.stringify(novelData)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      console.log('小说已保存到本地存储'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      // 可以在这里添加其他保存逻辑,例如发送到服务器 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      console.log('没有生成小说内容,无法保存'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 |