forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserPreferenceChatGPTConfiguration.swift
More file actions
59 lines (47 loc) · 1.64 KB
/
UserPreferenceChatGPTConfiguration.swift
File metadata and controls
59 lines (47 loc) · 1.64 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import AIModel
import ChatBasic
import Foundation
import Keychain
import Preferences
public struct UserPreferenceChatGPTConfiguration: ChatGPTConfiguration {
public var chatModelKey: KeyPath<UserDefaultPreferenceKeys, PreferenceKey<String>>?
public var temperature: Double {
min(max(0, UserDefaults.shared.value(for: \.chatGPTTemperature)), 2)
}
public var model: ChatModel? {
let models = UserDefaults.shared.value(for: \.chatModels)
if let chatModelKey {
let id = UserDefaults.shared.value(for: chatModelKey)
if id == "com.github.copilot" {
return .init(id: id, name: "GitHub Copilot", format: .openAI, info: .init())
}
if let model = models.first(where: { $0.id == id }) {
return model
}
}
let id = UserDefaults.shared.value(for: \.defaultChatFeatureChatModelId)
if id == "com.github.copilot", chatModelKey != \.preferredChatModelIdForUtilities {
return .init(id: id, name: "GitHub Copilot", format: .openAI, info: .init())
}
return models.first { $0.id == id }
?? models.first
}
public var maxTokens: Int {
model?.info.maxTokens ?? 0
}
public var stop: [String] {
[]
}
public var minimumReplyTokens: Int {
maxTokens / 5
}
public var runFunctionsAutomatically: Bool {
true
}
public var shouldEndTextWindow: (String) -> Bool {
{ _ in true }
}
public init(chatModelKey: KeyPath<UserDefaultPreferenceKeys, PreferenceKey<String>>? = nil) {
self.chatModelKey = chatModelKey
}
}