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
661245a8
Commit
661245a8
authored
Dec 02, 2024
by
Steven杜宇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
// AI
parent
125dde55
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
97 additions
and
46 deletions
+97
-46
YHAIChatConfiguration.swift
...odules/AI/AI-Dialogue(AI对话)/C/YHAIChatConfiguration.swift
+11
-1
YHAIMainChatViewController.swift
...s/AI/AI-Dialogue(AI对话)/C/YHAIMainChatViewController.swift
+30
-21
YHAIRobotChatViewController.swift
.../AI/AI-Dialogue(AI对话)/C/YHAIRobotChatViewController.swift
+25
-17
YHAIMessageModel.swift
...ses/Modules/AI/AI-Dialogue(AI对话)/M/YHAIMessageModel.swift
+19
-6
YHAITextMessageCell.swift
.../Modules/AI/AI-Dialogue(AI对话)/V/YHAITextMessageCell.swift
+12
-1
No files found.
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/C/YHAIChatConfiguration.swift
View file @
661245a8
...
@@ -13,6 +13,9 @@ class YHAIChatConfiguration {
...
@@ -13,6 +13,9 @@ class YHAIChatConfiguration {
static
let
defaultConfig
=
YHAIChatConfiguration
()
static
let
defaultConfig
=
YHAIChatConfiguration
()
var
disableHandleMessage
:
Bool
=
false
var
disableHandleMessage
:
Bool
=
false
var
recommentMsgClick
:((
String
)
->
())?
func
registerMessageGroupCells
(
_
tableView
:
UITableView
)
{
func
registerMessageGroupCells
(
_
tableView
:
UITableView
)
{
tableView
.
register
(
UITableViewCell
.
self
,
forCellReuseIdentifier
:
"UITableViewCell"
)
tableView
.
register
(
UITableViewCell
.
self
,
forCellReuseIdentifier
:
"UITableViewCell"
)
...
@@ -30,6 +33,11 @@ class YHAIChatConfiguration {
...
@@ -30,6 +33,11 @@ class YHAIChatConfiguration {
if
msg
.
isTextMessage
()
{
if
msg
.
isTextMessage
()
{
let
cell
=
tableView
.
dequeueReusableCell
(
withIdentifier
:
YHAITextMessageCell
.
cellReuseIdentifier
,
for
:
indexPath
)
as!
YHAITextMessageCell
let
cell
=
tableView
.
dequeueReusableCell
(
withIdentifier
:
YHAITextMessageCell
.
cellReuseIdentifier
,
for
:
indexPath
)
as!
YHAITextMessageCell
cell
.
message
=
msg
cell
.
message
=
msg
cell
.
messageClick
=
{
[
weak
self
]
text
in
guard
let
self
=
self
else
{
return
}
self
.
recommentMsgClick
?(
text
)
}
return
cell
return
cell
}
else
if
msgType
==
.
thinking
{
}
else
if
msgType
==
.
thinking
{
...
@@ -55,7 +63,10 @@ class YHAIChatConfiguration {
...
@@ -55,7 +63,10 @@ class YHAIChatConfiguration {
return
cell
return
cell
}
else
{
}
else
{
print
(
"无法识别该消息,请升级APP版本"
)
print
(
"contentType:
\(
msg
.
getType
()
)
"
)
let
cell
=
tableView
.
dequeueReusableCell
(
withIdentifier
:
YHAITextMessageCell
.
cellReuseIdentifier
,
for
:
indexPath
)
as!
YHAITextMessageCell
let
cell
=
tableView
.
dequeueReusableCell
(
withIdentifier
:
YHAITextMessageCell
.
cellReuseIdentifier
,
for
:
indexPath
)
as!
YHAITextMessageCell
msg
.
body
.
contentType
=
YHMessageType
.
none
.
rawValue
msg
.
body
.
contentText
=
"无法识别该消息,请升级APP版本"
msg
.
body
.
contentText
=
"无法识别该消息,请升级APP版本"
cell
.
message
=
msg
cell
.
message
=
msg
return
cell
return
cell
...
@@ -80,7 +91,6 @@ class YHAIChatConfiguration {
...
@@ -80,7 +91,6 @@ class YHAIChatConfiguration {
var
find
=
false
var
find
=
false
for
msg
in
messages
{
for
msg
in
messages
{
if
msg
.
uuid
==
res
.
uuid
{
if
msg
.
uuid
==
res
.
uuid
{
let
msgType
=
msg
.
getType
()
if
msg
.
isNeedSpiceMessage
(),
res
.
isNeedSpiceMessage
()
{
if
msg
.
isNeedSpiceMessage
(),
res
.
isNeedSpiceMessage
()
{
// 多个文字需要拼接
// 多个文字需要拼接
find
=
true
find
=
true
...
...
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/C/YHAIMainChatViewController.swift
View file @
661245a8
...
@@ -42,26 +42,7 @@ class YHAIMainChatViewController: YHBaseViewController {
...
@@ -42,26 +42,7 @@ class YHAIMainChatViewController: YHBaseViewController {
v
.
sendBlock
=
{
v
.
sendBlock
=
{
[
weak
self
]
text
in
[
weak
self
]
text
in
guard
let
self
=
self
else
{
return
}
guard
let
self
=
self
else
{
return
}
self
.
manager
.
getMainChatConversationId
{
self
.
sendMessage
(
text
)
sesseionId
in
self
.
conversationId
=
sesseionId
YHAIChatConfiguration
.
defaultConfig
.
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
.
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
)
if
done
{
self
.
bottomInputView
.
status
=
self
.
bottomInputView
.
textView
.
text
.
isEmpty
?
.
disableSend
:
.
enableSend
}
self
.
scrollToBottom
()
}
}
}
}
v
.
stopSendBlock
=
{
v
.
stopSendBlock
=
{
[
weak
self
]
in
[
weak
self
]
in
...
@@ -95,12 +76,17 @@ class YHAIMainChatViewController: YHBaseViewController {
...
@@ -95,12 +76,17 @@ class YHAIMainChatViewController: YHBaseViewController {
gk_navTitle
=
"AI对话"
gk_navTitle
=
"AI对话"
self
.
view
.
addSubview
(
self
.
tableView
)
self
.
view
.
addSubview
(
self
.
tableView
)
self
.
view
.
addSubview
(
self
.
bottomInputView
)
self
.
view
.
addSubview
(
self
.
bottomInputView
)
YHAIChatConfiguration
.
defaultConfig
.
recommentMsgClick
=
{
[
weak
self
]
text
in
guard
let
self
=
self
else
{
return
}
self
.
sendMessage
(
text
)
}
tableView
.
snp
.
makeConstraints
{
make
in
tableView
.
snp
.
makeConstraints
{
make
in
make
.
left
.
right
.
equalTo
(
0
)
make
.
left
.
right
.
equalTo
(
0
)
make
.
top
.
equalTo
(
0
)
make
.
top
.
equalTo
(
0
)
make
.
bottom
.
equalTo
(
bottomInputView
.
snp
.
top
)
.
offset
(
-
10
)
make
.
bottom
.
equalTo
(
bottomInputView
.
snp
.
top
)
.
offset
(
-
10
)
}
}
bottomInputView
.
snp
.
makeConstraints
{
make
in
bottomInputView
.
snp
.
makeConstraints
{
make
in
make
.
left
.
right
.
bottom
.
equalToSuperview
()
make
.
left
.
right
.
bottom
.
equalToSuperview
()
}
}
...
@@ -112,6 +98,29 @@ class YHAIMainChatViewController: YHBaseViewController {
...
@@ -112,6 +98,29 @@ class YHAIMainChatViewController: YHBaseViewController {
self
.
tableView
.
scrollToRow
(
at
:
indexPath
,
at
:
.
bottom
,
animated
:
true
)
self
.
tableView
.
scrollToRow
(
at
:
indexPath
,
at
:
.
bottom
,
animated
:
true
)
}
}
}
}
func
sendMessage
(
_
text
:
String
)
{
self
.
manager
.
getMainChatConversationId
{
sesseionId
in
self
.
conversationId
=
sesseionId
YHAIChatConfiguration
.
defaultConfig
.
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
.
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
)
if
done
{
self
.
bottomInputView
.
status
=
self
.
bottomInputView
.
textView
.
text
.
isEmpty
?
.
disableSend
:
.
enableSend
}
self
.
scrollToBottom
()
}
}
}
}
}
extension
YHAIMainChatViewController
:
UITableViewDelegate
,
UITableViewDataSource
{
extension
YHAIMainChatViewController
:
UITableViewDelegate
,
UITableViewDataSource
{
...
...
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/C/YHAIRobotChatViewController.swift
View file @
661245a8
...
@@ -46,23 +46,7 @@ class YHAIRobotChatViewController: YHBaseViewController {
...
@@ -46,23 +46,7 @@ class YHAIRobotChatViewController: YHBaseViewController {
v
.
sendBlock
=
{
v
.
sendBlock
=
{
[
weak
self
]
text
in
[
weak
self
]
text
in
guard
let
self
=
self
else
{
return
}
guard
let
self
=
self
else
{
return
}
self
.
sendMessage
(
text
)
YHAIChatConfiguration
.
defaultConfig
.
removeThinkingMessageFromChatList
(
&
messages
)
let
question
=
YHAIChatMessage
.
createQuestionMessage
(
text
)
messages
.
append
(
question
)
messages
.
append
(
thinkingMessage
)
self
.
scrollToBottom
()
self
.
bottomInputView
.
status
=
.
loading
YHAIChatConfiguration
.
defaultConfig
.
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
)
if
done
{
self
.
bottomInputView
.
status
=
self
.
bottomInputView
.
textView
.
text
.
isEmpty
?
.
disableSend
:
.
enableSend
}
self
.
scrollToBottom
()
}
}
}
v
.
stopSendBlock
=
{
v
.
stopSendBlock
=
{
[
weak
self
]
in
[
weak
self
]
in
...
@@ -100,6 +84,11 @@ class YHAIRobotChatViewController: YHBaseViewController {
...
@@ -100,6 +84,11 @@ class YHAIRobotChatViewController: YHBaseViewController {
self
.
view
.
addSubview
(
self
.
bottomInputView
)
self
.
view
.
addSubview
(
self
.
bottomInputView
)
self
.
view
.
addSubview
(
self
.
bgImgView
)
self
.
view
.
addSubview
(
self
.
bgImgView
)
self
.
view
.
insertSubview
(
bgImgView
,
belowSubview
:
gk_navigationBar
)
self
.
view
.
insertSubview
(
bgImgView
,
belowSubview
:
gk_navigationBar
)
YHAIChatConfiguration
.
defaultConfig
.
recommentMsgClick
=
{
[
weak
self
]
text
in
guard
let
self
=
self
else
{
return
}
self
.
sendMessage
(
text
)
}
bgImgView
.
snp
.
makeConstraints
{
make
in
bgImgView
.
snp
.
makeConstraints
{
make
in
make
.
edges
.
equalToSuperview
()
make
.
edges
.
equalToSuperview
()
...
@@ -121,6 +110,25 @@ class YHAIRobotChatViewController: YHBaseViewController {
...
@@ -121,6 +110,25 @@ class YHAIRobotChatViewController: YHBaseViewController {
self
.
tableView
.
scrollToRow
(
at
:
indexPath
,
at
:
.
bottom
,
animated
:
true
)
self
.
tableView
.
scrollToRow
(
at
:
indexPath
,
at
:
.
bottom
,
animated
:
true
)
}
}
}
}
func
sendMessage
(
_
text
:
String
)
{
YHAIChatConfiguration
.
defaultConfig
.
removeThinkingMessageFromChatList
(
&
messages
)
let
question
=
YHAIChatMessage
.
createQuestionMessage
(
text
)
messages
.
append
(
question
)
messages
.
append
(
thinkingMessage
)
self
.
scrollToBottom
()
self
.
bottomInputView
.
status
=
.
loading
YHAIChatConfiguration
.
defaultConfig
.
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
)
if
done
{
self
.
bottomInputView
.
status
=
self
.
bottomInputView
.
textView
.
text
.
isEmpty
?
.
disableSend
:
.
enableSend
}
self
.
scrollToBottom
()
}
}
}
}
extension
YHAIRobotChatViewController
:
UITableViewDelegate
,
UITableViewDataSource
{
extension
YHAIRobotChatViewController
:
UITableViewDelegate
,
UITableViewDataSource
{
...
...
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/M/YHAIMessageModel.swift
View file @
661245a8
...
@@ -15,13 +15,16 @@ class YHAIMessageModel: NSObject {
...
@@ -15,13 +15,16 @@ class YHAIMessageModel: NSObject {
enum
YHAIMessageType
:
Int
{
enum
YHAIMessageType
:
Int
{
case
thinking
=
-
1
// 思考消息
case
none
=
0
case
none
=
0
case
AIText
=
1
// 文字消息
case
AIText
=
1
// 文字消息
case
recommendText
=
2
// 推荐文字消息
case
fixProductList
=
2
// 固定商品列表消息
case
fixProductList
=
3
// 固定商品列表消息
case
productList
=
3
case
productList
=
4
case
card
=
4
case
card
=
5
// 自定义case
case
thinking
=
9527
// 思考消息
case
recommendText
=
-
9527
// 推荐文字消息
}
}
class
YHAIChatMessage
:
CustomStringConvertible
{
class
YHAIChatMessage
:
CustomStringConvertible
{
...
@@ -91,6 +94,15 @@ class YHAIChatMessage: CustomStringConvertible {
...
@@ -91,6 +94,15 @@ class YHAIChatMessage: CustomStringConvertible {
data
[
"contentText"
]
=
body
.
contentText
data
[
"contentText"
]
=
body
.
contentText
}
}
func
updateDataToBody
()
{
if
let
contentText
=
data
[
"contentText"
]
as?
String
{
body
.
contentText
=
contentText
}
if
let
contentType
=
data
[
"contentType"
]
as?
Int
{
body
.
contentType
=
contentType
}
}
// 获取消息类型
// 获取消息类型
func
getType
()
->
YHAIMessageType
{
func
getType
()
->
YHAIMessageType
{
if
let
contentType
=
data
[
"contentType"
]
as?
Int
{
if
let
contentType
=
data
[
"contentType"
]
as?
Int
{
...
@@ -117,7 +129,8 @@ class YHAIChatMessage: CustomStringConvertible {
...
@@ -117,7 +129,8 @@ class YHAIChatMessage: CustomStringConvertible {
// 获取文字消息的文字
// 获取文字消息的文字
func
getText
()
->
String
{
func
getText
()
->
String
{
if
getType
()
==
.
AIText
{
let
msgType
=
getType
()
if
msgType
==
.
AIText
||
msgType
==
.
recommendText
{
if
let
text
=
data
[
"contentText"
]
as?
String
,
!
text
.
isEmpty
{
if
let
text
=
data
[
"contentText"
]
as?
String
,
!
text
.
isEmpty
{
return
text
return
text
}
}
...
...
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/V/YHAITextMessageCell.swift
View file @
661245a8
...
@@ -12,6 +12,8 @@ class YHAITextMessageCell: UITableViewCell {
...
@@ -12,6 +12,8 @@ class YHAITextMessageCell: UITableViewCell {
static
let
cellReuseIdentifier
=
"YHAITextMessageCell"
static
let
cellReuseIdentifier
=
"YHAITextMessageCell"
var
messageClick
:((
String
)
->
())?
var
message
:
YHAIChatMessage
=
YHAIChatMessage
()
{
var
message
:
YHAIChatMessage
=
YHAIChatMessage
()
{
didSet
{
didSet
{
...
@@ -84,11 +86,13 @@ class YHAITextMessageCell: UITableViewCell {
...
@@ -84,11 +86,13 @@ class YHAITextMessageCell: UITableViewCell {
}
}
}
}
var
whiteContentView
:
UIView
=
{
lazy
var
whiteContentView
:
UIView
=
{
let
v
=
UIView
()
let
v
=
UIView
()
v
.
backgroundColor
=
.
white
v
.
backgroundColor
=
.
white
v
.
layer
.
cornerRadius
=
12.0
v
.
layer
.
cornerRadius
=
12.0
v
.
clipsToBounds
=
true
v
.
clipsToBounds
=
true
let
tap
=
UITapGestureRecognizer
(
target
:
self
,
action
:
#selector(
didMessageClicked
)
)
v
.
addGestureRecognizer
(
tap
)
return
v
return
v
}()
}()
...
@@ -213,4 +217,11 @@ class YHAITextMessageCell: UITableViewCell {
...
@@ -213,4 +217,11 @@ class YHAITextMessageCell: UITableViewCell {
make
.
bottom
.
equalTo
(
0
)
make
.
bottom
.
equalTo
(
0
)
}
}
}
}
@objc
func
didMessageClicked
()
{
if
message
.
getType
()
==
.
recommendText
{
let
text
=
message
.
getText
()
messageClick
?(
text
)
}
}
}
}
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