Add DashScope ASR model support and enhance related components

- Introduced DashScope as a new ASR model in the database initialization.
- Updated ASRModel schema to include vendor information.
- Enhanced ASR router to support DashScope-specific functionality, including connection testing and preview capabilities.
- Modified frontend components to accommodate DashScope as a selectable vendor with appropriate default settings.
- Added tests to validate DashScope ASR model creation, updates, and connectivity.
- Updated backend API to handle DashScope-specific base URLs and vendor normalization.
This commit is contained in:
Xin Wang
2026-03-09 07:37:00 +08:00
parent e41d34fe23
commit bfe165daae
6 changed files with 638 additions and 21 deletions

View File

@@ -3,6 +3,8 @@ import { apiRequest, getApiBaseUrl } from './apiClient';
type AnyRecord = Record<string, any>;
const DEFAULT_LIST_LIMIT = 1000;
const OPENAI_COMPATIBLE_DEFAULT_ASR_BASE_URL = 'https://api.siliconflow.cn/v1';
const DASHSCOPE_DEFAULT_ASR_BASE_URL = 'wss://dashscope.aliyuncs.com/api-ws/v1/realtime';
const TOOL_ID_ALIASES: Record<string, string> = {
voice_message_prompt: 'voice_msg_prompt',
};
@@ -129,7 +131,16 @@ const mapVoice = (raw: AnyRecord): Voice => ({
const mapASRModel = (raw: AnyRecord): ASRModel => ({
id: String(readField(raw, ['id'], '')),
name: readField(raw, ['name'], ''),
vendor: readField(raw, ['vendor'], 'OpenAI Compatible'),
vendor: (() => {
const vendor = String(readField(raw, ['vendor'], '')).trim().toLowerCase();
if (vendor === 'dashscope') {
return 'DashScope';
}
if (vendor === 'siliconflow' || vendor === 'openai compatible' || vendor === 'openai-compatible' || vendor === '硅基流动') {
return 'OpenAI Compatible';
}
return String(readField(raw, ['vendor'], 'OpenAI Compatible')) || 'OpenAI Compatible';
})(),
language: readField(raw, ['language'], 'zh'),
baseUrl: readField(raw, ['baseUrl', 'base_url'], ''),
apiKey: readField(raw, ['apiKey', 'api_key'], ''),
@@ -457,11 +468,16 @@ export const fetchASRModels = async (): Promise<ASRModel[]> => {
};
export const createASRModel = async (data: Partial<ASRModel>): Promise<ASRModel> => {
const vendor = data.vendor || 'OpenAI Compatible';
const normalizedVendor = String(vendor).trim().toLowerCase();
const defaultBaseUrl = normalizedVendor === 'dashscope'
? DASHSCOPE_DEFAULT_ASR_BASE_URL
: OPENAI_COMPATIBLE_DEFAULT_ASR_BASE_URL;
const payload = {
name: data.name || 'New ASR Model',
vendor: data.vendor || 'OpenAI Compatible',
vendor,
language: data.language || 'zh',
base_url: data.baseUrl || 'https://api.siliconflow.cn/v1',
base_url: data.baseUrl || defaultBaseUrl,
api_key: data.apiKey || '',
model_name: data.modelName || undefined,
hotwords: data.hotwords || [],