Skip to content

Commit 5ef37ab

Browse files
committed
Merge branch 'feature/new-way-to-setup-models' into develop
2 parents b639bbc + 95b5b84 commit 5ef37ab

60 files changed

Lines changed: 3401 additions & 584 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Copilot for Xcode.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Core/Package.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ let package = Package(
5050
url: "https://github.com/pointfreeco/swift-composable-architecture",
5151
from: "0.55.0"
5252
),
53-
.package(url: "https://github.com/apple/swift-syntax.git", branch: "main"),
5453
].pro,
5554
targets: [
5655
// MARK: - Main
@@ -261,6 +260,13 @@ let package = Package(
261260
dependencies: [
262261
"GitHubCopilotService",
263262
.product(name: "Preferences", package: "Tool"),
263+
.product(name: "Keychain", package: "Tool"),
264+
]
265+
),
266+
.testTarget(
267+
name: "ServiceUpdateMigrationTests",
268+
dependencies: [
269+
"ServiceUpdateMigration",
264270
]
265271
),
266272
.target(

Core/Sources/ChatContextCollector/ChatContextCollector.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public protocol ChatContextCollector {
1414
func generateContext(
1515
history: [ChatMessage],
1616
scopes: Set<String>,
17-
content: String
17+
content: String,
18+
configuration: ChatGPTConfiguration
1819
) -> ChatContext?
1920
}
2021

Core/Sources/ChatContextCollectors/ActiveDocumentChatContextCollector/ActiveDocumentChatContextCollector.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public final class ActiveDocumentChatContextCollector: ChatContextCollector {
1515
public func generateContext(
1616
history: [ChatMessage],
1717
scopes: Set<String>,
18-
content: String
18+
content: String,
19+
configuration: ChatGPTConfiguration
1920
) -> ChatContext? {
2021
guard let info = getEditorInformation() else { return nil }
2122
let context = getActiveDocumentContext(info)

Core/Sources/ChatContextCollectors/ActiveDocumentChatContextCollector/LegacyActiveDocumentChatContextCollector.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ public struct LegacyActiveDocumentChatContextCollector: ChatContextCollector {
1111
public func generateContext(
1212
history: [ChatMessage],
1313
scopes: Set<String>,
14-
content: String
14+
content: String,
15+
configuration: ChatGPTConfiguration
1516
) -> ChatContext? {
1617
guard let content = getEditorInformation() else { return nil }
1718
let relativePath = content.relativePath

Core/Sources/ChatContextCollectors/SystemInfoChatContextCollector/SystemInfoChatContextCollector.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public final class SystemInfoChatContextCollector: ChatContextCollector {
1414
public func generateContext(
1515
history: [ChatMessage],
1616
scopes: Set<String>,
17-
content: String
17+
content: String,
18+
configuration: ChatGPTConfiguration
1819
) -> ChatContext? {
1920
return .init(
2021
systemPrompt: """

Core/Sources/ChatContextCollectors/WebChatContextCollector/SearchFunction.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ struct SearchFunction: ChatGPTFunction {
2828
}.joined(separator: "\n")
2929
}
3030
}
31+
32+
let maxTokens: Int
3133

3234
var reportProgress: (String) async -> Void = { _ in }
3335

@@ -72,9 +74,10 @@ struct SearchFunction: ChatGPTFunction {
7274
subscriptionKey: UserDefaults.shared.value(for: \.bingSearchSubscriptionKey),
7375
searchURL: UserDefaults.shared.value(for: \.bingSearchEndpoint)
7476
)
77+
7578
let result = try await bingSearch.search(
7679
query: arguments.query,
77-
numberOfResult: UserDefaults.shared.value(for: \.chatGPTMaxToken) > 5000 ? 5 : 3,
80+
numberOfResult: maxTokens > 5000 ? 5 : 3,
7881
freshness: arguments.freshness
7982
)
8083

Core/Sources/ChatContextCollectors/WebChatContextCollector/WebChatContextCollector.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ public final class WebChatContextCollector: ChatContextCollector {
1010
public func generateContext(
1111
history: [ChatMessage],
1212
scopes: Set<String>,
13-
content: String
13+
content: String,
14+
configuration: ChatGPTConfiguration
1415
) -> ChatContext? {
1516
guard scopes.contains("web") || scopes.contains("w") else { return nil }
1617
let links = Self.detectLinks(from: history) + Self.detectLinks(from: content)
1718
let functions: [(any ChatGPTFunction)?] = [
18-
SearchFunction(),
19+
SearchFunction(maxTokens: configuration.maxTokens),
1920
// allow this function only when there is a link in the memory.
2021
links.isEmpty ? nil : QueryWebsiteFunction(),
2122
]

Core/Sources/ChatService/ContextAwareAutoManagedChatGPTMemory.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public final class ContextAwareAutoManagedChatGPTMemory: ChatGPTMemory {
3535
contextController = DynamicContextController(
3636
memory: memory,
3737
functionProvider: functionProvider,
38+
configuration: configuration,
3839
contextCollectors: allContextCollectors
3940
)
4041
self.functionProvider = functionProvider

Core/Sources/ChatService/DynamicContextController.swift

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

1415
convenience init(
1516
memory: AutoManagedChatGPTMemory,
1617
functionProvider: ChatFunctionProvider,
18+
configuration: ChatGPTConfiguration,
1719
contextCollectors: ChatContextCollector...
1820
) {
1921
self.init(
2022
memory: memory,
2123
functionProvider: functionProvider,
24+
configuration: configuration,
2225
contextCollectors: contextCollectors
2326
)
2427
}
2528

2629
init(
2730
memory: AutoManagedChatGPTMemory,
2831
functionProvider: ChatFunctionProvider,
32+
configuration: ChatGPTConfiguration,
2933
contextCollectors: [ChatContextCollector]
3034
) {
3135
self.memory = memory
3236
self.functionProvider = functionProvider
37+
self.configuration = configuration
3338
self.contextCollectors = contextCollectors
3439
}
3540

3641
func updatePromptToMatchContent(systemPrompt: String, content: String) async throws {
3742
var content = content
3843
var scopes = Self.parseScopes(&content)
3944
scopes.formUnion(defaultScopes)
40-
45+
4146
functionProvider.removeAll()
4247
let language = UserDefaults.shared.value(for: \.chatGPTLanguage)
4348
let oldMessages = await memory.history
4449
let contexts = contextCollectors.compactMap {
45-
$0.generateContext(history: oldMessages, scopes: scopes, content: content)
50+
$0.generateContext(
51+
history: oldMessages,
52+
scopes: scopes,
53+
content: content,
54+
configuration: configuration
55+
)
4656
}
4757
let contextualSystemPrompt = """
4858
\(language.isEmpty ? "" : "You must always reply in \(language)")

0 commit comments

Comments
 (0)