Skip to content

Commit 678601e

Browse files
committed
Remove default scopes in custom chats, and reset them on prompt reset
1 parent 8fba67c commit 678601e

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

Core/Sources/ChatService/ChatService.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,22 @@ public final class ChatService: ObservableObject {
4949
functionProvider: memory.functionProvider
5050
)
5151
)
52+
53+
resetDefaultScopes()
5254

55+
memory.chatService = self
5356
memory.observeHistoryChange { [weak self] in
5457
self?.objectWillChange.send()
5558
}
5659
}
60+
61+
public func resetDefaultScopes() {
62+
if UserDefaults.shared.value(for: \.useCodeScopeByDefaultInChatContext) {
63+
memory.contextController.defaultScopes = ["code"]
64+
} else {
65+
memory.contextController.defaultScopes = ["file"]
66+
}
67+
}
5768

5869
public func send(content: String) async throws {
5970
guard !isReceivingMessage else { throw CancellationError() }
@@ -101,6 +112,7 @@ public final class ChatService: ObservableObject {
101112
public func resetPrompt() async {
102113
systemPrompt = UserDefaults.shared.value(for: \.defaultChatSystemPrompt)
103114
extraSystemPrompt = ""
115+
resetDefaultScopes()
104116
}
105117

106118
public func deleteMessage(id: String) async {
@@ -161,6 +173,7 @@ public final class ChatService: ObservableObject {
161173
name: command.name
162174
)
163175
case let .customChat(systemPrompt, prompt):
176+
memory.contextController.defaultScopes = []
164177
return .init(
165178
specifiedSystemPrompt: systemPrompt,
166179
extraSystemPrompt: "",

Core/Sources/ChatService/DynamicContextController.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ final class DynamicContextController {
99
let contextCollectors: [ChatContextCollector]
1010
let memory: AutoManagedChatGPTMemory
1111
let functionProvider: ChatFunctionProvider
12+
var defaultScopes = [] as Set<String>
1213

1314
convenience init(
1415
memory: AutoManagedChatGPTMemory,
@@ -35,11 +36,7 @@ final class DynamicContextController {
3536
func updatePromptToMatchContent(systemPrompt: String, content: String) async throws {
3637
var content = content
3738
var scopes = Self.parseScopes(&content)
38-
if UserDefaults.shared.value(for: \.useCodeScopeByDefaultInChatContext) {
39-
scopes.insert("code")
40-
} else {
41-
scopes.insert("file")
42-
}
39+
scopes.formUnion(defaultScopes)
4340

4441
functionProvider.removeAll()
4542
let language = UserDefaults.shared.value(for: \.chatGPTLanguage)

0 commit comments

Comments
 (0)