chat-class.d.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. import { Observable } from "rxjs";
  2. import Parse from "parse";
  3. import { NavController } from "@ionic/angular";
  4. import { FmodeTTS } from "../../voice/tts";
  5. import { NovaCloudService } from "../../../nova-cloud";
  6. import { NovaUploadService } from "../../../storage/service-upload/nova-upload.service";
  7. import { ElementRef } from "@angular/core";
  8. export interface FmodeChatMessageVoice {
  9. id: string;
  10. duration?: number;
  11. ssml?: string;
  12. voiceUrl?: string;
  13. }
  14. export interface FmodeChatEventMap {
  15. onComplete?(FmodeChatMessage: any): void;
  16. onSSMLComplete?(FmodeChatMessageVoice: any): void;
  17. }
  18. export interface FmodeChatVoiceConfig {
  19. voice: string;
  20. autoTalk: boolean;
  21. welcome: {
  22. enabled: true;
  23. };
  24. }
  25. export declare function getMessageContentText(content: any | string | Array<ChatImageContentItem>): string;
  26. export declare function getMessageImageUrl(content: any | string | Array<ChatImageContentItem>): any;
  27. export interface ChatImageContentItem {
  28. type: string;
  29. text?: string;
  30. image_url?: {
  31. url: string;
  32. };
  33. }
  34. export interface FmodeChatMessage {
  35. role: string;
  36. content: string | Array<ChatImageContentItem>;
  37. json?: any;
  38. hidden?: boolean;
  39. createdAt?: Date;
  40. complete?: boolean;
  41. voice?: FmodeChatMessageVoice;
  42. /**AI回复消息字段 */
  43. cid?: string;
  44. }
  45. /**
  46. * FmodeChat 聊天对话类
  47. * @public
  48. */
  49. export declare class FmodeChat {
  50. title: string;
  51. sessionId: string;
  52. ChatSession: any;
  53. chatSession: Parse.Object;
  54. role: any;
  55. messageList: FmodeChatMessage[];
  56. latestAIResponse: string | undefined;
  57. chatServ: any;
  58. userInput: string;
  59. userImage: string;
  60. isDirect: boolean;
  61. /**
  62. * 函数生命周期
  63. */
  64. onChatSaved: (chat: FmodeChat) => void;
  65. onMessage: (chat: FmodeChat, message: FmodeChatMessage) => void;
  66. onUserSend: (chat: FmodeChat, message: FmodeChatMessage) => boolean | Promise<boolean>;
  67. onClose: (chat: FmodeChat) => boolean | Promise<boolean>;
  68. hideShare: boolean;
  69. hideModalSelect: boolean;
  70. hideInputPreview: boolean;
  71. /**
  72. * 虚拟形象展示状态
  73. */
  74. isAvatarShow: boolean;
  75. avatarMode: string;
  76. avatarConfig: any | undefined;
  77. showAvatar(): void;
  78. /**
  79. * 预置提示词弹窗是否展示
  80. */
  81. isPromptModalOpen: boolean;
  82. isPromptMessageAreaShow: boolean;
  83. promptList: any;
  84. /**
  85. * 输入按钮区域
  86. */
  87. focusUserInput: Function;
  88. navCtrl: NavController;
  89. leftButtons: Array<any>;
  90. /**
  91. * 是否开启语音消息模式(单次)
  92. */
  93. isVoiceInputMode: boolean;
  94. isTexting: boolean;
  95. /**
  96. * 是否开启实时对话模式(实时)
  97. * @desc
  98. * 开启ssml system提示词
  99. * 开启回答文本除xml显示模式
  100. */
  101. voiceConfig: FmodeChatVoiceConfig | undefined;
  102. isTalkMode: boolean;
  103. SSMLRoleVoice: string;
  104. /**
  105. * 滚动至消息区域底部方法
  106. * @desc 通过chat-panel等聊天面板,赋值该方法
  107. */
  108. scrollComp: ElementRef;
  109. scrollToBottom(comp?: ElementRef): void;
  110. /**
  111. * 依赖服务
  112. */
  113. ncloud: NovaCloudService;
  114. uploadServ: NovaUploadService;
  115. constructor(sessionId: string, role?: Parse.Object, chatSession?: Parse.Object, chatServ?: any, navCtrl?: NavController, ncloud?: NovaCloudService, uploadServ?: NovaUploadService);
  116. /**
  117. * 会话Avatar控制
  118. */
  119. playAnimation: (animName: string) => void;
  120. welcome: () => Promise<void>;
  121. getTimeOfDay(): "早上" | "中午" | "下午" | "晚上";
  122. self: {
  123. Person?: Parse.Object | undefined;
  124. Profile?: Parse.Object | undefined;
  125. };
  126. loadSelf(className: any, userKey: any): Promise<any>;
  127. /**
  128. * 对话模型提示词
  129. */
  130. loadTalkSystemPrompt(role: Parse.Object): Promise<void>;
  131. /**
  132. * 角色提示词
  133. * @returns
  134. */
  135. loadRolePrompt(): void;
  136. /**
  137. * 发送消息
  138. * @param message
  139. * @param imageUrl
  140. */
  141. sendMessage(message?: string, imageUrl?: string, onComplete?: Function, eventMap?: FmodeChatEventMap, voice?: FmodeChatMessageVoice): Promise<void>;
  142. getVoiceByContentText(content: string | ChatImageContentItem[], eventMap?: FmodeChatEventMap, promptEnabled?: boolean): Promise<FmodeChatMessageVoice>;
  143. getContentText(content: string | ChatImageContentItem[]): string;
  144. /**
  145. * TTS - 语音合成
  146. *
  147. */
  148. initTTS(): Promise<FmodeTTS | null>;
  149. voiceMap: any;
  150. VoiceTTSMap: {
  151. [key: string]: FmodeTTS;
  152. };
  153. stopPlayingVoice(): void;
  154. playChatVoice(voice: Parse.Object, eventMap?: any): Promise<FmodeTTS | null>;
  155. /**
  156. * 保存单次会话
  157. */
  158. saveChatSession(): Promise<void>;
  159. getInviteUrl(url: any): string;
  160. genTitle(): string;
  161. fixMessageList(messages: FmodeChatMessage[]): {
  162. role: string;
  163. content: string | ChatImageContentItem[];
  164. }[];
  165. nowStr(): string;
  166. }
  167. /**
  168. * FmodeChatCompletion 文本补全类
  169. * @public
  170. */
  171. export declare class FmodeChatCompletion {
  172. indexOfList: number;
  173. model: string;
  174. messages: FmodeChatMessage[];
  175. content: string;
  176. contentBuffer: string[];
  177. contentPusher: any;
  178. isCompleted: boolean;
  179. constructor(messages: FmodeChatMessage[], options?: {
  180. model?: string;
  181. });
  182. /**
  183. * @param options
  184. * @param options.isDirect 是否不等待逐字获取,直接完成内容推送
  185. * @param options.intTime 是否不等待逐字获取,直接完成内容推送
  186. * @returns
  187. */
  188. sendCompletion(options?: {
  189. isDirect?: boolean;
  190. intTime?: number;
  191. onComplete?: Function;
  192. }): Observable<FmodeChatMessage>;
  193. }