|
@@ -1,52 +1,76 @@
|
|
import { Component, OnInit } from '@angular/core';
|
|
import { Component, OnInit } from '@angular/core';
|
|
-import { Router } from '@angular/router';
|
|
|
|
import { IonicModule } from '@ionic/angular';
|
|
import { IonicModule } from '@ionic/angular';
|
|
import { FormsModule } from '@angular/forms';
|
|
import { FormsModule } from '@angular/forms';
|
|
|
|
+import { Router } from '@angular/router';
|
|
|
|
+import { FmodeChatCompletion, MarkdownPreviewModule } from 'fmode-ng';
|
|
|
|
|
|
@Component({
|
|
@Component({
|
|
selector: 'app-short-generator',
|
|
selector: 'app-short-generator',
|
|
templateUrl: './short-generator.page.html',
|
|
templateUrl: './short-generator.page.html',
|
|
styleUrls: ['./short-generator.page.scss'],
|
|
styleUrls: ['./short-generator.page.scss'],
|
|
standalone: true,
|
|
standalone: true,
|
|
- imports: [IonicModule, FormsModule]
|
|
|
|
|
|
+ imports: [
|
|
|
|
+ IonicModule,
|
|
|
|
+ FormsModule,
|
|
|
|
+ MarkdownPreviewModule
|
|
|
|
+ ],
|
|
})
|
|
})
|
|
export class ShortGeneratorPage implements OnInit {
|
|
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() { }
|
|
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; // 修正这里应该是修改style而不是title
|
|
}
|
|
}
|
|
|
|
|
|
- onStyleChange() {
|
|
|
|
- // 处理风格选择变化
|
|
|
|
|
|
+ // 用户输入提示词
|
|
|
|
+ userPrompt: string = "人物名字:林浅夏; 人物角色:女主角;人物描述:林浅夏是一名来自中国的少女,她的爱好是画画,她的梦想是成为一名优秀的画家。";
|
|
|
|
+ promptInput(ev: any) {
|
|
|
|
+ this.userPrompt = ev.detail.value;
|
|
}
|
|
}
|
|
|
|
|
|
- addCharacter() {
|
|
|
|
- console.log('人物创建:', {
|
|
|
|
- name: this.characterName,
|
|
|
|
- gender: this.characterGender,
|
|
|
|
- description: this.characterDescription
|
|
|
|
|
|
+ // 生成的小说大纲
|
|
|
|
+ generatedOutline: 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;
|
|
|
|
+ }
|
|
});
|
|
});
|
|
- 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 = '';
|
|
|
|
- }
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
|
+ }
|
|
|
|
+}
|