Skip to content

Commit a2edca4

Browse files
committed
Add utility chat model
1 parent 096569f commit a2edca4

6 files changed

Lines changed: 41 additions & 5 deletions

File tree

Core/Sources/HostApp/FeatureSettings/Chat/ChatSettingsGeneralSectionView.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct ChatSettingsGeneralSectionView: View {
1616
@AppStorage(\.chatCodeFont) var chatCodeFont
1717

1818
@AppStorage(\.defaultChatFeatureChatModelId) var defaultChatFeatureChatModelId
19+
@AppStorage(\.preferredChatModelIdForUtilities) var utilityChatModelId
1920
@AppStorage(\.defaultChatSystemPrompt) var defaultChatSystemPrompt
2021
@AppStorage(\.chatSearchPluginMaxIterations) var chatSearchPluginMaxIterations
2122
@AppStorage(\.defaultChatFeatureEmbeddingModelId) var defaultChatFeatureEmbeddingModelId
@@ -119,6 +120,27 @@ struct ChatSettingsGeneralSectionView: View {
119120
}
120121
}
121122

123+
Picker(
124+
"Utility chat model",
125+
selection: $settings.utilityChatModelId
126+
) {
127+
Text("Use the default model").tag("")
128+
129+
if !settings.chatModels.contains(where: { $0.id == settings.utilityChatModelId }),
130+
!settings.utilityChatModelId.isEmpty
131+
{
132+
Text(
133+
(settings.chatModels.first?.name).map { "\($0) (Default)" }
134+
?? "No Model Found"
135+
)
136+
.tag(settings.utilityChatModelId)
137+
}
138+
139+
ForEach(settings.chatModels, id: \.id) { chatModel in
140+
Text(chatModel.name).tag(chatModel.id)
141+
}
142+
}
143+
122144
Picker(
123145
"Embedding model",
124146
selection: $settings.defaultChatFeatureEmbeddingModelId

Pro

Submodule Pro updated from d1df4fa to 406c851

Tool/Sources/LangChain/Chains/CombineAnswersChain.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Foundation
22
import Logger
33
import OpenAIService
4+
import Preferences
45

56
public class CombineAnswersChain: Chain {
67
public struct Input: Decodable {
@@ -16,7 +17,8 @@ public class CombineAnswersChain: Chain {
1617
public let chatModelChain: ChatModelChain<Input>
1718

1819
public init(
19-
configuration: ChatGPTConfiguration = UserPreferenceChatGPTConfiguration(),
20+
configuration: ChatGPTConfiguration =
21+
UserPreferenceChatGPTConfiguration(chatModelKey: \.preferredChatModelIdForUtilities),
2022
extraInstructions: String = ""
2123
) {
2224
chatModelChain = .init(

Tool/Sources/LangChain/Chains/RefineDocumentChain.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import ChatBasic
12
import Foundation
23
import OpenAIService
3-
import ChatBasic
4+
import Preferences
45

56
public final class RefineDocumentChain: Chain {
67
public struct Input {
@@ -76,7 +77,10 @@ public final class RefineDocumentChain: Chain {
7677
func buildChatModel() -> ChatModelChain<RefinementInput> {
7778
.init(
7879
chatModel: OpenAIChat(
79-
configuration: UserPreferenceChatGPTConfiguration().overriding {
80+
configuration: UserPreferenceChatGPTConfiguration(
81+
chatModelKey: \.preferredChatModelIdForUtilities
82+
)
83+
.overriding {
8084
$0.temperature = 0
8185
$0.runFunctionsAutomatically = false
8286
},

Tool/Sources/LangChain/Chains/RelevantInformationExtractionChain.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import ChatBasic
22
import Foundation
33
import OpenAIService
4+
import Preferences
45

56
public final class RelevantInformationExtractionChain: Chain {
67
public struct Input {
@@ -52,7 +53,10 @@ public final class RelevantInformationExtractionChain: Chain {
5253
func buildChatModel() -> ChatModelChain<TaskInput> {
5354
.init(
5455
chatModel: OpenAIChat(
55-
configuration: UserPreferenceChatGPTConfiguration().overriding {
56+
configuration: UserPreferenceChatGPTConfiguration(
57+
chatModelKey: \.preferredChatModelIdForUtilities
58+
)
59+
.overriding {
5660
$0.temperature = 0.5
5761
$0.runFunctionsAutomatically = false
5862
},

Tool/Sources/Preferences/Keys.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,10 @@ public extension UserDefaultPreferenceKeys {
505505
var preferredChatModelIdForWebScope: PreferenceKey<String> {
506506
.init(defaultValue: "", key: "PreferredChatModelIdForWebScope")
507507
}
508+
509+
var preferredChatModelIdForUtilities: PreferenceKey<String> {
510+
.init(defaultValue: "", key: "PreferredChatModelIdForUtilities")
511+
}
508512

509513
var disableFloatOnTopWhenTheChatPanelIsDetached: PreferenceKey<Bool> {
510514
.init(defaultValue: true, key: "DisableFloatOnTopWhenTheChatPanelIsDetached")

0 commit comments

Comments
 (0)