Skip to content

Commit 698a8e9

Browse files
authored
feat: DashScopeChatModel add EnableSearch, To use web search (#169)
1 parent eaf7ba1 commit 698a8e9

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

‎agentscope-core/src/main/java/io/agentscope/core/model/DashScopeChatModel.java‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public class DashScopeChatModel extends ChatModelBase {
6969
private final String modelName;
7070
private final boolean stream;
7171
private final Boolean enableThinking; // nullable
72+
private final Boolean enableSearch; // nullable
7273
private final GenerateOptions defaultOptions;
7374
private final String protocol; // HTTP or WEBSOCKET
7475
private final String baseUrl; // Optional custom base URL
@@ -105,6 +106,7 @@ private boolean requiresMultiModalConversationAPI() {
105106
* @param modelName the model name (e.g., "qwen-max", "qwen-vl-plus")
106107
* @param stream whether streaming should be enabled (ignored if enableThinking is true)
107108
* @param enableThinking whether thinking mode should be enabled (null for disabled)
109+
* @param enableSearch whether search enhancement should be enabled (null for disabled)
108110
* @param defaultOptions default generation options (null for defaults)
109111
* @param protocol the protocol to use ("HTTP" or "WEBSOCKET", null for HTTP)
110112
* @param baseUrl custom base URL for DashScope API (null for default)
@@ -115,6 +117,7 @@ public DashScopeChatModel(
115117
String modelName,
116118
boolean stream,
117119
Boolean enableThinking,
120+
Boolean enableSearch,
118121
GenerateOptions defaultOptions,
119122
String protocol,
120123
String baseUrl,
@@ -123,6 +126,7 @@ public DashScopeChatModel(
123126
this.modelName = modelName;
124127
this.stream = enableThinking != null && enableThinking ? true : stream;
125128
this.enableThinking = enableThinking;
129+
this.enableSearch = enableSearch;
126130
this.defaultOptions =
127131
defaultOptions != null ? defaultOptions : GenerateOptions.builder().build();
128132
this.protocol = protocol != null ? protocol : Protocol.HTTP.getValue();
@@ -431,6 +435,11 @@ private void applyModelSpecificOptions(
431435
param.setIncrementalOutput(Boolean.TRUE);
432436
}
433437
}
438+
439+
// Model-specific settings for search mode
440+
if (Boolean.TRUE.equals(enableSearch)) {
441+
param.setEnableSearch(Boolean.TRUE);
442+
}
434443
}
435444

436445
/**
@@ -638,6 +647,7 @@ public static class Builder {
638647
private String modelName;
639648
private boolean stream = true;
640649
private Boolean enableThinking;
650+
private Boolean enableSearch;
641651
private GenerateOptions defaultOptions = null;
642652
private String protocol = Protocol.HTTP.getValue();
643653
private String baseUrl;
@@ -699,6 +709,20 @@ public Builder enableThinking(Boolean enableThinking) {
699709
return this;
700710
}
701711

712+
/**
713+
* Sets whether search enhancement should be enabled.
714+
*
715+
* <p>When enabled, the model can access internet search to provide more up-to-date
716+
* and accurate responses.
717+
*
718+
* @param enableSearch true to enable search mode, false to disable, null for default (disabled)
719+
* @return this builder instance
720+
*/
721+
public Builder enableSearch(Boolean enableSearch) {
722+
this.enableSearch = enableSearch;
723+
return this;
724+
}
725+
702726
/**
703727
* Sets the default generation options.
704728
*
@@ -765,6 +789,7 @@ public DashScopeChatModel build() {
765789
modelName,
766790
stream,
767791
enableThinking,
792+
enableSearch,
768793
effectiveOptions,
769794
protocol,
770795
baseUrl,

‎agentscope-core/src/test/java/io/agentscope/core/model/DashScopeChatModelTest.java‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,28 @@ void testThinkingModeConfiguration() {
248248
assertNotNull(normalModel);
249249
}
250250

251+
@Test
252+
@DisplayName("Should handle search mode configuration")
253+
void testSearchModeConfiguration() {
254+
DashScopeChatModel searchEnabledModel =
255+
DashScopeChatModel.builder()
256+
.apiKey(mockApiKey)
257+
.modelName("qwen-plus")
258+
.enableSearch(true)
259+
.build();
260+
261+
assertNotNull(searchEnabledModel);
262+
263+
DashScopeChatModel searchDisabledModel =
264+
DashScopeChatModel.builder()
265+
.apiKey(mockApiKey)
266+
.modelName("qwen-plus")
267+
.enableSearch(false)
268+
.build();
269+
270+
assertNotNull(searchDisabledModel);
271+
}
272+
251273
@Test
252274
@DisplayName("Should create vision model with qwen-vl model name")
253275
void testVisionModelCreation() {

0 commit comments

Comments
 (0)