1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- // ai-continue-modal.component.ts
- import { Component, Input } from '@angular/core';
- import { ModalController } from '@ionic/angular';
- import { IonButton, IonIcon, IonInput, IonItem, IonLabel, IonToolbar, IonHeader, IonContent, IonTitle, IonButtons, IonTextarea } from '@ionic/angular/standalone';
- import { FormsModule } from '@angular/forms';
- import { FmodeChatCompletion, MarkdownPreviewModule } from 'fmode-ng';
- @Component({
- selector: 'app-ai-continue-modal',
- templateUrl: './ai-continue-modal.component.html',
- styleUrls: ['./ai-continue-modal.component.scss'],
- standalone: true,
- imports: [
- IonButton, IonIcon, IonInput, IonItem, IonTitle, FormsModule,
- IonLabel, IonToolbar, IonHeader, IonContent, IonButtons, MarkdownPreviewModule, IonTextarea
- ]
- })
- export class AiContinueModalComponent {
- inputText: string = '';
- continuedText: string = '';
- userPrompt: string = "";
- responseMsg: any = "";
- isComplete: boolean = false;
- @Input() onInsertText?: (text: string) => void;
- constructor(private modalCtrl: ModalController) { }
- dismiss() {
- this.modalCtrl.dismiss();
- }
- promptInput(ev: any) {
- this.userPrompt = ev.detail.value;
- }
- sendMessage() {
- console.log("create");
- let PromptTemplate = `
- 您是一名专业的文字作者,请您根据用户提供的文本继续创作。
- 以下是用户的原文:${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;
- this.continuedText = message.content; // 将生成的内容赋值给 continuedText
- if (message?.complete) { // 判断message为完成状态,则设置isComplete为完成
- this.isComplete = true;
- }
- });
- }
- copyContinuedText() {
- navigator.clipboard.writeText(this.continuedText).then(() => {
- alert('文本已复制到剪贴板');
- }, (err) => {
- console.error('未能复制文本:', err);
- });
- }
- insertIntoChapterEnd() {
- // 检查是否有选择的章节
- if (this.continuedText && this.onInsertText) {
- this.onInsertText(this.continuedText);
- this.dismiss();
- } else {
- alert('请先生成续写内容');
- }
- }
- regenerate() {
- // 清空输入框和结果区域
- this.userPrompt = '';
- this.responseMsg = '';
- this.continuedText = '';
- this.isComplete = false;
- // 重新发送请求
- this.sendMessage();
- }
- }
|