Merge branch 'main' of 47.107.44.202:xionglijia/18xchat
This commit is contained in:
@@ -4,34 +4,92 @@
|
||||
import { BaseData } from "./BaseData";
|
||||
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
||||
|
||||
export class AiCharacterData extends BaseData {
|
||||
// api键
|
||||
private _apiKey: string = "";
|
||||
// 数据结构
|
||||
export interface AiCharacters {
|
||||
id: number;
|
||||
basePrompt: string;
|
||||
additionPrompt: string;
|
||||
}
|
||||
|
||||
export class AiCharacterData extends BaseData {
|
||||
// 数据 map
|
||||
private _dataMap: Map<number, AiCharacters>;
|
||||
// 数据 id
|
||||
private _ids: number[];
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this._dataMap = new Map<number, AiCharacters>(),
|
||||
this._ids = [];
|
||||
}
|
||||
|
||||
public reset(): void {
|
||||
this._apiKey = "";
|
||||
this._dataMap.clear();
|
||||
this._ids = [];
|
||||
}
|
||||
|
||||
public clear(): void {
|
||||
this._apiKey = "";
|
||||
this._dataMap.clear();
|
||||
this._ids = [];
|
||||
}
|
||||
|
||||
public destroy(): void {
|
||||
super.destroy();
|
||||
this._apiKey = null;
|
||||
this._dataMap = null;
|
||||
this._ids = null;
|
||||
}
|
||||
|
||||
// 解析数据,一个
|
||||
private parseOneAiCharacters(data: any): AiCharacters | null {
|
||||
if (!data) return null;
|
||||
const oneData: AiCharacters = {
|
||||
id: data.id, // 角色id
|
||||
basePrompt: data.basePrompt, // 个人信息基础prompt(聊天&评分都需要)
|
||||
additionPrompt: data.additionPrompt, // 额外信息prompt(聊天需要)
|
||||
};
|
||||
return oneData;
|
||||
}
|
||||
|
||||
// 解析数据,多个
|
||||
private parseAllAiCharacters(data: any): AiCharacters[] {
|
||||
if (!data) return [];
|
||||
let allData = [];
|
||||
for (const value of data) {
|
||||
const oneData: AiCharacters = this.parseOneAiCharacters(value);
|
||||
if (oneData) {
|
||||
allData.push(oneData);
|
||||
}
|
||||
}
|
||||
return allData;
|
||||
}
|
||||
|
||||
/** 设置Ai角色配置*/
|
||||
public set aiCharacter(data: proto.cs.ICSGetResConfigRes) {
|
||||
const parsed = JSON.parse(data.data);
|
||||
console.log("请求Ai角色配置的解析数据:", parsed);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/** 获取api键 */
|
||||
public getApiKey(): string {
|
||||
return this._apiKey;
|
||||
/** 获取所有 id */
|
||||
public getAllIds(): number[] {
|
||||
return this._ids;
|
||||
}
|
||||
|
||||
/** 获取数据,根据 id */
|
||||
private getAiCharactersById(id: number): AiCharacters | null {
|
||||
return this._dataMap.get(id) ?? null;
|
||||
}
|
||||
|
||||
/** 获取个人信息基础prompt,根据 id*/
|
||||
public getBasePromptById(id: number): string {
|
||||
const oneData = this.getAiCharactersById(id);
|
||||
return oneData ? oneData.basePrompt : "";
|
||||
}
|
||||
|
||||
/** 获取额外信息prompt,根据 id*/
|
||||
public getAdditionPromptById(id: number): string {
|
||||
const oneData = this.getAiCharactersById(id);
|
||||
return oneData ? oneData.additionPrompt : "";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user