Commit c7bbad05 authored by Steven杜宇's avatar Steven杜宇

// AI

parent 065bee76
......@@ -22,7 +22,9 @@ class YHAIRequestManager: NSObject {
let prefix_data = "data:"
let viewModel = YHAIViewModel()
// 每次回答的唯一标识符
var uuid = UUID().uuidString + NSDate().timeIntervalSince1970.description
var chatId = UUID().uuidString + NSDate().timeIntervalSince1970.description
func getCommonHeaders() -> HTTPHeaders {
......@@ -68,10 +70,6 @@ class YHAIRequestManager: NSObject {
"conversationId" : conversationId,
"question" : question] as! [String: Any]
// parameters = ["botId": "7441190609433755702",
// "conversationId": sesseionId,
// "question": question] as! [String: String]
let headers = self.getCommonHeaders()
// 发送 POST 请求
......@@ -93,21 +91,21 @@ class YHAIRequestManager: NSObject {
case let .success(string):
print(string)
self.handle(dataString: string) {
res in
completion?(res, false)
response, done in
completion?(response, done)
}
case let .failure(error):
print("\(error)")
}
case let .complete(completion):
print("COMPLETE")
if let af_error = completion.error {
if let error = af_error.underlyingError {
print("\(error)")
} else {
print("&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
// completion?(nil, true)
}
} else if let res = completion.response {
......@@ -136,7 +134,7 @@ class YHAIRequestManager: NSObject {
}
// 处理data字符串
func handle(dataString: String, completion:((_ : YHAIMessage) ->())?) {
func handle(dataString: String, completion:((_ : YHAIMessage, _ done: Bool) ->())?) {
let arr = dataString.components(separatedBy: "\n\n")
if arr.count <= 0 {
......@@ -183,15 +181,24 @@ class YHAIRequestManager: NSObject {
}
}
}
if receiveMessage.body.isStart() {
chatId = receiveMessage.body.chatId
}
}
if receiveMessage.isFinishd() {
// 一段话结束需要重新生成uuid 来
uuid = UUID().uuidString + NSDate().timeIntervalSince1970.description
}
print("msgType: \(receiveMessage.getType()), compltete:\(receiveMessage.isFinishd()), uuid:\(receiveMessage.uuid), \(receiveMessage.body.contentText)")
completion?(receiveMessage)
let sessionDone = receiveMessage.body.isDone()
if !receiveMessage.body.isStart() {
completion?(receiveMessage, sessionDone)
}
}
}
} // arr 结束
}
}
......
......@@ -55,6 +55,7 @@ class YHAIMessage: CustomStringConvertible {
body.contentText = text
question.setFinished()
question.body = body
question.uuid = UUID().uuidString + NSDate().timeIntervalSince1970.description
question.updateBodyToData()
return question
}
......@@ -66,6 +67,7 @@ class YHAIMessage: CustomStringConvertible {
body.contentType = YHAIMessageType.thinking.rawValue
message.setFinished()
message.body = body
message.uuid = UUID().uuidString + NSDate().timeIntervalSince1970.description
message.updateBodyToData()
return message
}
......@@ -117,6 +119,21 @@ class YHAIMessageBody: SmartCodable {
var botId: String = ""
var status: String = ""
var type: String = ""
var chatId: String = ""
func isStart() -> Bool {
if status == "start" {
return true
}
return false
}
func isDone() -> Bool {
if status == "done" {
return true
}
return false
}
var productListModel: YHProductListModel = YHProductListModel()
......
......@@ -79,6 +79,11 @@ class YHAIMessageCell: UITableViewCell {
lable.numberOfLines = 0
return lable
}()
lazy var shadowView: YHAIChatShadowView = {
let v = YHAIChatShadowView()
return v
}()
required init?(coder: NSCoder) {
super.init(coder: coder)
......@@ -94,10 +99,15 @@ class YHAIMessageCell: UITableViewCell {
selectionStyle = .none
contentView.backgroundColor = .clear
backgroundColor = .clear
contentView.addSubview(shadowView)
contentView.addSubview(rightAngleView)
contentView.addSubview(whiteContentView)
whiteContentView.addSubview(messageLabel)
shadowView.snp.makeConstraints { make in
make.edges.equalTo(whiteContentView)
}
rightAngleView.snp.makeConstraints { make in
make.top.right.equalTo(whiteContentView)
make.width.height.equalTo(15)
......
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Frame@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Frame@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
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