mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 08:47:44 +00:00
feat: openApi configurable window (#1019)
This commit is contained in:
@@ -78,20 +78,17 @@ export function AuthDialog({
|
|||||||
);
|
);
|
||||||
|
|
||||||
const handleAuthSelect = (authMethod: AuthType) => {
|
const handleAuthSelect = (authMethod: AuthType) => {
|
||||||
const error = validateAuthMethod(authMethod);
|
if (authMethod === AuthType.USE_OPENAI) {
|
||||||
if (error) {
|
setShowOpenAIKeyPrompt(true);
|
||||||
if (
|
|
||||||
authMethod === AuthType.USE_OPENAI &&
|
|
||||||
!process.env['OPENAI_API_KEY']
|
|
||||||
) {
|
|
||||||
setShowOpenAIKeyPrompt(true);
|
|
||||||
setErrorMessage(null);
|
|
||||||
} else {
|
|
||||||
setErrorMessage(error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
setErrorMessage(null);
|
setErrorMessage(null);
|
||||||
onSelect(authMethod, SettingScope.User);
|
} else {
|
||||||
|
const error = validateAuthMethod(authMethod);
|
||||||
|
if (error) {
|
||||||
|
setErrorMessage(error);
|
||||||
|
} else {
|
||||||
|
setErrorMessage(null);
|
||||||
|
onSelect(authMethod, SettingScope.User);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -137,10 +134,23 @@ export function AuthDialog({
|
|||||||
},
|
},
|
||||||
{ isActive: true },
|
{ isActive: true },
|
||||||
);
|
);
|
||||||
|
const getDefaultOpenAIConfig = () => {
|
||||||
|
const fromSettings = settings.merged.security?.auth;
|
||||||
|
const modelSettings = settings.merged.model;
|
||||||
|
return {
|
||||||
|
apiKey: fromSettings?.apiKey || process.env['OPENAI_API_KEY'] || '',
|
||||||
|
baseUrl: fromSettings?.baseUrl || process.env['OPENAI_BASE_URL'] || '',
|
||||||
|
model: modelSettings?.name || process.env['OPENAI_MODEL'] || '',
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
if (showOpenAIKeyPrompt) {
|
if (showOpenAIKeyPrompt) {
|
||||||
|
const defaults = getDefaultOpenAIConfig();
|
||||||
return (
|
return (
|
||||||
<OpenAIKeyPrompt
|
<OpenAIKeyPrompt
|
||||||
|
defaultApiKey={defaults.apiKey}
|
||||||
|
defaultBaseUrl={defaults.baseUrl}
|
||||||
|
defaultModel={defaults.model}
|
||||||
onSubmit={handleOpenAIKeySubmit}
|
onSubmit={handleOpenAIKeySubmit}
|
||||||
onCancel={handleOpenAIKeyCancel}
|
onCancel={handleOpenAIKeyCancel}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -13,15 +13,21 @@ import { useKeypress } from '../hooks/useKeypress.js';
|
|||||||
interface OpenAIKeyPromptProps {
|
interface OpenAIKeyPromptProps {
|
||||||
onSubmit: (apiKey: string, baseUrl: string, model: string) => void;
|
onSubmit: (apiKey: string, baseUrl: string, model: string) => void;
|
||||||
onCancel: () => void;
|
onCancel: () => void;
|
||||||
|
defaultApiKey?: string;
|
||||||
|
defaultBaseUrl?: string;
|
||||||
|
defaultModel?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function OpenAIKeyPrompt({
|
export function OpenAIKeyPrompt({
|
||||||
onSubmit,
|
onSubmit,
|
||||||
onCancel,
|
onCancel,
|
||||||
|
defaultApiKey,
|
||||||
|
defaultBaseUrl,
|
||||||
|
defaultModel,
|
||||||
}: OpenAIKeyPromptProps): React.JSX.Element {
|
}: OpenAIKeyPromptProps): React.JSX.Element {
|
||||||
const [apiKey, setApiKey] = useState('');
|
const [apiKey, setApiKey] = useState(defaultApiKey || '');
|
||||||
const [baseUrl, setBaseUrl] = useState('');
|
const [baseUrl, setBaseUrl] = useState(defaultBaseUrl || '');
|
||||||
const [model, setModel] = useState('');
|
const [model, setModel] = useState(defaultModel || '');
|
||||||
const [currentField, setCurrentField] = useState<
|
const [currentField, setCurrentField] = useState<
|
||||||
'apiKey' | 'baseUrl' | 'model'
|
'apiKey' | 'baseUrl' | 'model'
|
||||||
>('apiKey');
|
>('apiKey');
|
||||||
|
|||||||
Reference in New Issue
Block a user