Browse Source

feat:new interest-test

csdn1233 4 months ago
parent
commit
71395a3214

File diff suppressed because it is too large
+ 641 - 14
AIart-app/package-lock.json


+ 1 - 0
AIart-app/package.json

@@ -27,6 +27,7 @@
     "@capacitor/keyboard": "6.0.3",
     "@capacitor/status-bar": "6.0.2",
     "@ionic/angular": "^8.0.0",
+    "fmode-ng": "^0.0.62",
     "ionicons": "^7.2.1",
     "rxjs": "~7.8.0",
     "swiper": "^11.1.15",

+ 22 - 1
AIart-app/src/app/interest-test/interest-test.component.html

@@ -1 +1,22 @@
-<p>nihao</p>
+<ion-content>
+    <!-- 文本域:生成提示词 -->
+    <h1>兴趣方向</h1>
+    <ion-textarea [value]="department" (ionInput)="departmentInput($event)" placeholder="文本提示词"
+        autoGrow="true"></ion-textarea>
+    <h1>具体描述</h1>
+    <ion-textarea [value]="userPrompt" (ionInput)="promptInput($event)" placeholder="文本提示词"
+        autoGrow="true"></ion-textarea>
+
+    <!-- 按钮:执行消息生成函数 -->
+    <ion-button (click)="sendMessage()" expand="block">开始定制学习规划</ion-button>
+
+    <!-- 展示:返回消息内容 -->
+    @if(!isComplete){
+    <div>{{responseMsg}}</div>
+    }
+
+    @if(isComplete){
+    <fm-markdown-preview class="content-style" [content]="responseMsg"></fm-markdown-preview>
+    }
+
+</ion-content>

+ 43 - 3
AIart-app/src/app/interest-test/interest-test.component.ts

@@ -1,15 +1,55 @@
 import { Component, OnInit } from '@angular/core';
+import { IonButton, IonContent, IonHeader, IonInput, IonTitle, IonToolbar } from '@ionic/angular/standalone';
+import { IonTextarea } from '@ionic/angular/standalone';
+import { FmodeChatCompletion, MarkdownPreviewModule } from 'fmode-ng';
 
 @Component({
   selector: 'app-interest-test',
   templateUrl: './interest-test.component.html',
   styleUrls: ['./interest-test.component.scss'],
   standalone: true,
+  imports: [IonHeader, IonToolbar, IonTitle, IonContent, IonButton,
+    IonTextarea, IonInput, MarkdownPreviewModule
+  ],
 })
-export class InterestTestComponent  implements OnInit {
+export class InterestTestComponent implements OnInit {
+  ngOnInit(): void {
 
+  }
   constructor() { }
-
-  ngOnInit() {}
+  // 用户输入提示词
+  department: string = "学习方向"
+  departmentInput(ev: any) {
+    this.department = ev.detail.value;
+  }
+  // 用户输入提示词
+  userPrompt: string = "请具体描述您想要学习/感兴趣的内容"
+  promptInput(ev: any) {
+    this.userPrompt = ev.detail.value;
+  }
+  // 属性:组件内用于展示消息内容的变量
+  responseMsg: any = ""
+  // 方法:实例化completion对象,传入消息数组,并订阅生成的可观察对象。
+  isComplete: boolean = false;
+  sendMessage() {
+    console.log("create")
+    let PromptTemplate = `
+    您作为一名专业的${this.department}兴趣规划师,请根据用户的描述,给出初步的实现方案并给出一些建议,
+    以下是用户的描述${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) (
+        this.isComplete = true
+      )
+    })
+  }
 
 }

+ 20 - 0
AIart-app/src/main.ts

@@ -5,10 +5,30 @@ import { IonicRouteStrategy, provideIonicAngular } from '@ionic/angular/standalo
 import { routes } from './app/app.routes';
 import { AppComponent } from './app/app.component';
 
+// 引用HttpClient方法
+import { provideHttpClient } from '@angular/common/http';
+// 引用移动端授权检测供应器
+import { Diagnostic } from '@awesome-cordova-plugins/diagnostic/ngx';
+// 设置Parse服务属性
+import Parse from "parse";
+Parse.initialize("ncloudmaster");
+Parse.serverURL = "https://server.fmode.cn/parse";
+localStorage.setItem("NOVA_APIG_SERVER", 'aHR0cHMlM0ElMkYlMkZzZXJ2ZXIuZm1vZGUuY24lMkZhcGklMkZhcGlnJTJG')
+
+// 注意:替换Token 根据Token设置Parse服务帐套权限
+Parse.User.become('r:E4KpGvTEto-198800181681732952653')
+
+
+// 'r:E4KpGvTEto-198800181681732952653'
+
 bootstrapApplication(AppComponent, {
   providers: [
     { provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
     provideIonicAngular(),
     provideRouter(routes, withPreloading(PreloadAllModules)),
+    // 添加HttpClient供应器
+    provideHttpClient(),
+    // 添加Diagnostic
+    Diagnostic,
   ],
 });

+ 6 - 2
AIart-app/tsconfig.json

@@ -2,6 +2,7 @@
 {
   "compileOnSave": false,
   "compilerOptions": {
+    "allowSyntheticDefaultImports": true,
     "baseUrl": "./",
     "outDir": "./dist/out-tsc",
     "forceConsistentCasingInFileNames": true,
@@ -18,7 +19,10 @@
     "importHelpers": true,
     "target": "es2022",
     "module": "es2020",
-    "lib": ["es2018", "dom"],
+    "lib": [
+      "es2018",
+      "dom"
+    ],
     "useDefineForClassFields": false
   },
   "angularCompilerOptions": {
@@ -27,4 +31,4 @@
     "strictInputAccessModifiers": true,
     "strictTemplates": true
   }
-}
+}

Some files were not shown because too many files changed in this diff