Skip to content

Commit f4c7e05

Browse files
committed
Support setting max search iteration
1 parent 77fa566 commit f4c7e05

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

Core/Sources/ChatPlugins/SearchChatPlugin/SearchQuery.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func search(_ query: String) async throws
4747
let agentExecutor = AgentExecutor(
4848
agent: ChatAgent(chatModel: chatModel, tools: tools),
4949
tools: tools,
50-
maxIteration: 2,
50+
maxIteration: UserDefaults.shared.value(for: \.chatSearchPluginMaxIterations),
5151
earlyStopHandleType: .generate
5252
)
5353

Core/Sources/HostApp/FeatureSettings/ChatSettingsView.swift

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct ChatSettingsView: View {
2020
@AppStorage(\.chatFeatureProvider) var chatFeatureProvider
2121
@AppStorage(\.chatGPTModel) var chatGPTModel
2222
@AppStorage(\.defaultChatSystemPrompt) var defaultChatSystemPrompt
23+
@AppStorage(\.chatSearchPluginMaxIterations) var chatSearchPluginMaxIterations
2324

2425
init() {}
2526
}
@@ -36,6 +37,8 @@ struct ChatSettingsView: View {
3637
uiForm
3738
Divider()
3839
contextForm
40+
Divider()
41+
pluginForm
3942
}
4043
}
4144

@@ -123,7 +126,7 @@ struct ChatSettingsView: View {
123126
Text("9 Messages").tag(9)
124127
Text("11 Messages").tag(11)
125128
}
126-
129+
127130
VStack(alignment: .leading, spacing: 4) {
128131
Text("Default System Prompt")
129132
EditableText(text: $settings.defaultChatSystemPrompt)
@@ -178,7 +181,7 @@ struct ChatSettingsView: View {
178181
Toggle(isOn: $settings.useSelectionScopeByDefaultInChatContext) {
179182
Text("Use selection scope by default in chat context.")
180183
}
181-
184+
182185
Toggle(isOn: $settings.embedFileContentInChatContextIfNoSelection) {
183186
Text("Embed file content in chat context if no code is selected.")
184187
}
@@ -198,6 +201,20 @@ struct ChatSettingsView: View {
198201
}
199202
}
200203

204+
@ViewBuilder
205+
var pluginForm: some View {
206+
Form {
207+
TextField(text: .init(get: {
208+
"\(Int(settings.chatSearchPluginMaxIterations))"
209+
}, set: {
210+
settings.chatSearchPluginMaxIterations = Int($0) ?? 0
211+
})) {
212+
Text("Search Plugin Max Iterations")
213+
}
214+
.textFieldStyle(.roundedBorder)
215+
}
216+
}
217+
201218
var languagePicker: some View {
202219
Menu {
203220
if !settings.chatGPTLanguage.isEmpty,

Tool/Sources/Preferences/Keys.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ public extension UserDefaultPreferenceKeys {
245245
key: "DefaultChatSystemPrompt"
246246
)
247247
}
248+
249+
var chatSearchPluginMaxIterations: PreferenceKey<Int> {
250+
.init(defaultValue: 3, key: "ChatSearchPluginMaxIterations")
251+
}
248252
}
249253

250254
// MARK: - Bing Search

0 commit comments

Comments
 (0)