Commit 565563bd authored by Steven杜宇's avatar Steven杜宇

// AI

parent a54bcece
......@@ -10,7 +10,6 @@ import UIKit
class YHAIChatConfiguration {
static let defaultConfig = YHAIChatConfiguration()
var disableHandleMessage: Bool = false
func registerMessageGroupCells(_ tableView: UITableView) {
......
......@@ -21,6 +21,11 @@ class YHAIMainChatViewController: YHBaseViewController {
let manager = YHAIRequestManager()
let viewModel = YHAIViewModel()
lazy var chatConfig: YHAIChatConfiguration = {
let config = YHAIChatConfiguration()
return config
}()
lazy var tableView: UITableView = {
......@@ -36,7 +41,7 @@ class YHAIMainChatViewController: YHBaseViewController {
tableView.separatorStyle = .none
tableView.delegate = self
tableView.dataSource = self
YHAIChatConfiguration.defaultConfig.registerMessageGroupCells(tableView)
chatConfig.registerMessageGroupCells(tableView)
return tableView
}()
......@@ -53,8 +58,8 @@ class YHAIMainChatViewController: YHBaseViewController {
self.manager.stopChat(chatId: self.manager.chatId, conversationId: self.conversationId) { success, error in
self.bottomInputView.status = self.bottomInputView.textView.text.isEmpty ? .disableSend : .enableSend
if success {
YHAIChatConfiguration.defaultConfig.disableHandleMessage = true
YHAIChatConfiguration.defaultConfig.removeThinkingMessageFromChatList(&self.messages)
self.chatConfig.disableHandleMessage = true
self.chatConfig.removeThinkingMessageFromChatList(&self.messages)
self.bottomInputView.status = self.bottomInputView.textView.text.isEmpty ? .disableSend : .enableSend
self.tableView.reloadData()
}
......@@ -119,17 +124,17 @@ class YHAIMainChatViewController: YHBaseViewController {
self.manager.getMainChatConversationId {
sesseionId in
self.conversationId = sesseionId
YHAIChatConfiguration.defaultConfig.removeThinkingMessageFromChatList(&self.messages)
self.chatConfig.removeThinkingMessageFromChatList(&self.messages)
let question = YHAIChatMessage.createQuestionMessage(text)
self.messages.append(question)
self.messages.append(self.thinkingMessage)
self.scrollToBottom()
self.bottomInputView.status = .loading
YHAIChatConfiguration.defaultConfig.disableHandleMessage = false
self.chatConfig.disableHandleMessage = false
self.manager.requestAI(botId: self.robotId, conversationId: self.conversationId, question:text) {
[weak self] res, done in
guard let self = self else { return }
YHAIChatConfiguration.defaultConfig.handleReceiveMessage(res, done, &messages)
self.chatConfig.handleReceiveMessage(res, done, &messages)
if done {
print("RESPONSE-DONE")
self.bottomInputView.status = self.bottomInputView.textView.text.isEmpty ? .disableSend : .enableSend
......
......@@ -20,6 +20,11 @@ class YHAIRobotChatViewController: YHBaseViewController {
let manager = YHAIRequestManager()
let viewModel = YHAIViewModel()
lazy var chatConfig: YHAIChatConfiguration = {
let config = YHAIChatConfiguration()
return config
}()
lazy var tableView: UITableView = {
let tableView = UITableView(frame:.zero, style:.grouped)
......@@ -34,7 +39,7 @@ class YHAIRobotChatViewController: YHBaseViewController {
tableView.separatorStyle = .none
tableView.delegate = self
tableView.dataSource = self
YHAIChatConfiguration.defaultConfig.registerMessageGroupCells(tableView)
chatConfig.registerMessageGroupCells(tableView)
return tableView
}()
......@@ -56,8 +61,8 @@ class YHAIRobotChatViewController: YHBaseViewController {
self.manager.stopChat(chatId: self.manager.chatId, conversationId: self.conversationId) { success, error in
self.bottomInputView.status = self.bottomInputView.textView.text.isEmpty ? .disableSend : .enableSend
if success {
YHAIChatConfiguration.defaultConfig.disableHandleMessage = true
YHAIChatConfiguration.defaultConfig.removeThinkingMessageFromChatList(&self.messages)
self.chatConfig.disableHandleMessage = true
self.chatConfig.removeThinkingMessageFromChatList(&self.messages)
self.bottomInputView.status = self.bottomInputView.textView.text.isEmpty ? .disableSend : .enableSend
self.tableView.reloadData()
}
......@@ -133,17 +138,17 @@ class YHAIRobotChatViewController: YHBaseViewController {
}
func sendMessage(_ text: String) {
YHAIChatConfiguration.defaultConfig.removeThinkingMessageFromChatList(&messages)
self.chatConfig.removeThinkingMessageFromChatList(&messages)
let question = YHAIChatMessage.createQuestionMessage(text)
messages.append(question)
messages.append(thinkingMessage)
self.scrollToBottom()
self.bottomInputView.status = .loading
YHAIChatConfiguration.defaultConfig.disableHandleMessage = false
self.chatConfig.disableHandleMessage = false
self.manager.requestAI(botId: self.robotId, conversationId: self.conversationId, question:text) {
[weak self] res, done in
guard let self = self else { return }
YHAIChatConfiguration.defaultConfig.handleReceiveMessage(res, done, &messages)
self.chatConfig.handleReceiveMessage(res, done, &messages)
if done {
print("RESPONSE-DONE")
self.bottomInputView.status = self.bottomInputView.textView.text.isEmpty ? .disableSend : .enableSend
......
......@@ -31,6 +31,7 @@ class YHAIServiceListViewController: YHBaseViewController {
collectView.register(YHAIProductCell.self, forCellWithReuseIdentifier: YHAIProductCell.cellReuseIdentifier)
collectView.register(YHAIGreetCollectionReusableView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: YHAIGreetCollectionReusableView.reuseIdentifier)
collectView.contentInset = .zero
collectView.showsVerticalScrollIndicator = false
return collectView
}()
......
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