mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
feat(web-search): enable DashScope provider only for Qwen OAuth auth type
This commit is contained in:
@@ -17,6 +17,7 @@ import { ToolErrorType } from '../tool-error.js';
|
|||||||
|
|
||||||
import type { Config } from '../../config/config.js';
|
import type { Config } from '../../config/config.js';
|
||||||
import { ApprovalMode } from '../../config/config.js';
|
import { ApprovalMode } from '../../config/config.js';
|
||||||
|
import { AuthType } from '../../core/contentGenerator.js';
|
||||||
import { getErrorMessage } from '../../utils/errors.js';
|
import { getErrorMessage } from '../../utils/errors.js';
|
||||||
import { buildContentWithSources } from './utils.js';
|
import { buildContentWithSources } from './utils.js';
|
||||||
import { TavilyProvider } from './providers/tavily-provider.js';
|
import { TavilyProvider } from './providers/tavily-provider.js';
|
||||||
@@ -28,6 +29,7 @@ import type {
|
|||||||
WebSearchProvider,
|
WebSearchProvider,
|
||||||
WebSearchResultItem,
|
WebSearchResultItem,
|
||||||
WebSearchProviderConfig,
|
WebSearchProviderConfig,
|
||||||
|
DashScopeProviderConfig,
|
||||||
} from './types.js';
|
} from './types.js';
|
||||||
|
|
||||||
class WebSearchToolInvocation extends BaseToolInvocation<
|
class WebSearchToolInvocation extends BaseToolInvocation<
|
||||||
@@ -43,8 +45,15 @@ class WebSearchToolInvocation extends BaseToolInvocation<
|
|||||||
|
|
||||||
override getDescription(): string {
|
override getDescription(): string {
|
||||||
const webSearchConfig = this.config.getWebSearchConfig();
|
const webSearchConfig = this.config.getWebSearchConfig();
|
||||||
const provider =
|
const authType = this.config.getAuthType();
|
||||||
this.params.provider || webSearchConfig?.default || 'tavily';
|
let defaultProvider = webSearchConfig?.default;
|
||||||
|
|
||||||
|
// If auth type is QWEN_OAUTH, prefer dashscope as default
|
||||||
|
if (authType === AuthType.QWEN_OAUTH && !defaultProvider) {
|
||||||
|
defaultProvider = 'dashscope';
|
||||||
|
}
|
||||||
|
|
||||||
|
const provider = this.params.provider || defaultProvider;
|
||||||
return ` (Searching the web via ${provider})`;
|
return ` (Searching the web via ${provider})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,8 +86,15 @@ class WebSearchToolInvocation extends BaseToolInvocation<
|
|||||||
return new TavilyProvider(config);
|
return new TavilyProvider(config);
|
||||||
case 'google':
|
case 'google':
|
||||||
return new GoogleProvider(config);
|
return new GoogleProvider(config);
|
||||||
case 'dashscope':
|
case 'dashscope': {
|
||||||
return new DashScopeProvider(config);
|
// Pass auth type to DashScope provider for availability check
|
||||||
|
const authType = this.config.getAuthType();
|
||||||
|
const dashscopeConfig: DashScopeProviderConfig = {
|
||||||
|
...config,
|
||||||
|
authType: authType as string | undefined,
|
||||||
|
};
|
||||||
|
return new DashScopeProvider(dashscopeConfig);
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
throw new Error('Unknown provider type');
|
throw new Error('Unknown provider type');
|
||||||
}
|
}
|
||||||
@@ -284,7 +300,7 @@ export class WebSearchTool extends BaseDeclarativeTool<
|
|||||||
provider: {
|
provider: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description:
|
description:
|
||||||
'Optional provider to use for the search (e.g., "tavily", "google", "dashscope"). If not specified, the default provider will be used.',
|
'Optional provider to use for the search (e.g., "tavily", "google", "dashscope"). IMPORTANT: Only specify this parameter if you explicitly know which provider to use. Otherwise, omit this parameter entirely and let the system automatically select the appropriate provider based on availability and configuration. The system will choose the best available provider automatically.',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
required: ['query'],
|
required: ['query'],
|
||||||
|
|||||||
@@ -93,8 +93,9 @@ export class DashScopeProvider extends BaseWebSearchProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isAvailable(): boolean {
|
isAvailable(): boolean {
|
||||||
return true;
|
// DashScope provider is only available when auth type is QWEN_OAUTH
|
||||||
// return !!(this.config.apiKey && this.config.uid && this.config.appId);
|
// This ensures it's only used when OAuth credentials are available
|
||||||
|
return this.config.authType === 'qwen-oauth';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -138,6 +138,12 @@ export interface DashScopeProviderConfig {
|
|||||||
maxResults?: number;
|
maxResults?: number;
|
||||||
scene?: string;
|
scene?: string;
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
|
/**
|
||||||
|
* Optional auth type to determine provider availability.
|
||||||
|
* If set to 'qwen-oauth', the provider will be available.
|
||||||
|
* If set to other values or undefined, the provider will check auth type dynamically.
|
||||||
|
*/
|
||||||
|
authType?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user