tab2.page.ts 866 B

1234567891011121314151617181920212223242526272829
  1. import { Component,OnInit } from '@angular/core';
  2. import { AlertController } from '@ionic/angular';
  3. // 引用FmodeChatCompletion类
  4. import { TestChatCompletion, TestChatMessage } from './class-chat-completion';
  5. @Component({
  6. selector: 'app-tab2',
  7. templateUrl: './tab2.page.html',
  8. styleUrls: ['./tab2.page.scss'],
  9. })
  10. export class Tab2Page implements OnInit {
  11. messages: { sender: string, text: string }[] = [];
  12. newMessage: string = '';
  13. messageList:Array<TestChatMessage> = []
  14. userInput:string = ""
  15. completion:TestChatCompletion
  16. constructor(private alertController: AlertController) {this.completion = new TestChatCompletion(this.messageList)}
  17. ngOnInit() {}
  18. //ai对话
  19. sendMessage(){
  20. this.messageList.push({
  21. role:"user",
  22. content: this.userInput
  23. })
  24. this.userInput = ""
  25. this.completion.createCompletionByStream()
  26. }
  27. }