mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-01-10 10:59:14 +00:00
* refactor: openaiContentGenerator * refactor: optimize stream handling * refactor: re-organize refactored files * fix: unit test cases * feat: `/model` command for switching to vision model * fix: lint error * feat: add image tokenizer to fit vlm context window * fix: lint and type errors * feat: add `visionModelPreview` to control default visibility of vision models * fix: remove deprecated files * fix: align supported image formats with bailian doc
89 lines
2.2 KiB
TypeScript
89 lines
2.2 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2025 Qwen
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
import { AuthType } from '@qwen-code/qwen-code-core';
|
|
import type {
|
|
SlashCommand,
|
|
CommandContext,
|
|
OpenDialogActionReturn,
|
|
MessageActionReturn,
|
|
} from './types.js';
|
|
import { CommandKind } from './types.js';
|
|
import {
|
|
AVAILABLE_MODELS_QWEN,
|
|
getOpenAIAvailableModelFromEnv,
|
|
type AvailableModel,
|
|
} from '../models/availableModels.js';
|
|
|
|
function getAvailableModelsForAuthType(authType: AuthType): AvailableModel[] {
|
|
switch (authType) {
|
|
case AuthType.QWEN_OAUTH:
|
|
return AVAILABLE_MODELS_QWEN;
|
|
case AuthType.USE_OPENAI: {
|
|
const openAIModel = getOpenAIAvailableModelFromEnv();
|
|
return openAIModel ? [openAIModel] : [];
|
|
}
|
|
default:
|
|
// For other auth types, return empty array for now
|
|
// This can be expanded later according to the design doc
|
|
return [];
|
|
}
|
|
}
|
|
|
|
export const modelCommand: SlashCommand = {
|
|
name: 'model',
|
|
description: 'Switch the model for this session',
|
|
kind: CommandKind.BUILT_IN,
|
|
action: async (
|
|
context: CommandContext,
|
|
): Promise<OpenDialogActionReturn | MessageActionReturn> => {
|
|
const { services } = context;
|
|
const { config } = services;
|
|
|
|
if (!config) {
|
|
return {
|
|
type: 'message',
|
|
messageType: 'error',
|
|
content: 'Configuration not available.',
|
|
};
|
|
}
|
|
|
|
const contentGeneratorConfig = config.getContentGeneratorConfig();
|
|
if (!contentGeneratorConfig) {
|
|
return {
|
|
type: 'message',
|
|
messageType: 'error',
|
|
content: 'Content generator configuration not available.',
|
|
};
|
|
}
|
|
|
|
const authType = contentGeneratorConfig.authType;
|
|
if (!authType) {
|
|
return {
|
|
type: 'message',
|
|
messageType: 'error',
|
|
content: 'Authentication type not available.',
|
|
};
|
|
}
|
|
|
|
const availableModels = getAvailableModelsForAuthType(authType);
|
|
|
|
if (availableModels.length === 0) {
|
|
return {
|
|
type: 'message',
|
|
messageType: 'error',
|
|
content: `No models available for the current authentication type (${authType}).`,
|
|
};
|
|
}
|
|
|
|
// Trigger model selection dialog
|
|
return {
|
|
type: 'dialog',
|
|
dialog: 'model',
|
|
};
|
|
},
|
|
};
|