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

// AI

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