forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamicContextController.swift
More file actions
32 lines (27 loc) · 1.07 KB
/
DynamicContextController.swift
File metadata and controls
32 lines (27 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import ChatContextCollector
import Foundation
import OpenAIService
import Preferences
import XcodeInspector
final class DynamicContextController {
let chatGPTService: any ChatGPTServiceType
let contextCollectors: [ChatContextCollector]
init(chatGPTService: any ChatGPTServiceType, contextCollectors: ChatContextCollector...) {
self.chatGPTService = chatGPTService
self.contextCollectors = contextCollectors
}
func updatePromptToMatchContent(systemPrompt: String, content: String) async throws {
let language = UserDefaults.shared.value(for: \.chatGPTLanguage)
let oldMessages = (await chatGPTService.history).map(\.content)
let contextualSystemPrompt = """
\(language.isEmpty ? "" : "You must always reply in \(language)")
\(systemPrompt)
\(
contextCollectors
.map { $0.generateSystemPrompt(history: oldMessages, content: content) }
.joined(separator: "\n")
)
"""
await chatGPTService.mutateSystemPrompt(contextualSystemPrompt)
}
}