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
f9b64510
Commit
f9b64510
authored
Nov 29, 2024
by
Steven杜宇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
// AI
parent
2b46bfd3
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
188 additions
and
43 deletions
+188
-43
YHAIMainChatViewController.swift
...s/AI/AI-Dialogue(AI对话)/C/YHAIMainChatViewController.swift
+12
-7
YHAIRequestManager.swift
...s/Modules/AI/AI-Dialogue(AI对话)/C/YHAIRequestManager.swift
+5
-8
YHAIRobotChatViewController.swift
.../AI/AI-Dialogue(AI对话)/C/YHAIRobotChatViewController.swift
+123
-10
YHAIServiceListViewController.swift
...I/AI-Dialogue(AI对话)/C/YHAIServiceListViewController.swift
+11
-12
YHAITabViewController.swift
...odules/AI/AI-Dialogue(AI对话)/C/YHAITabViewController.swift
+33
-4
YHAIProductCell.swift
...sses/Modules/AI/AI-Dialogue(AI对话)/V/YHAIProductCell.swift
+4
-2
No files found.
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/C/YHAIMainChatViewController.swift
View file @
f9b64510
...
...
@@ -13,6 +13,8 @@ import JXSegmentedView
class
YHAIMainChatViewController
:
YHBaseViewController
{
var
robotId
:
String
=
""
var
messages
:[
YHAIMessage
]
=
[]
lazy
var
tableView
:
UITableView
=
{
...
...
@@ -45,13 +47,16 @@ class YHAIMainChatViewController: YHBaseViewController {
messages
.
append
(
thinkingMessage
)
self
.
scrollToBottom
()
YHAIRequestManager
.
shared
.
requestAI
(
botId
:
""
,
conversationId
:
""
,
question
:
text
)
{
[
weak
self
]
res
,
done
in
guard
let
self
=
self
else
{
return
}
YHAIChatConfiguration
.
defaultConfig
.
handleReceiveMessage
(
res
,
done
,
&
messages
)
self
.
scrollToBottom
()
YHAIRequestManager
.
shared
.
getMainChatConversationId
{
sesseionId
in
YHAIRequestManager
.
shared
.
requestAI
(
botId
:
self
.
robotId
,
conversationId
:
sesseionId
,
question
:
text
)
{
[
weak
self
]
res
,
done
in
guard
let
self
=
self
else
{
return
}
YHAIChatConfiguration
.
defaultConfig
.
handleReceiveMessage
(
res
,
done
,
&
messages
)
self
.
scrollToBottom
()
}
}
}
return
v
}()
...
...
@@ -112,7 +117,7 @@ extension YHAIMainChatViewController: UITableViewDelegate, UITableViewDataSource
let
defaultCell
=
tableView
.
dequeueReusableCell
(
withIdentifier
:
"UITableViewCell"
,
for
:
indexPath
)
return
defaultCell
}
func
tableView
(
_
tableView
:
UITableView
,
heightForRowAt
indexPath
:
IndexPath
)
->
CGFloat
{
return
UITableView
.
automaticDimension
}
...
...
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/C/YHAIRequestManager.swift
View file @
f9b64510
...
...
@@ -59,8 +59,6 @@ class YHAIRequestManager: NSObject {
func
requestAI
(
botId
:
String
,
conversationId
:
String
,
question
:
String
=
""
,
completion
:
((
_
msg
:
YHAIMessage
?,
_
done
:
Bool
)
->
Void
)?)
{
self
.
getSessionId
{
sesseionId
in
let
url
=
YHBaseUrlManager
.
shared
.
curURL
()
+
YHAllApiName
.
AIChat
.
agentChat
self
.
uuid
=
UUID
()
.
uuidString
+
NSDate
()
.
timeIntervalSince1970
.
description
...
...
@@ -68,11 +66,11 @@ class YHAIRequestManager: NSObject {
// body 请求体参数
var
parameters
=
[
"botId"
:
botId
,
"conversationId"
:
conversationId
,
"question"
:
question
]
"question"
:
question
]
as!
[
String
:
Any
]
parameters
=
[
"botId"
:
"7441190609433755702"
,
"conversationId"
:
sesseionId
,
"question"
:
question
]
as!
[
String
:
String
]
//
parameters = ["botId": "7441190609433755702",
//
"conversationId": sesseionId,
//
"question": question] as! [String: String]
let
headers
=
self
.
getCommonHeaders
()
...
...
@@ -121,7 +119,6 @@ class YHAIRequestManager: NSObject {
}
}
}
}
}
func
dictionaryToHttpBodyStream
(
_
dic
:
[
String
:
Any
])
->
InputStream
?
{
...
...
@@ -199,7 +196,7 @@ class YHAIRequestManager: NSObject {
}
extension
YHAIRequestManager
{
func
get
Sess
ionId
(
completion
:((
String
)
->
())?)
{
func
get
MainChatConversat
ionId
(
completion
:((
String
)
->
())?)
{
if
let
sessionId
=
UserDefaults
.
standard
.
value
(
forKey
:
YHAIRequestManager
.
sessionKey
)
as?
String
,
!
sessionId
.
isEmpty
{
completion
?(
sessionId
)
...
...
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/C/YHAIRobotChatViewController.swift
View file @
f9b64510
...
...
@@ -5,26 +5,139 @@
// Created by Dufet on 2024/11/29.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import
UIKit
import
Alamofire
import
IQKeyboardManagerSwift
import
JXSegmentedView
class
YHAIRobotChatViewController
:
YHBaseViewController
{
var
robotId
:
String
=
""
var
conversationId
:
String
=
""
var
messages
:[
YHAIMessage
]
=
[]
lazy
var
tableView
:
UITableView
=
{
let
tableView
=
UITableView
(
frame
:
.
zero
,
style
:
.
grouped
)
if
#available(iOS 11.0, *)
{
tableView
.
contentInsetAdjustmentBehavior
=
.
never
}
tableView
.
showsVerticalScrollIndicator
=
false
tableView
.
estimatedSectionHeaderHeight
=
1.0
tableView
.
estimatedSectionFooterHeight
=
1.0
tableView
.
backgroundColor
=
.
clear
tableView
.
separatorStyle
=
.
none
tableView
.
delegate
=
self
tableView
.
dataSource
=
self
YHAIChatConfiguration
.
defaultConfig
.
registerMessageGroupCells
(
tableView
)
return
tableView
}()
lazy
var
bottomInputView
:
YHAITextInputView
=
{
let
v
=
YHAITextInputView
(
frame
:
.
zero
)
v
.
sendBlock
=
{
[
weak
self
]
text
in
guard
let
self
=
self
else
{
return
}
YHAIChatConfiguration
.
defaultConfig
.
removeThinkingMessageFromChatList
(
&
messages
)
let
question
=
YHAIMessage
.
createQuestionMessage
(
text
)
messages
.
append
(
question
)
messages
.
append
(
thinkingMessage
)
self
.
scrollToBottom
()
YHAIRequestManager
.
shared
.
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
.
scrollToBottom
()
}
}
return
v
}()
lazy
var
thinkingMessage
:
YHAIMessage
=
{
let
msg
=
YHAIMessage
.
createThinkingMesssage
()
return
msg
}()
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
// Do any additional setup after loading the view.
gk_navBarAlpha
=
0
view
.
backgroundColor
=
.
clear
IQKeyboardManager
.
shared
.
enable
=
false
gk_navTitle
=
"新港生活规划师"
self
.
view
.
addSubview
(
self
.
tableView
)
self
.
view
.
addSubview
(
self
.
bottomInputView
)
tableView
.
snp
.
makeConstraints
{
make
in
make
.
left
.
right
.
equalTo
(
0
)
make
.
top
.
equalTo
(
0
)
make
.
bottom
.
equalTo
(
bottomInputView
.
snp
.
top
)
.
offset
(
-
10
)
}
bottomInputView
.
snp
.
makeConstraints
{
make
in
make
.
left
.
right
.
bottom
.
equalToSuperview
()
}
}
func
scrollToBottom
()
{
self
.
tableView
.
reloadData
{
let
indexPath
=
IndexPath
(
row
:
self
.
messages
.
count
-
1
,
section
:
0
)
self
.
tableView
.
scrollToRow
(
at
:
indexPath
,
at
:
.
bottom
,
animated
:
true
)
}
}
}
/*
// MARK: - Navigation
extension
YHAIRobotChatViewController
:
UITableViewDelegate
,
UITableViewDataSource
{
func
numberOfSections
(
in
tableView
:
UITableView
)
->
Int
{
return
1
}
func
tableView
(
_
tableView
:
UITableView
,
numberOfRowsInSection
section
:
Int
)
->
Int
{
return
messages
.
count
}
func
tableView
(
_
tableView
:
UITableView
,
cellForRowAt
indexPath
:
IndexPath
)
->
UITableViewCell
{
if
0
<=
indexPath
.
row
,
indexPath
.
row
<
messages
.
count
{
let
msg
=
messages
[
indexPath
.
row
]
let
cell
=
YHAIChatConfiguration
.
defaultConfig
.
getMessageCell
(
msg
,
tableView
,
indexPath
:
indexPath
)
return
cell
}
let
defaultCell
=
tableView
.
dequeueReusableCell
(
withIdentifier
:
"UITableViewCell"
,
for
:
indexPath
)
return
defaultCell
}
func
tableView
(
_
tableView
:
UITableView
,
heightForRowAt
indexPath
:
IndexPath
)
->
CGFloat
{
return
UITableView
.
automaticDimension
}
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
func
tableView
(
_
tableView
:
UITableView
,
heightForFooterInSection
section
:
Int
)
->
CGFloat
{
return
1.0
}
func
tableView
(
_
tableView
:
UITableView
,
viewForFooterInSection
section
:
Int
)
->
UIView
?
{
let
view
=
UIView
()
return
view
}
func
tableView
(
_
tableView
:
UITableView
,
heightForHeaderInSection
section
:
Int
)
->
CGFloat
{
return
1.0
}
*/
}
extension
YHAIRobotChatViewController
:
JXSegmentedListContainerViewListDelegate
{
func
listView
()
->
UIView
{
return
view
}
}
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/C/YHAIServiceListViewController.swift
View file @
f9b64510
...
...
@@ -100,17 +100,6 @@ class YHAIServiceListViewController: YHBaseViewController {
make
.
height
.
equalTo
(
46
)
make
.
bottom
.
equalTo
(
-
10
-
k_Height_safeAreaInsetsBottom
())
}
requestList
()
}
func
requestList
()
{
viewModel
.
getAIEntranceList
{
[
weak
self
]
success
,
error
in
guard
let
self
=
self
else
{
return
}
serviceArr
.
removeAll
()
serviceArr
.
append
(
contentsOf
:
self
.
viewModel
.
listModel
.
entranceConfig
)
self
.
collectionView
.
reloadData
()
}
}
}
...
...
@@ -145,7 +134,17 @@ extension YHAIServiceListViewController: UICollectionViewDelegate, UICollectionV
func
collectionView
(
_
collectionView
:
UICollectionView
,
didSelectItemAt
indexPath
:
IndexPath
)
{
if
0
<=
indexPath
.
item
&&
indexPath
.
item
<
serviceArr
.
count
{
let
text
=
serviceArr
[
indexPath
.
item
]
let
model
=
serviceArr
[
indexPath
.
item
]
YHHUD
.
show
(
.
progress
(
message
:
"加载中..."
))
YHAIRequestManager
.
shared
.
getMainChatConversationId
{
sesseionId
in
YHHUD
.
hide
()
let
vc
=
YHAIRobotChatViewController
()
vc
.
robotId
=
model
.
botId
vc
.
conversationId
=
sesseionId
self
.
navigationController
?
.
pushViewController
(
vc
,
animated
:
true
)
}
}
}
...
...
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/C/YHAITabViewController.swift
View file @
f9b64510
...
...
@@ -12,6 +12,7 @@ import JXSegmentedView
class
YHAITabViewController
:
YHBaseViewController
{
var
defaltIndex
:
Int
=
0
let
viewModel
=
YHAIViewModel
()
let
arrItemTitles
=
[
"港小宝"
,
"对话"
]
var
arrItemVCs
:
[
YHBaseViewController
]
=
[]
...
...
@@ -65,6 +66,17 @@ class YHAITabViewController: YHBaseViewController {
return
btn
}()
lazy
var
listVC
:
YHAIServiceListViewController
=
{
let
vc
=
YHAIServiceListViewController
()
return
vc
}()
lazy
var
mainChatVC
:
YHAIMainChatViewController
=
{
let
vc
=
YHAIMainChatViewController
()
return
vc
}()
@objc
func
didBackBtnClicked
()
{
self
.
navigationController
?
.
popViewController
(
animated
:
true
)
}
...
...
@@ -77,6 +89,11 @@ class YHAITabViewController: YHBaseViewController {
createUI
()
}
override
func
viewWillAppear
(
_
animated
:
Bool
)
{
super
.
viewWillAppear
(
animated
)
requestList
()
}
deinit
{
NotificationCenter
.
default
.
removeObserver
(
self
)
}
...
...
@@ -88,14 +105,13 @@ class YHAITabViewController: YHBaseViewController {
view
.
addSubview
(
bgImgView
)
view
.
addSubview
(
headerImgView
)
arrItemVCs
.
removeAll
()
for
i
in
0
..<
arrItemTitles
.
count
{
if
i
==
0
{
// 银河AI
let
vc
=
YHAIServiceListViewController
()
arrItemVCs
.
append
(
vc
)
arrItemVCs
.
append
(
listVC
)
}
else
if
i
==
1
{
// 对话
let
vc
=
YHAIMainChatViewController
()
arrItemVCs
.
append
(
vc
)
arrItemVCs
.
append
(
mainChatVC
)
}
}
...
...
@@ -151,6 +167,19 @@ class YHAITabViewController: YHBaseViewController {
}
}
func
requestList
()
{
YHHUD
.
show
(
.
progress
(
message
:
"加载中..."
))
viewModel
.
getAIEntranceList
{
[
weak
self
]
success
,
error
in
YHHUD
.
hide
()
guard
let
self
=
self
else
{
return
}
self
.
mainChatVC
.
robotId
=
self
.
viewModel
.
listModel
.
mainBotId
self
.
listVC
.
serviceArr
.
removeAll
()
self
.
listVC
.
serviceArr
.
append
(
contentsOf
:
self
.
viewModel
.
listModel
.
entranceConfig
)
self
.
listVC
.
collectionView
.
reloadData
()
}
}
func
jumpToItemIndex
(
itemIndex
:
Int
)
{
self
.
segmentedView
.
selectItemAt
(
index
:
itemIndex
)
}
...
...
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/V/YHAIProductCell.swift
View file @
f9b64510
...
...
@@ -25,6 +25,7 @@ class YHAIProductCell: UICollectionViewCell {
}
else
{
blackButton
.
setTitle
(
"去了解"
,
for
:
.
normal
)
}
bgImgView
.
sd_setImage
(
with
:
URL
(
string
:
model
.
cover
))
}
}
...
...
@@ -122,7 +123,8 @@ class YHAIProductCell: UICollectionViewCell {
titleLabel
.
transform
=
transform
subtitleLabel
.
transform
=
transform
blackButton
.
transform
=
transform
bgImgView
.
image
=
UIImage
(
named
:
isRotateRight
?
"ai_product_left"
:
"ai_product_right"
)
if
model
.
cover
.
isEmpty
{
bgImgView
.
image
=
UIImage
(
named
:
isRotateRight
?
"ai_product_left"
:
"ai_product_right"
)
}
}
}
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