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

// AI

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