Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
galaxy-iOS
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mobile-group
galaxy-iOS
Commits
5772f8c9
Commit
5772f8c9
authored
Dec 03, 2024
by
Steven杜宇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
// AI
parent
2f5db187
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
50 additions
and
10 deletions
+50
-10
YHAIMainChatViewController.swift
...s/AI/AI-Dialogue(AI对话)/C/YHAIMainChatViewController.swift
+33
-1
YHAIRequestManager.swift
...s/Modules/AI/AI-Dialogue(AI对话)/C/YHAIRequestManager.swift
+1
-2
YHAIRobotChatViewController.swift
.../AI/AI-Dialogue(AI对话)/C/YHAIRobotChatViewController.swift
+3
-2
YHAIHistoryMessage.swift
...s/Modules/AI/AI-Dialogue(AI对话)/M/YHAIHistoryMessage.swift
+6
-0
YHAIViewModel.swift
...lasses/Modules/AI/AI-Dialogue(AI对话)/M/YHAIViewModel.swift
+7
-3
YHAITextInputView.swift
...es/Modules/AI/AI-Dialogue(AI对话)/V/YHAITextInputView.swift
+0
-2
No files found.
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/C/YHAIMainChatViewController.swift
View file @
5772f8c9
...
@@ -14,10 +14,13 @@ import JXSegmentedView
...
@@ -14,10 +14,13 @@ import JXSegmentedView
class
YHAIMainChatViewController
:
YHBaseViewController
{
class
YHAIMainChatViewController
:
YHBaseViewController
{
var
robotId
:
String
=
""
var
robotId
:
String
=
""
var
conversationId
:
String
=
""
var
historyLastMessageId
:
String
=
""
var
messages
:[
YHAIChatMessage
]
=
[]
var
messages
:[
YHAIChatMessage
]
=
[]
let
manager
=
YHAIRequestManager
()
let
manager
=
YHAIRequestManager
()
var
conversationId
:
String
=
""
let
viewModel
=
YHAIViewModel
()
lazy
var
tableView
:
UITableView
=
{
lazy
var
tableView
:
UITableView
=
{
...
@@ -34,6 +37,9 @@ class YHAIMainChatViewController: YHBaseViewController {
...
@@ -34,6 +37,9 @@ class YHAIMainChatViewController: YHBaseViewController {
tableView
.
delegate
=
self
tableView
.
delegate
=
self
tableView
.
dataSource
=
self
tableView
.
dataSource
=
self
YHAIChatConfiguration
.
defaultConfig
.
registerMessageGroupCells
(
tableView
)
YHAIChatConfiguration
.
defaultConfig
.
registerMessageGroupCells
(
tableView
)
tableView
.
es
.
addYHPullToRefresh
{
self
.
getHistoryMessages
(
false
)
}
return
tableView
return
tableView
}()
}()
...
@@ -97,6 +103,14 @@ class YHAIMainChatViewController: YHBaseViewController {
...
@@ -97,6 +103,14 @@ class YHAIMainChatViewController: YHBaseViewController {
bottomInputView
.
snp
.
makeConstraints
{
make
in
bottomInputView
.
snp
.
makeConstraints
{
make
in
make
.
left
.
right
.
bottom
.
equalToSuperview
()
make
.
left
.
right
.
bottom
.
equalToSuperview
()
}
}
YHHUD
.
show
(
.
progress
(
message
:
"加载中..."
))
self
.
manager
.
getMainChatConversationId
{
sesseionId
in
YHHUD
.
hide
()
self
.
conversationId
=
sesseionId
self
.
getHistoryMessages
(
false
)
}
}
}
func
scrollToBottom
()
{
func
scrollToBottom
()
{
...
@@ -131,6 +145,24 @@ class YHAIMainChatViewController: YHBaseViewController {
...
@@ -131,6 +145,24 @@ class YHAIMainChatViewController: YHBaseViewController {
}
}
}
}
}
}
func
getHistoryMessages
(
_
isLoading
:
Bool
)
{
if
isLoading
{
YHHUD
.
show
(
.
progress
(
message
:
"加载中..."
))
}
viewModel
.
getHistoryChatMessages
(
botId
:
robotId
,
conversationId
:
conversationId
,
messageId
:
historyLastMessageId
)
{
[
weak
self
]
success
,
error
in
YHHUD
.
hide
()
guard
let
self
=
self
else
{
return
}
self
.
historyLastMessageId
=
self
.
viewModel
.
lastHistroyMsgId
self
.
tableView
.
es
.
stopPullToRefresh
()
let
results
=
self
.
viewModel
.
historyMessages
.
map
{
return
$0
.
convertToChatMessage
()
}
messages
.
append
(
contentsOf
:
results
)
self
.
tableView
.
reloadData
()
}
}
}
}
extension
YHAIMainChatViewController
:
UITableViewDelegate
,
UITableViewDataSource
{
extension
YHAIMainChatViewController
:
UITableViewDelegate
,
UITableViewDataSource
{
...
...
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/C/YHAIRequestManager.swift
View file @
5772f8c9
...
@@ -28,7 +28,6 @@ class YHAIRequestManager: NSObject {
...
@@ -28,7 +28,6 @@ class YHAIRequestManager: NSObject {
var
requestHeader
=
HTTPHeaders
()
var
requestHeader
=
HTTPHeaders
()
requestHeader
.
add
(
name
:
"Accept"
,
value
:
"text/event-stream"
)
requestHeader
.
add
(
name
:
"Accept"
,
value
:
"text/event-stream"
)
requestHeader
.
add
(
name
:
"Connection"
,
value
:
"keep-alive"
)
requestHeader
.
add
(
name
:
"appid"
,
value
:
"1"
)
requestHeader
.
add
(
name
:
"appid"
,
value
:
"1"
)
let
dateStr
=
String
(
Date
()
.
timeIntervalSince1970
)
let
dateStr
=
String
(
Date
()
.
timeIntervalSince1970
)
requestHeader
.
add
(
name
:
"timestamp"
,
value
:
dateStr
)
requestHeader
.
add
(
name
:
"timestamp"
,
value
:
dateStr
)
...
@@ -219,7 +218,7 @@ class YHAIRequestManager: NSObject {
...
@@ -219,7 +218,7 @@ class YHAIRequestManager: NSObject {
if
receiveMessage
.
isFinishd
()
{
if
receiveMessage
.
isFinishd
()
{
// 一段话结束需要重新生成uuid 来
// 一段话结束需要重新生成uuid 来
uuid
=
UUID
()
.
uuidString
+
NSDate
()
.
timeIntervalSince1970
.
description
self
.
uuid
=
UUID
()
.
uuidString
+
NSDate
()
.
timeIntervalSince1970
.
description
}
}
}
}
}
// arr 结束
}
// arr 结束
...
...
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/C/YHAIRobotChatViewController.swift
View file @
5772f8c9
...
@@ -149,11 +149,12 @@ class YHAIRobotChatViewController: YHBaseViewController {
...
@@ -149,11 +149,12 @@ class YHAIRobotChatViewController: YHBaseViewController {
if
isLoading
{
if
isLoading
{
YHHUD
.
show
(
.
progress
(
message
:
"加载中..."
))
YHHUD
.
show
(
.
progress
(
message
:
"加载中..."
))
}
}
viewModel
.
getHistoryChatMessages
(
bo
l
tId
:
robotId
,
conversationId
:
conversationId
,
messageId
:
historyLastMessageId
)
{
viewModel
.
getHistoryChatMessages
(
botId
:
robotId
,
conversationId
:
conversationId
,
messageId
:
historyLastMessageId
)
{
[
weak
self
]
success
,
error
in
[
weak
self
]
success
,
error
in
YHHUD
.
hide
()
YHHUD
.
hide
()
guard
let
self
=
self
else
{
return
}
guard
let
self
=
self
else
{
return
}
messages
.
removeAll
()
self
.
historyLastMessageId
=
self
.
viewModel
.
lastHistroyMsgId
self
.
tableView
.
es
.
stopPullToRefresh
()
let
results
=
self
.
viewModel
.
historyMessages
.
map
{
let
results
=
self
.
viewModel
.
historyMessages
.
map
{
return
$0
.
convertToChatMessage
()
return
$0
.
convertToChatMessage
()
}
}
...
...
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/M/YHAIHistoryMessage.swift
View file @
5772f8c9
...
@@ -19,19 +19,25 @@ class YHAIHistoryMessage: SmartCodable {
...
@@ -19,19 +19,25 @@ class YHAIHistoryMessage: SmartCodable {
var
role
:
String
=
""
var
role
:
String
=
""
var
type
:
String
=
""
var
type
:
String
=
""
var
cardsInfo
:
YHAIListinfoModel
?
required
init
()
{
required
init
()
{
}
}
func
convertToChatMessage
()
->
YHAIChatMessage
{
func
convertToChatMessage
()
->
YHAIChatMessage
{
let
msg
=
YHAIChatMessage
()
let
msg
=
YHAIChatMessage
()
msg
.
uuid
=
self
.
messageId
msg
.
uuid
=
self
.
messageId
msg
.
isSelf
=
self
.
role
==
"user"
msg
.
isDone
=
true
let
body
=
YHAIMessageBody
()
let
body
=
YHAIMessageBody
()
body
.
contentType
=
self
.
contentType
body
.
contentType
=
self
.
contentType
body
.
contentText
=
self
.
contentText
body
.
contentText
=
self
.
contentText
body
.
botId
=
self
.
botId
body
.
botId
=
self
.
botId
body
.
chatId
=
self
.
chatId
body
.
chatId
=
self
.
chatId
body
.
type
=
self
.
type
body
.
type
=
self
.
type
body
.
cardsInfo
=
self
.
cardsInfo
msg
.
body
=
body
msg
.
body
=
body
msg
.
setFinished
()
msg
.
setFinished
()
msg
.
updateBodyToData
()
msg
.
updateBodyToData
()
...
...
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/M/YHAIViewModel.swift
View file @
5772f8c9
...
@@ -15,6 +15,7 @@ class YHAIViewModel: NSObject {
...
@@ -15,6 +15,7 @@ class YHAIViewModel: NSObject {
var
listModel
:
YHAIListModel
=
YHAIListModel
()
var
listModel
:
YHAIListModel
=
YHAIListModel
()
var
sessionId
:
String
=
""
var
sessionId
:
String
=
""
var
historyMessages
:
[
YHAIHistoryMessage
]
=
[]
var
historyMessages
:
[
YHAIHistoryMessage
]
=
[]
var
lastHistroyMsgId
:
String
=
""
func
getAIEntranceList
(
callBackBlock
:
@escaping
(
_
success
:
Bool
,
_
error
:
YHErrorModel
?)
->
())
{
func
getAIEntranceList
(
callBackBlock
:
@escaping
(
_
success
:
Bool
,
_
error
:
YHErrorModel
?)
->
())
{
...
@@ -71,11 +72,11 @@ class YHAIViewModel: NSObject {
...
@@ -71,11 +72,11 @@ class YHAIViewModel: NSObject {
}
}
}
}
func
getHistoryChatMessages
(
bo
l
tId
:
String
,
conversationId
:
String
,
messageId
:
String
,
callBackBlock
:
@escaping
(
_
success
:
Bool
,
_
error
:
YHErrorModel
?)
->
())
{
func
getHistoryChatMessages
(
botId
:
String
,
conversationId
:
String
,
messageId
:
String
,
callBackBlock
:
@escaping
(
_
success
:
Bool
,
_
error
:
YHErrorModel
?)
->
())
{
let
strUrl
=
YHBaseUrlManager
.
shared
.
curURL
()
+
YHAllApiName
.
AIChat
.
chatHistory
let
strUrl
=
YHBaseUrlManager
.
shared
.
curURL
()
+
YHAllApiName
.
AIChat
.
chatHistory
let
params
:[
String
:
Any
]
=
[
let
params
:[
String
:
Any
]
=
[
"bo
ltId"
:
bol
tId
,
"bo
tId"
:
bo
tId
,
"conversationId"
:
conversationId
,
"conversationId"
:
conversationId
,
"messageId"
:
messageId
"messageId"
:
messageId
]
]
...
@@ -92,7 +93,10 @@ class YHAIViewModel: NSObject {
...
@@ -92,7 +93,10 @@ class YHAIViewModel: NSObject {
return
return
}
}
self
.
historyMessages
=
arr
self
.
historyMessages
=
arr
.
reversed
()
if
let
lastMsg
=
arr
.
last
{
self
.
lastHistroyMsgId
=
lastMsg
.
messageId
}
callBackBlock
(
true
,
nil
)
callBackBlock
(
true
,
nil
)
}
else
{
}
else
{
...
...
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/V/YHAITextInputView.swift
View file @
5772f8c9
...
@@ -47,8 +47,6 @@ class YHAITextInputView: UIView {
...
@@ -47,8 +47,6 @@ class YHAITextInputView: UIView {
let
v
=
UIView
()
let
v
=
UIView
()
v
.
backgroundColor
=
.
white
v
.
backgroundColor
=
.
white
v
.
layer
.
cornerRadius
=
12.0
v
.
layer
.
cornerRadius
=
12.0
v
.
layer
.
borderWidth
=
2.0
v
.
layer
.
borderColor
=
UIColor
.
brandMainColor
.
cgColor
v
.
clipsToBounds
=
true
v
.
clipsToBounds
=
true
return
v
return
v
}()
}()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment