Commit 3a77a9ff authored by Steven杜宇's avatar Steven杜宇

// AI

parent be2b5d11
......@@ -17,6 +17,7 @@ class YHAIRequestManager: NSObject {
static let subrobotConversationConfigKey = "subrobot_conversation_config_key"
var sessionId: String = ""
var request: DataStreamRequest?
let prefix_id = "id:"
let prefix_event = "event:"
......@@ -73,57 +74,58 @@ class YHAIRequestManager: NSObject {
let headers = self.getCommonHeaders()
// 发送 POST 请求
AF.streamRequest(url,
method: .post,
headers: headers,
automaticallyCancelOnStreamError: false,
requestModifier: { request in
if let httpBodyStream = self.dictionaryToHttpBodyStream(parameters) {
request.httpBodyStream = httpBodyStream
}
}).responseStreamString {
[weak self] stream in
guard let self = self else { return }
request = AF.streamRequest(url,
method: .post,
headers: headers,
automaticallyCancelOnStreamError: false,
requestModifier: { request in
if let httpBodyStream = self.dictionaryToHttpBodyStream(parameters) {
request.httpBodyStream = httpBodyStream
}
}).responseStreamString {
[weak self] stream in
guard let self = self else { return }
switch stream.event {
case let .stream(result):
switch result {
case let .success(string):
print(string)
self.handle(dataString: string) {
response, done in
callback?(response, done)
}
case let .failure(error):
print("\(error)")
// 一段话结束需要重新生成uuid 来
self.uuid = UUID().uuidString + NSDate().timeIntervalSince1970.description
callback?(nil, true)
}
case let .complete(completion):
print("COMPLETE")
// 一段话结束需要重新生成uuid 来
self.uuid = UUID().uuidString + NSDate().timeIntervalSince1970.description
callback?(nil, true)
if let af_error = completion.error {
if let error = af_error.underlyingError {
print("\(error)")
} else {
print("&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
}
} else if let res = completion.response {
print("&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
print("\(res)")
switch stream.event {
case let .stream(result):
switch result {
case let .success(string):
print(string)
self.handle(dataString: string) {
response, done in
callback?(response, done)
}
case let .failure(error):
print("\(error)")
// 一段话结束需要重新生成uuid 来
self.uuid = UUID().uuidString + NSDate().timeIntervalSince1970.description
callback?(nil, true)
}
case let .complete(completion):
print("COMPLETE")
// 一段话结束需要重新生成uuid 来
self.uuid = UUID().uuidString + NSDate().timeIntervalSince1970.description
callback?(nil, true)
if let af_error = completion.error {
if let error = af_error.underlyingError {
print("\(error)")
} else {
print("&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
}
} else if let res = completion.response {
print("&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
print("\(res)")
} else {
print("response done")
}
}
}
} else {
print("response done")
}
}
}
}
func stopChat(chatId: String, conversationId: String, callBackBlock:@escaping (_ success: Bool,_ error:YHErrorModel?)->()) {
......
......@@ -12,6 +12,7 @@ import SDWebImage
class YHAICardItemView: UIView {
var updateBlock:(()->())?
var evaluationResultCallback: ((Dictionary<String, Any>)->())?
var cardModel = YHAIListItemModel() {
didSet {
......@@ -132,6 +133,7 @@ class YHAICardItemView: UIView {
YHAIJumpPageTool.jumpPageWithType(mode: cardModel.redirectMode, path: cardModel.redirectPath) {
dict in
self.evaluationResultCallback?(dict)
}
}
}
......@@ -37,6 +37,7 @@ class YHAIJumpPageTool {
let vc = YHH5WebViewVC()
vc.url = path
vc.evaluationResultCallback = block
UIViewController.current?.navigationController?.pushViewController(vc, animated: true)
}
}
......@@ -73,7 +74,7 @@ class YHCardMessageCell: UITableViewCell {
static let cellReuseIdentifier = "YHCardMessageCell"
var evaluationResultCallback: ((Dictionary<String, Any>)->()) = { dic in }
var evaluationResultCallback: ((Dictionary<String, Any>)->())?
var cardListModel = YHAIListInfoModel() {
didSet {
......@@ -91,6 +92,11 @@ class YHCardMessageCell: UITableViewCell {
guard let self = self else { return }
self.updateBlock?()
}
productView.evaluationResultCallback = {
[weak self] dict in
guard let self = self else { return }
self.evaluationResultCallback?(dict)
}
productView.cardModel = item
listView.addSubview(productView)
productView.snp.makeConstraints { make in
......@@ -172,7 +178,7 @@ class YHCardMessageCell: UITableViewCell {
}
YHAIJumpPageTool.jumpPageWithType(type, mode: cardListModel.redirectMode, path: cardListModel.redirectPath) {
dict in
self.evaluationResultCallback(dict)
self.evaluationResultCallback?(dict)
}
}
......
......@@ -520,6 +520,7 @@ extension YHH5WebViewVC {
printLog("\(dic)")
}
self.evaluationResultCallback?(dic)
self.navigationController?.popViewController(animated: false)
}
//22、禁用全局手势返回
......@@ -534,8 +535,6 @@ extension YHH5WebViewVC {
}
}
//20、导航栏上是否展示title
func hideNavigationTitleSyn(_ tag : String) {
if tag.contains("0") {
......
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