Browse Source

feat:new consult page with aigc

cainiao-hue 4 months ago
parent
commit
a3a1a5d16e

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


+ 1 - 0
soul-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",
     "tslib": "^2.3.0",

+ 13 - 0
soul-app/src/app/page-consult/page-consult.component.html

@@ -0,0 +1,13 @@
+<ion-content>
+    <h1>类型</h1>
+    <ion-input [value]="leixing" (ionInput)="leixingInput($event)"></ion-input>
+<!-- 文本域:生成提示词 -->
+ <h1>心理状况的描述</h1>
+<ion-textarea [value]="userPrompt" (ionInput)="promptInput($event)" placeholder="文本提示词" autoGrow="true"></ion-textarea>
+
+<!-- 按钮:执行消息生成函数 -->
+<ion-button (click)="sendMessage()" expand="block">初步判断</ion-button>
+  
+<!-- 展示:返回消息内容 -->
+<div>{{responseMsg}}</div>
+</ion-content>

+ 0 - 0
soul-app/src/app/page-consult/page-consult.component.scss


+ 22 - 0
soul-app/src/app/page-consult/page-consult.component.spec.ts

@@ -0,0 +1,22 @@
+import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+
+import { PageConsultComponent } from './page-consult.component';
+
+describe('PageConsultComponent', () => {
+  let component: PageConsultComponent;
+  let fixture: ComponentFixture<PageConsultComponent>;
+
+  beforeEach(waitForAsync(() => {
+    TestBed.configureTestingModule({
+      imports: [PageConsultComponent],
+    }).compileComponents();
+
+    fixture = TestBed.createComponent(PageConsultComponent);
+    component = fixture.componentInstance;
+    fixture.detectChanges();
+  }));
+
+  it('should create', () => {
+    expect(component).toBeTruthy();
+  });
+});

+ 52 - 0
soul-app/src/app/page-consult/page-consult.component.ts

@@ -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-consult',
+  templateUrl: './page-consult.component.html',
+  styleUrls: ['./page-consult.component.scss'],
+  standalone: true,
+  imports: [IonHeader, IonToolbar, IonTitle, IonContent, IonButton,
+    IonTextarea,IonInput
+    ],
+})
+export class PageConsultComponent  implements OnInit {
+  constructor() {}
+  ngOnInit(): void {
+  }
+  // 用户输入提示词
+  leixing:string = "心理问题类型"
+  leixingInput(ev:any){
+    this.leixing = ev.detail.value;
+  }
+  // 用户输入提示词
+   userPrompt:string = "请详细描述你的情况"
+  promptInput(ev:any){
+    this.userPrompt = ev.detail.value;
+  }
+  // 属性:组件内用于展示消息内容的变量
+  responseMsg:any = ""
+  // 方法:实例化completion对象,传入消息数组,并订阅生成的可观察对象。
+  sendMessage(){
+    console.log("create")
+
+    let PromptTemplate = `
+    您作为一名专业的${this.leixing}智能心理咨询师,请您根据用户描述的情况,给出初步的判断,并给出一些详细的建议。'
+    以下是用户的口述:${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
+    })
+  }
+
+}

+ 2 - 2
soul-app/src/app/tab1/tab1.page.html

@@ -23,7 +23,7 @@
             <h2>{{ consultant.name }}</h2>
             <p>{{ consultant.fields.join(', ') }}</p>
           </ion-label>
-          <ion-button slot="end" (click)="bookConsultation(consultant)">预约咨询</ion-button>
+          <ion-button slot="end" (click)="clickToConsult()">点击咨询</ion-button>
         </ion-item>
       </ion-list>
     </ion-card-content>
@@ -56,7 +56,7 @@
       <ion-card-title>用户评价</ion-card-title>
       <ion-buttons slot="end">
         <ion-button (click)="evaluate()" color="primary" fill="solid">
-          <span class="button-text">点击评价</span>
+          <span class="button-text">进入评价</span>
         </ion-button>
       </ion-buttons>
     </ion-toolbar>

+ 8 - 18
soul-app/src/app/tab1/tab1.page.ts

@@ -30,19 +30,9 @@ export class Tab1Page {
   }
   consultants = [
     {
-      name: '李医生',
+      name: '智能心理咨询师',
       avatar: '/assets/img/1.png',
-      fields: ['焦虑', '抑郁']
-    },
-    {
-      name: '张医生',
-      avatar: '/assets/img/1.png',
-      fields: ['人际关系', '情绪管理']
-    },
-    {
-      name: '王医生',
-      avatar: '/assets/img/1.png',
-      fields: ['压力管理', '心理咨询']
+      fields: ['焦虑', '抑郁','压力','...']
     }
   ];
   topics = [
@@ -87,6 +77,11 @@ export class Tab1Page {
     // 其他构造函数代码
   }
   
+  clickToConsult() {
+    // 点击咨询
+    this.router.navigate(['tabs/consult'])
+  }
+  
   viewDetails(topicId: number): void {
     let route: string;
     switch (topicId) {
@@ -106,14 +101,9 @@ export class Tab1Page {
     this.router.navigate([`tabs/${route}`, { id: topicId }]);
   }
 
-  bookConsultation(consultant: any) {
-    // 预约咨询逻辑
-    console.log(`预约咨询: ${consultant.name}`);
-  }
-
   evaluate() {
     // 处理点击评价的逻辑
-    console.log('用户点击了“点击评价”按钮');
+    console.log('用户点击了“进入评价”按钮');
     // 您可以导航到一个新的页面来让用户填写评价,或者显示一个模态框等。
   }
   review: any = { rating: 5 };  // 示例数据

+ 5 - 0
soul-app/src/app/tabs/tabs.routes.ts

@@ -36,6 +36,11 @@ export const routes: Routes = [
         loadComponent: () =>
           import('../topic-detail3/topic-detail3.component').then((m) => m.TopicDetail3Component),
       },
+      {
+        path: 'consult',
+        loadComponent: () =>
+          import('../page-consult/page-consult.component').then((m) => m.PageConsultComponent),
+      },
       {
         path: '',
         redirectTo: '/tabs/tab1',

+ 20 - 0
soul-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:bf1dc433a0b48ca0937e559134e3e316')
+
+//'r:bf1dc433a0b48ca0937e559134e3e316'
 bootstrapApplication(AppComponent, {
   providers: [
     { provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
     provideIonicAngular(),
     provideRouter(routes, withPreloading(PreloadAllModules)),
+
+    // 添加HttpClient供应器
+    provideHttpClient(),
+    // 添加Diagnostic
+    Diagnostic,
   ],
 });

+ 3 - 0
soul-app/tsconfig.json

@@ -2,6 +2,9 @@
 {
   "compileOnSave": false,
   "compilerOptions": {
+
+    "allowSyntheticDefaultImports":true,
+    
     "baseUrl": "./",
     "outDir": "./dist/out-tsc",
     "forceConsistentCasingInFileNames": true,

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