File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed
Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff 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: " " ,
Original file line number Diff line number Diff 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)
You can’t perform that action at this time.
0 commit comments