协议调试:聊天
This commit is contained in:
@@ -80,11 +80,23 @@ export class ChatAIService {
|
||||
* 创建或获取指定角色的聊天实例
|
||||
* @param roleId 角色ID
|
||||
*/
|
||||
private createOrGetChat(roleId: number): any {
|
||||
async createOrGetChat(roleId: number): Promise<any> {
|
||||
if (!this.chatInstances.has(roleId)) {
|
||||
const systemInstruction = RoleConfigLoader.getRoleInstruction(roleId);
|
||||
const config = ApiConfig.Instance.getAIConfig();
|
||||
|
||||
// // 获取聊天数据
|
||||
// await this.reqGetChatMsg(roleId, 1, 20);
|
||||
// const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
||||
// const category = girlData.getGrilCategoryById(roleId);
|
||||
// const ids = girlData.getChatRecordIds(category.toString(), roleId);
|
||||
// for (let id of ids) {
|
||||
// let isAi = girlData.getChatRecordIsAi(category.toString(), roleId, id);
|
||||
// let mgs = girlData.getChatRecordMsg(category.toString(), roleId, id);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// 从本地加载历史记录
|
||||
const savedHistory = ChatHistoryManager.Instance.loadHistory(roleId);
|
||||
let chat;
|
||||
@@ -311,7 +323,7 @@ export class ChatAIService {
|
||||
* 上报聊天数据到服务器
|
||||
*/
|
||||
async reqChatMsg(girlId: number, msgList: proto.cs.IChatMsg[]) {
|
||||
// 请求购买商品
|
||||
// 请求数据
|
||||
const reqData = {
|
||||
girlId,
|
||||
ChatMsg: msgList,
|
||||
@@ -329,6 +341,30 @@ export class ChatAIService {
|
||||
girlData.setChatRemainCount(category.toString(), girlId, resData.chatRemainCount);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取聊天数据
|
||||
*/
|
||||
async reqGetChatMsg(girlId: number, page: number, limit: number) {
|
||||
// 请求数据
|
||||
const reqData = {
|
||||
GirlId: girlId,
|
||||
page,
|
||||
limit,
|
||||
};
|
||||
console.log("获取聊天数据的请求数据:", reqData);
|
||||
let res = await ChatService.I.reqGetChatMsg(reqData);
|
||||
console.log("获取聊天数据的响应数据:", res);
|
||||
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
|
||||
const resData = res.data;
|
||||
// 保存数据
|
||||
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
||||
const category = girlData.getGrilCategoryById(girlId);
|
||||
girlData.setChatRecord(category.toString(), girlId, resData.msgs);
|
||||
girlData.setChatTotalCount(category.toString(), girlId, resData.chatTotalCount);
|
||||
girlData.setChatRemainCount(category.toString(), girlId, resData.chatRemainCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 请求数据类型定义
|
||||
|
||||
Reference in New Issue
Block a user