Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[ensu] Fix conversation CI checks

setalp3583a478fe64
diff --git a/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatStoreActions.kt b/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatStoreActions.kt
index b1c7d7b947..0167e8dc7e 100644
--- a/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatStoreActions.kt
+++ b/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatStoreActions.kt
@@ -559,13 +559,12 @@ internal class ChatStoreActions(
} catch (_: LlmProvider.EmbeddingAssetInvalid) {
embeddingAssetInvalid = true
emptyList()
+ } catch (_: LlmException.Cancelled) {
+ return@launch
+ } catch (_: AssetDownloadException.Cancelled) {
+ return@launch
} catch (error: Throwable) {
- if (
- !isActive() ||
- stopRequested ||
- error is LlmException.Cancelled ||
- error is AssetDownloadException.Cancelled
- ) {
+ if (!isActive() || stopRequested) {
return@launch
}
logRepository.log(
@@ -943,12 +942,12 @@ internal class ChatStoreActions(
}
} catch (error: kotlinx.coroutines.CancellationException) {
throw error
+ } catch (_: LlmException.Cancelled) {
+ return
+ } catch (_: ConversationException.Cancelled) {
+ return
} catch (error: Throwable) {
- val cancelled =
- stopRequested ||
- error is LlmException.Cancelled ||
- error is ConversationException.Cancelled
- if (!cancelled) {
+ if (!stopRequested) {
logRepository.log(
LogLevel.Error,
"Conversation preparation failed",
diff --git a/apple/apps/ensu/Ensu/Chat/ChatViewModel.swift b/apple/apps/ensu/Ensu/Chat/ChatViewModel.swift
index 1622538525..7a7d1b3265 100644
--- a/apple/apps/ensu/Ensu/Chat/ChatViewModel.swift
+++ b/apple/apps/ensu/Ensu/Chat/ChatViewModel.swift
@@ -1302,7 +1302,8 @@ final class ChatViewModel: ObservableObject {
}
}
do {
- let runGeneration: () async throws -> GenerationSummary = {
+ let runGeneration: @MainActor ([LlmMessage]) async throws -> GenerationSummary = {
+ messages in
if prompt.imageFiles.isEmpty {
return try await self.generatePreparedChat(
selection,
@@ -1344,7 +1345,7 @@ final class ChatViewModel: ObservableObject {
}
let summary: GenerationSummary
do {
- summary = try await runGeneration()
+ summary = try await runGeneration(messages)
} catch {
if case LlmError.PromptTooLong = error,
!prompt.imageFiles.isEmpty,
@@ -1360,7 +1361,7 @@ final class ChatViewModel: ObservableObject {
hasAttachments: false
)
] + normalHistoryMessages + [userMessage]
- summary = try await runGeneration()
+ summary = try await runGeneration(messages)
} else {
throw error
}
diff --git a/rust/crates/ensu/src/conversation/lookup.rs b/rust/crates/ensu/src/conversation/lookup.rs
index f3ec08bd4b..dbe311d0a3 100644
--- a/rust/crates/ensu/src/conversation/lookup.rs
+++ b/rust/crates/ensu/src/conversation/lookup.rs
@@ -207,7 +207,7 @@ pub(super) fn lookup_history(
));
}
}
- candidates.sort_by(|a, b| (b.0, b.1, b.2).cmp(&(a.0, a.1, a.2)));
+ candidates.sort_by_key(|a| std::cmp::Reverse((a.0, a.1, a.2)));
let mut included = HashSet::new();
for (_, _, index, hit) in candidates {
if result.excerpts.len() >= LOOKUP_MAX_EXCERPTS {