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

// AI

parent a5ba1bea
......@@ -12,7 +12,7 @@ import IQKeyboardManagerSwift
class YHAIViewController: YHBaseViewController {
var messages:[YHAIResponse] = []
var messages:[YHAIMessage] = []
lazy var tableView: UITableView = {
......@@ -38,7 +38,7 @@ class YHAIViewController: YHBaseViewController {
v.sendBlock = {
[weak self] text in
guard let self = self else { return }
let question = YHAIResponse.createQuestion(text)
let question = YHAIMessage.createQuestion(text)
messages.append(question)
self.scrollToBottom()
......@@ -70,7 +70,7 @@ class YHAIViewController: YHBaseViewController {
}
}
func handleMessage(_ res: YHAIResponse) {
func handleMessage(_ res: YHAIMessage) {
var find = false
for msg in messages {
if msg.uuid == res.uuid {
......
......@@ -12,7 +12,7 @@ class YHAIMessageCell: UITableViewCell {
static let cellReuseIdentifier = "YHAIMessageCell"
var message: YHAIResponse = YHAIResponse() {
var message: YHAIMessage = YHAIMessage() {
didSet {
messageLabel.text = message.body.contentText
......
......@@ -16,11 +16,12 @@ enum YHAIResponseType: Int {
case card = 2
}
class YHAIResponse: CustomStringConvertible {
class YHAIMessage: CustomStringConvertible {
var id: String = ""
var event: String = ""
var data: [String : Any] = [:]
var uuid: String = ""
var isSelf: Bool = false
......@@ -40,8 +41,8 @@ class YHAIResponse: CustomStringConvertible {
event = "conversation.message.completed"
}
static func createQuestion(_ text: String) -> YHAIResponse {
let question = YHAIResponse()
static func createQuestion(_ text: String) -> YHAIMessage {
let question = YHAIMessage()
question.isSelf = true
let body = YHAIResponseBody()
body.contentType = 1
......@@ -94,7 +95,7 @@ class YHAIRequestManager: NSObject {
var uuid = UUID().uuidString + NSDate().timeIntervalSince1970.description
func requestAI(query: String = "", completion:((_ : YHAIResponse) ->())?) {
func requestAI(query: String = "", completion:((_ : YHAIMessage) ->())?) {
var url = "http://192.168.52.250:9898/example?query=" + query
url = url.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)!
......@@ -123,7 +124,7 @@ class YHAIRequestManager: NSObject {
}
// 处理data字符串
func handle(dataString: String, completion:((_ : YHAIResponse) ->())?) {
func handle(dataString: String, completion:((_ : YHAIMessage) ->())?) {
let arr = dataString.components(separatedBy: "\n\n")
if arr.count <= 0 {
......@@ -136,7 +137,7 @@ class YHAIRequestManager: NSObject {
}
let lines = text.components(separatedBy: "\n")
if lines.count > 0 {
let response = YHAIResponse()
let response = YHAIMessage()
response.uuid = uuid
for line in lines {
if line.starts(with: prefix_id) {
......
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