1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- import { Component, OnInit } from '@angular/core';
- import { CommonModule } from '@angular/common';
- import { FormsModule } from '@angular/forms';
- import { IonHeader, IonToolbar, IonTitle, IonContent, IonButton, IonTextarea, IonInput, IonBackButton, IonButtons, IonCardContent, IonCardTitle, IonCardHeader, IonCard, IonCol, IonRow, IonLabel, IonGrid } from '@ionic/angular/standalone';
- import { FmodeChatCompletion, MarkdownPreviewModule } from 'fmode-ng';
- @Component({
- selector: 'app-world-setup',
- templateUrl: './world-setup.page.html',
- styleUrls: ['./world-setup.page.scss'],
- standalone: true,
- imports: [
- CommonModule, // 确保 CommonModule 已经导入
- FormsModule,
- IonHeader, IonToolbar, IonTitle, IonContent, IonButton, IonTextarea, IonInput, IonBackButton, IonButtons,
- IonCardContent, IonCardTitle, IonCardHeader, IonCard, IonCol, IonRow, IonLabel, IonGrid,
- // 引入fm-markdown-preview组件模块
- MarkdownPreviewModule
- ],
- })
- export class WorldSetupPage implements OnInit {
- constructor() { }
- ngOnInit() { }
- novelBackground: string = '在一个神秘的星球上,有许多不同的种族,他们都有着自己独特的文化和历史。';
- responseMsg: string = '';
- backgroundInput(event: any) {
- this.novelBackground = event.target.value;
- }
- // 用户输入提示词
- userPrompt: string = "我希望这个世界有强大的魔法体系,主角从一个普通少年成长为一代宗师。";
- promptInput(ev: any) {
- this.userPrompt = ev.detail.value;
- }
- // 方法:实例化completion对象,传入消息数组,并订阅生成的可观察对象。
- isComplete: boolean = false; // 定义完成状态属性,用来标记是否补全完成
- sendMessage() {
- console.log("create");
- let PromptTemplate = `
- 您作为一名专业的小说作者,请您根据以下信息生成一个详细的世界架构设定:
-
- 小说背景:${this.novelBackground}
- 用户期望:${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;
- }
- });
- }
- // 复制到剪贴板
- copyToClipboard() {
- const textarea = document.createElement('textarea');
- textarea.value = this.responseMsg;
- document.body.appendChild(textarea);
- textarea.select();
- document.execCommand('copy');
- document.body.removeChild(textarea);
- alert('内容已复制到剪贴板');
- }
- }
|