mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
feat(cli): add pro model availability check and fallback to flash (#608)
This commit is contained in:
@@ -19,6 +19,10 @@ import {
|
||||
} from '@gemini-code/core';
|
||||
import { Settings } from './settings.js';
|
||||
import { readPackageUp } from 'read-package-up';
|
||||
import {
|
||||
getEffectiveModel,
|
||||
type EffectiveModelCheckResult,
|
||||
} from '../utils/modelCheck.js';
|
||||
|
||||
// Simple console logger for now - replace with actual logger if available
|
||||
const logger = {
|
||||
@@ -30,7 +34,8 @@ const logger = {
|
||||
error: (...args: any[]) => console.error('[ERROR]', ...args),
|
||||
};
|
||||
|
||||
const DEFAULT_GEMINI_MODEL = 'gemini-2.5-pro-preview-05-06';
|
||||
export const DEFAULT_GEMINI_MODEL = 'gemini-2.5-pro-preview-05-06';
|
||||
export const DEFAULT_GEMINI_FLASH_MODEL = 'gemini-2.5-flash-preview-05-20';
|
||||
|
||||
interface CliArgs {
|
||||
model: string | undefined;
|
||||
@@ -114,7 +119,16 @@ export async function loadHierarchicalGeminiMemory(
|
||||
return loadServerHierarchicalMemory(currentWorkingDirectory, debugMode);
|
||||
}
|
||||
|
||||
export async function loadCliConfig(settings: Settings): Promise<Config> {
|
||||
export interface LoadCliConfigResult {
|
||||
config: Config;
|
||||
modelWasSwitched: boolean;
|
||||
originalModelBeforeSwitch?: string;
|
||||
finalModel: string;
|
||||
}
|
||||
|
||||
export async function loadCliConfig(
|
||||
settings: Settings,
|
||||
): Promise<LoadCliConfigResult> {
|
||||
loadEnvironment();
|
||||
|
||||
const geminiApiKey = process.env.GEMINI_API_KEY;
|
||||
@@ -164,9 +178,27 @@ export async function loadCliConfig(settings: Settings): Promise<Config> {
|
||||
const apiKeyForServer = geminiApiKey || googleApiKey || '';
|
||||
const useVertexAI = hasGeminiApiKey ? false : undefined;
|
||||
|
||||
let modelToUse = argv.model || DEFAULT_GEMINI_MODEL;
|
||||
let modelSwitched = false;
|
||||
let originalModel: string | undefined = undefined;
|
||||
|
||||
if (apiKeyForServer) {
|
||||
const checkResult: EffectiveModelCheckResult = await getEffectiveModel(
|
||||
apiKeyForServer,
|
||||
modelToUse,
|
||||
);
|
||||
if (checkResult.switched) {
|
||||
modelSwitched = true;
|
||||
originalModel = checkResult.originalModelIfSwitched;
|
||||
modelToUse = checkResult.effectiveModel;
|
||||
}
|
||||
} else {
|
||||
// logger.debug('API key not available during config load. Skipping model availability check.');
|
||||
}
|
||||
|
||||
const configParams: ConfigParameters = {
|
||||
apiKey: apiKeyForServer,
|
||||
model: argv.model || DEFAULT_GEMINI_MODEL,
|
||||
model: modelToUse,
|
||||
sandbox: argv.sandbox ?? settings.sandbox ?? argv.yolo ?? false,
|
||||
targetDir: process.cwd(),
|
||||
debugMode,
|
||||
@@ -186,7 +218,13 @@ export async function loadCliConfig(settings: Settings): Promise<Config> {
|
||||
argv.show_memory_usage || settings.showMemoryUsage || false,
|
||||
};
|
||||
|
||||
return createServerConfig(configParams);
|
||||
const config = createServerConfig(configParams);
|
||||
return {
|
||||
config,
|
||||
modelWasSwitched: modelSwitched,
|
||||
originalModelBeforeSwitch: originalModel,
|
||||
finalModel: modelToUse,
|
||||
};
|
||||
}
|
||||
|
||||
async function createUserAgent(): Promise<string> {
|
||||
|
||||
Reference in New Issue
Block a user