Commit 992e13be authored by Steven杜宇's avatar Steven杜宇

// AI

parent 450f6cf2
...@@ -84,17 +84,37 @@ class YHAIViewModel: NSObject { ...@@ -84,17 +84,37 @@ class YHAIViewModel: NSObject {
printLog("model 是 ==> \(json)") printLog("model 是 ==> \(json)")
if json.code == 200 { if json.code == 200 {
guard let dic = json.data?.peel as? [Any], let arr = [YHAIHistoryMessage].deserialize(from: dic) else { guard let dic = json.data?.peel as? [Any], var arr = [YHAIHistoryMessage].deserialize(from: dic) else {
let err = YHErrorModel(errorCode: YHErrorCode.dictParseError.rawValue, errorMsg: YHErrorCode.dictParseError.description()) let err = YHErrorModel(errorCode: YHErrorCode.dictParseError.rawValue, errorMsg: YHErrorCode.dictParseError.description())
callBackBlock(false, err) callBackBlock(false, err)
return return
} }
self.historyMessages = arr.reversed()
if let lastMsg = arr.last { if let lastMsg = arr.last {
self.lastHistroyMsgId = lastMsg.messageId self.lastHistroyMsgId = lastMsg.messageId
} }
// 删除相邻两个相同的iqueston
var result: [YHAIHistoryMessage] = []
for curMsg in arr {
// 仅在结果数组为空或当前字符串与最后一个不同的情况下,才添加当前字符串
if result.isEmpty {
result.append(curMsg)
} else {
if let lastMsg = result.last {
let isSameQuestionMsg = (lastMsg.type == "question" && curMsg.type == "question" && lastMsg.contentText == curMsg.contentText)
if !isSameQuestionMsg {
result.append(curMsg)
}
}
}
}
self.historyMessages = result.reversed()
callBackBlock(true,nil) callBackBlock(true,nil)
} else { } else {
let err = YHErrorModel(errorCode: Int32(json.code), errorMsg: json.msg.isEmpty ? "" : json.msg) let err = YHErrorModel(errorCode: Int32(json.code), errorMsg: json.msg.isEmpty ? "" : json.msg)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment