-
-
Notifications
You must be signed in to change notification settings - Fork 43
[Bug] Chat name being generate even when option is disabled #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
bug
Something isn't working
Comments
For reference: AI Generated patch that I am using in a local build locally and seems to works. diff --git a/macai/Utilities/MessageManager.swift b/macai/Utilities/MessageManager.swift
index d9b7f09..c45bb6a 100644
--- a/macai/Utilities/MessageManager.swift
+++ b/macai/Utilities/MessageManager.swift
@@ -99,19 +99,47 @@ class MessageManager: ObservableObject {
}
func generateChatNameIfNeeded(chat: ChatEntity, force: Bool = false) {
- guard force || chat.name == "", chat.messages.count > 0 else {
+ // Condition 1: API service must exist and allow name generation
+ guard let serviceEntity = chat.apiService else {
#if DEBUG
- print("Chat name not needed, skipping generation")
+ print("MessageManager: Chat name generation skipped - API service entity is nil for chat \(chat.id.uuidString).")
#endif
return
}
+ guard serviceEntity.generateChatNames else {
+ #if DEBUG
+ // Use serviceEntity here, which is APIServiceEntity and has a name property
+ print("MessageManager: Chat name generation skipped - 'generateChatNames' is false for API service '\(serviceEntity.name ?? "Unnamed")' (chat \(chat.id.uuidString)).")
+ #endif
+ return
+ }
+
+ // Condition 2: Either force generation, or chat name is empty and there are messages
+ let needsGenerationDueToEmptyName = chat.name == "" && chat.messages.count > 0
+ guard force || needsGenerationDueToEmptyName else {
+ #if DEBUG
+ if !force && chat.name != "" {
+ print("MessageManager: Chat name generation skipped - chat '\(chat.name)' already has a name and force is false (chat \(chat.id.uuidString)).")
+ } else if !force && chat.messages.count == 0 && chat.name == "" {
+ print("MessageManager: Chat name generation skipped - chat has no messages, name is empty, and force is false (chat \(chat.id.uuidString)).")
+ } else {
+ print("MessageManager: Chat name generation skipped - conditions not met (force=\(force), nameEmpty=\(chat.name == ""), messagesCount=\(chat.messages.count)) for chat \(chat.id.uuidString).")
+ }
+ #endif
+ return
+ }
+
+ #if DEBUG
+ print("MessageManager: Proceeding with chat name generation for chat \(chat.id.uuidString) (force: \(force), current name: '\(chat.name)', message count: \(chat.messages.count)).")
+ #endif
let requestMessages = prepareRequestMessages(
userMessage: AppConstants.chatGptGenerateChatInstruction,
chat: chat,
contextSize: 3
)
- apiService.sendMessage(requestMessages, temperature: AppConstants.defaultTemperatureForChatNameGeneration) {
+ // Use self.apiService (the protocol instance) to send messages, not serviceEntity (the CoreData entity)
+ self.apiService.sendMessage(requestMessages, temperature: AppConstants.defaultTemperatureForChatNameGeneration) {
[weak self] result in
guard let self = self else { return }
@@ -252,4 +280,4 @@ class MessageManager: ObservableObject {
return messages
}
-}
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
In the latest version 2.1.0, when a user selects the option to not generate a chat name, the system still sends requests to generate chat names in the background. This behavior is unexpected and can lead to unnecessary costs, especially when dealing with long contexts.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
When the user selects the option to not generate a chat name, no requests for generating chat names should be sent. This ensures that unnecessary costs are avoided, especially for long contexts.
Screenshots
Additional context
This issue can be particularly problematic for users with large contexts or high usage volumes, as the unnecessary requests can significantly increase costs. A fix should ensure that the system respects the user's preference to disable chat name generation entirely.
The text was updated successfully, but these errors were encountered: