|
@@ -0,0 +1,52 @@
|
|
|
+import { Component, OnInit } from '@angular/core';
|
|
|
+import { IonHeader, IonToolbar, IonTitle, IonContent,IonButton,IonTextarea,IonInput } from '@ionic/angular/standalone';
|
|
|
+/** 引用:从fmode-ng库引用FmodeChatCompletion类 */
|
|
|
+import { FmodeChatCompletion } from 'fmode-ng';
|
|
|
+
|
|
|
+@Component({
|
|
|
+ selector: 'app-page-create',
|
|
|
+ templateUrl: './page-create.component.html',
|
|
|
+ styleUrls: ['./page-create.component.scss'],
|
|
|
+ standalone: true,
|
|
|
+ imports: [IonHeader, IonToolbar, IonTitle, IonContent, IonButton,
|
|
|
+ IonTextarea,IonInput
|
|
|
+ ],
|
|
|
+})
|
|
|
+export class PageCreateComponent implements OnInit {
|
|
|
+ ngOnInit(){
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ constructor() {}
|
|
|
+ // 用户输入提示词
|
|
|
+ style:string = "诗句格式"
|
|
|
+ styleInput(ev:any){
|
|
|
+ this.style = ev.detail.value;
|
|
|
+ }
|
|
|
+ userPrompt:string = "请描述你的诗歌需求"
|
|
|
+ promptInput(ev:any){
|
|
|
+ this.userPrompt = ev.detail.value;
|
|
|
+ }
|
|
|
+ // 属性:组件内用于展示消息内容的变量
|
|
|
+ responseMsg:any = ""
|
|
|
+ // 方法:实例化completion对象,传入消息数组,并订阅生成的可观察对象。
|
|
|
+ sendMessage(){
|
|
|
+ console.log("create")
|
|
|
+
|
|
|
+ let PromptTemplate = `
|
|
|
+ 您作为一位专业的$(this.style)诗歌创作者,请您根据用户提出的感官体验、情感表达和诗歌的结构,给出要求的诗歌格式的诗歌内容创作,
|
|
|
+ 以下是用户的需求$(this.userPrompt)
|
|
|
+ `
|
|
|
+
|
|
|
+ let completion = new FmodeChatCompletion([
|
|
|
+ {role:"system",content:""},
|
|
|
+ {role:"user",content:this.userPrompt}
|
|
|
+ ])
|
|
|
+ completion.sendCompletion().subscribe((message:any)=>{
|
|
|
+ // 打印消息体
|
|
|
+ console.log(message.content)
|
|
|
+ // 赋值消息内容给组件内属性
|
|
|
+ this.responseMsg = message.content
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|