File tree Expand file tree Collapse file tree 4 files changed +13
-5
lines changed
Expand file tree Collapse file tree 4 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -6,12 +6,20 @@ import XcodeInspector
66public struct ActiveDocumentChatContextCollector : ChatContextCollector {
77 public init ( ) { }
88
9- public func generateSystemPrompt( oldMessages : [ String ] ) -> String {
9+ public func generateSystemPrompt( history : [ String ] , content prompt : String ) -> String {
1010 let content = getEditorInformation ( )
1111 let relativePath = content. documentURL. path
1212 . replacingOccurrences ( of: content. projectURL. path, with: " " )
1313 let selectionRange = content. editorContent? . selections. first ?? . outOfScope
1414 let editorContent = {
15+ if prompt. hasPrefix ( " @file " ) {
16+ return """
17+ File Content:``` \( content. language. rawValue)
18+ \( content. editorContent? . content ?? " " )
19+ ```
20+ """
21+ }
22+
1523 if selectionRange. start == selectionRange. end,
1624 UserDefaults . shared. value ( for: \. embedFileContentInChatContextIfNoSelection)
1725 {
Original file line number Diff line number Diff line change 11import Foundation
22
33public protocol ChatContextCollector {
4- func generateSystemPrompt( oldMessages : [ String ] ) -> String
4+ func generateSystemPrompt( history : [ String ] , content : String ) -> String
55}
Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ public final class ChatService: ObservableObject {
4747 try await contextController. updatePromptToMatchContent ( systemPrompt: """
4848 \( systemPrompt)
4949 \( extraSystemPrompt)
50- """ )
50+ """ , content : content )
5151
5252 _ = try await chatGPTService. send ( content: content, summary: nil )
5353 }
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ final class DynamicContextController {
1313 self . contextCollectors = contextCollectors
1414 }
1515
16- func updatePromptToMatchContent( systemPrompt: String ) async throws {
16+ func updatePromptToMatchContent( systemPrompt: String , content : String ) async throws {
1717 let language = UserDefaults . shared. value ( for: \. chatGPTLanguage)
1818 let oldMessages = ( await chatGPTService. history) . map ( \. content)
1919 let contextualSystemPrompt = """
@@ -22,7 +22,7 @@ final class DynamicContextController {
2222
2323 \(
2424 contextCollectors
25- . map { $0. generateSystemPrompt ( oldMessages : oldMessages) }
25+ . map { $0. generateSystemPrompt ( history : oldMessages, content : content ) }
2626 . joined ( separator: " \n " )
2727 )
2828 """
You can’t perform that action at this time.
0 commit comments