Skip to content

Commit f48b415

Browse files
reabbottedszabinst
andauthored
[Horizon] Assist Introduction Updates CLX-1730 (#3496)
* Adding the thumbs-up/thumbs down for assist chat. [ignore-commit-lint] * WIP [ignore-commit-lint] * WIP * WIP * Adding Cedar API calls and making the CoursePageGoal more capable * Adding some more options when viewing a page. * Disabling line length violations * Disabling line length violations * Making it so we can reset the environment * Making it so the course document goal actually does something * Making the translate option a little more generic * Removing the translation abilities for the moment * Removing the translation abilities for the moment * Code cleanup * Just updating a prompt * Addressing merge comments and improving the look of the assist chat * Fixing lint * Making it so you can press the back button while an assist message is in process and it cancels the request. * Making it so if we have lots of course options, it only presents the first 5. Making more options available to documents * Moving the related CourseDocument and CoursePage goals into a group * Satisfying swiftlint * Adding comments and section deliniation * Fixing Localizable.xcstrings * More code cleanup * Fixing a build error * Code Review * Code Review * Code Review * fix: resolve memory leaks * Fixing an empty response and back button not appearing in assist * Fixing Goals * Adding back error handling * Adding back error handling * Swiftlint fix --------- Co-authored-by: szabinst <[email protected]>
1 parent 2c4ae14 commit f48b415

38 files changed

+1866
-920
lines changed

Core/Core/Common/CommonModels/API/API.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
//
1818

19+
import Combine
1920
import Foundation
2021

2122
public class API {

Core/Core/Features/Inbox/ComposeMessage/View/WrappingHStack.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,21 @@ public struct WrappingHStack<Model, V>: View where Model: Hashable, V: View {
2222
public typealias ViewGenerator = (Model) -> V
2323
var models: [Model]
2424
var viewGenerator: ViewGenerator
25-
var horizontalSpacing: CGFloat = 5
26-
var verticalSpacing: CGFloat = 5
25+
var horizontalSpacing: CGFloat
26+
var verticalSpacing: CGFloat
2727

2828
@State private var totalHeight = CGFloat.zero
2929

3030
public init(
3131
models: [Model],
32+
horizontalSpacing: CGFloat = 5,
33+
verticalSpacing: CGFloat = 5,
3234
viewGenerator: @escaping ViewGenerator
3335
) {
3436
self.models = models
3537
self.viewGenerator = viewGenerator
38+
self.horizontalSpacing = horizontalSpacing
39+
self.verticalSpacing = horizontalSpacing
3640
}
3741

3842
public var body: some View {

Horizon/Horizon/Resources/Localizable.xcstrings

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@
210210
},
211211
"Cairo (+02:00/+03:00)" : {
212212

213+
},
214+
"Can I answer any questions about this document for you?" : {
215+
213216
},
214217
"Canberra (+10:00/+11:00)" : {
215218

@@ -285,6 +288,9 @@
285288
},
286289
"Copenhagen (+01:00/+02:00)" : {
287290

291+
},
292+
"Create a Quiz" : {
293+
288294
},
289295
"Create message" : {
290296

@@ -390,9 +396,6 @@
390396
},
391397
"Filter by person" : {
392398

393-
},
394-
"Flash cards" : {
395-
396399
},
397400
"Fortaleza (-03:00/-03:00)" : {
398401

@@ -402,6 +405,9 @@
402405
},
403406
"Full Name can only be changed by your institution." : {
404407

408+
},
409+
"Generate Flash Cards" : {
410+
405411
},
406412
"Georgetown (-04:00/-04:00)" : {
407413

@@ -435,6 +441,9 @@
435441
},
436442
"Hello, Career!" : {
437443

444+
},
445+
"Hello! Which course you'd like to discuss today?" : {
446+
438447
},
439448
"Helsinki (+02:00/+03:00)" : {
440449

@@ -454,7 +463,7 @@
454463
"hours" : {
455464

456465
},
457-
"How can I help today?" : {
466+
"How can I help you with this page?" : {
458467

459468
},
460469
"Important" : {
@@ -504,9 +513,6 @@
504513
},
505514
"Kathmandu (+05:45/+05:45)" : {
506515

507-
},
508-
"Key takeaways" : {
509-
510516
},
511517
"Kolkata (+05:30)" : {
512518

@@ -534,9 +540,6 @@
534540
},
535541
"Learn" : {
536542

537-
},
538-
"Learner" : {
539-
540543
},
541544
"Lima (-05:00/-05:00)" : {
542545

@@ -648,9 +651,18 @@
648651
},
649652
"No" : {
650653

654+
},
655+
"No additional information found." : {
656+
657+
},
658+
"No key takeaways found." : {
659+
651660
},
652661
"No notification activity yet." : {
653662

663+
},
664+
"No summary found." : {
665+
654666
},
655667
"Norfolk Island (+11:00/+12:00)" : {
656668

@@ -758,9 +770,6 @@
758770
},
759771
"Quito (-05:00/-05:00)" : {
760772

761-
},
762-
"Quiz" : {
763-
764773
},
765774
"Rangoon (+06:30/+06:30)" : {
766775

@@ -866,6 +875,12 @@
866875
},
867876
"Something went wrong" : {
868877

878+
},
879+
"Sorry, can we try that again? Which course is it you'd like to discuss?" : {
880+
881+
},
882+
"Sorry, I don't have an answer for that right now." : {
883+
869884
},
870885
"Sort By" : {
871886

@@ -896,9 +911,6 @@
896911
},
897912
"Submitted" : {
898913

899-
},
900-
"Summarize" : {
901-
902914
},
903915
"Support" : {
904916

@@ -927,10 +939,10 @@
927939
"Tehran (+03:30/+03:30)" : {
928940

929941
},
930-
"Tell me more" : {
942+
"Text" : {
931943

932944
},
933-
"Text" : {
945+
"Thank you for your feedback!" : {
934946

935947
},
936948
"There are no scored activities in this course." : {
@@ -1037,6 +1049,12 @@
10371049
},
10381050
"West Central Africa (+01:00)" : {
10391051

1052+
},
1053+
"What would you like to discuss about the course %@?" : {
1054+
1055+
},
1056+
"What would you like to discuss today?" : {
1057+
10401058
},
10411059
"Yakutsk (+09:00/+09:00)" : {
10421060

Horizon/Horizon/Sources/Features/Assist/AssistAssembly.swift

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,19 @@ final class AssistAssembly {
4444
return navigationController
4545
}
4646

47-
static func makeChatBotInteractor(courseId: String? = nil, pageUrl: String? = nil, fileId: String? = nil) -> AssistChatInteractor {
48-
if let courseId = courseId, let pageUrl = pageUrl {
49-
return AssistChatInteractorLive(
50-
courseId: courseId,
51-
pageUrl: pageUrl
52-
)
53-
}
54-
if let courseId = courseId, let fileId = fileId {
55-
return AssistChatInteractorLive(
56-
courseId: courseId,
57-
fileId: fileId,
58-
downloadFileInteractor: DownloadFileInteractorLive(courseID: courseId)
59-
)
60-
}
61-
return AssistChatInteractorLive()
47+
static func makeChatBotInteractor(
48+
courseId: String? = nil,
49+
pageUrl: String? = nil,
50+
fileId: String? = nil
51+
) -> AssistChatInteractor {
52+
AssistChatInteractorLive(
53+
courseID: courseId,
54+
fileID: fileId,
55+
pageURL: pageUrl,
56+
downloadFileInteractor: courseId.map {
57+
DownloadFileInteractorLive(courseID: $0)
58+
}
59+
)
6260
}
6361

6462
static func makeAIQuizView(

Horizon/Horizon/Sources/Features/Assist/AssistChat/Data/AssistChatAction.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ import Core
2020

2121
/// ChatBotActions are published to the AssistChatInteractor. The Interactor reacts to the action and publishes one or more ChatBotResponses.
2222
enum AssistChatAction {
23+
case begin
24+
2325
/// the user is chatting with the bot
24-
case chat(prompt: String = "", history: [AssistChatMessage] = [])
26+
case chat(prompt: String?, history: [AssistChatMessage] = [])
2527

2628
/// the user has selected a chip while viewing a file
2729
case chip(option: AssistChipOption, history: [AssistChatMessage] = [])

Horizon/Horizon/Sources/Features/Assist/AssistChat/Data/AssistChatMessage.swift

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,51 +19,85 @@
1919
import Foundation
2020

2121
/// A message returned from the interactor
22-
struct AssistChatMessage: Codable, Equatable {
22+
struct AssistChatMessage {
2323

2424
let id: UUID
2525

2626
/// The prompt that was sent to the AI. Not shown to the user
2727
/// If set to null, then it is removed from the list of messages sent to the AI
2828
let prompt: String?
2929

30-
/// The text shown to the user in the history. This may be different from the prompt sent to the AI
31-
let text: String
30+
/// The text shown to the user on screen. This may be different from the prompt sent to the AI
31+
let text: String?
3232

3333
/// Whether or not this came from the AI
3434
let role: Role
3535

36-
init(botResponse: String) {
37-
prompt = botResponse
38-
text = botResponse
39-
role = .Assistant
40-
id = UUID()
36+
/// A list of options that the user can select from.
37+
let chipOptions: [AssistChipOption]?
38+
39+
let flashCards: [AssistChatFlashCard]?
40+
41+
let quizItems: [QuizItem]?
42+
43+
init(botResponse: String, chipOptions: [AssistChipOption] = []) {
44+
self.init(
45+
role: .Assistant,
46+
prompt: botResponse,
47+
text: botResponse,
48+
chipOptions: chipOptions
49+
)
4150
}
4251

43-
init(userResponse: String) {
44-
prompt = userResponse
45-
text = userResponse
46-
role = .User
47-
id = UUID()
52+
/// The user has asked for FlashCards
53+
init(flashCards: [AssistChatFlashCard]) {
54+
self.init(
55+
role: .Assistant,
56+
flashCards: flashCards
57+
)
4858
}
4959

50-
init(prompt: String?, text: String, role: Role = .User) {
51-
self.prompt = prompt
52-
self.text = text
53-
id = UUID()
60+
/// The user has asked for a quiz
61+
init(quizItems: [QuizItem]) {
62+
self.init(
63+
role: .Assistant,
64+
quizItems: quizItems
65+
)
66+
}
5467

55-
self.role = role
68+
init(userResponse: String, prompt: String? = nil) {
69+
self.init(
70+
role: .User,
71+
prompt: prompt ?? userResponse,
72+
text: userResponse
73+
)
5674
}
5775

58-
func encode(to encoder: Encoder) throws {
59-
var container = encoder.container(keyedBy: CodingKeys.self)
60-
try container.encode(prompt, forKey: .prompt)
61-
try container.encode(text, forKey: .text)
62-
try container.encode(role, forKey: .role)
76+
private init(
77+
role: Role,
78+
prompt: String? = nil,
79+
text: String? = nil,
80+
chipOptions: [AssistChipOption] = [],
81+
flashCards: [AssistChatFlashCard] = [],
82+
quizItems: [QuizItem]? = nil
83+
) {
84+
self.id = UUID()
85+
self.role = role
86+
self.prompt = prompt
87+
self.text = text
88+
self.chipOptions = chipOptions
89+
self.flashCards = flashCards
90+
self.quizItems = quizItems
6391
}
6492

6593
enum Role: String, Codable, Equatable {
6694
case Assistant
6795
case User
6896
}
97+
98+
struct QuizItem: Codable, Equatable {
99+
let question: String
100+
let answers: [String]
101+
let correctAnswerIndex: Int
102+
}
69103
}

0 commit comments

Comments
 (0)