update model select
This commit is contained in:
parent
86c442d284
commit
57c3efdac3
@ -207,8 +207,11 @@ export default {
|
||||
// Models Section
|
||||
ApiProvider: {
|
||||
label: 'Api provider:',
|
||||
labelDescription: 'Select the LLM provider you want to use. Multiple providers can be configured, and API keys are securely stored locally',
|
||||
useCustomBaseUrl: 'Use custom base url',
|
||||
useCustomBaseUrlDescription: 'Use custom API endpoint URL for this provider',
|
||||
enterApiKey: 'Enter your api key',
|
||||
enterApiKeyDescription: 'API Key can be obtained from their official website{provider_api_url}',
|
||||
enterCustomUrl: 'Enter your custom api endpoint url',
|
||||
},
|
||||
Models: {
|
||||
|
||||
@ -208,14 +208,20 @@ export default {
|
||||
// 模型设置部分
|
||||
ApiProvider: {
|
||||
label: 'LLM 提供商:',
|
||||
labelDescription: '选择您想要使用的 LLM 提供商,支持配置多个提供商,API 密钥将安全保存在本地',
|
||||
useCustomBaseUrl: '使用自定义基础 URL',
|
||||
useCustomBaseUrlDescription: '为该提供商使用自定义的API端点URL',
|
||||
enterApiKey: '输入您的 API 密钥',
|
||||
enterApiKeyDescription: 'API Key 可以从官方网站{provider_api_url}获取',
|
||||
enterCustomUrl: '输入您的自定义 API 端点 URL',
|
||||
},
|
||||
Models: {
|
||||
chatModel: '聊天模型:',
|
||||
chatModelDescription: '用于日常对话和问答的模型,处理大部分聊天交互',
|
||||
autocompleteModel: '自动补全模型:',
|
||||
autocompleteModelDescription: '用于代码和文本自动补全的模型,提供智能写作建议',
|
||||
embeddingModel: '嵌入模型:',
|
||||
embeddingModelDescription: '用于文档向量化和语义搜索的模型,支持 RAG 功能',
|
||||
},
|
||||
|
||||
// 模型参数部分
|
||||
|
||||
@ -91,6 +91,7 @@ export const TextComponent: React.FC<TextComponentProps> = ({
|
||||
|
||||
export type ToggleComponentProps = {
|
||||
name: string;
|
||||
description?: string;
|
||||
value: boolean;
|
||||
onChange: (value: boolean) => void;
|
||||
disabled?: boolean;
|
||||
@ -98,19 +99,633 @@ export type ToggleComponentProps = {
|
||||
|
||||
export const ToggleComponent: React.FC<ToggleComponentProps> = ({
|
||||
name,
|
||||
description,
|
||||
value,
|
||||
onChange,
|
||||
disabled = false,
|
||||
}) => (
|
||||
<div className="infio-llm-setting-item">
|
||||
<label className={`switch ${disabled ? "disabled" : ""}`}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={value}
|
||||
onChange={(e) => onChange(e.target.checked)}
|
||||
disabled={disabled}
|
||||
/>
|
||||
<span className="infio-llm-setting-checkbox-name">{name}</span>
|
||||
</label>
|
||||
<div className="infio-toggle-setting-section">
|
||||
<div className="infio-toggle-info">
|
||||
<div className="infio-llm-setting-item-name">{name}</div>
|
||||
{description && <div className="infio-llm-setting-item-description">{description}</div>}
|
||||
</div>
|
||||
<label className={`infio-toggle-switch ${disabled ? "disabled" : ""}`}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={value}
|
||||
onChange={(e) => onChange(e.target.checked)}
|
||||
disabled={disabled}
|
||||
/>
|
||||
<span className="slider"></span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<style>{`
|
||||
.infio-toggle-setting-section {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
width: 100%;
|
||||
gap: var(--size-4-2);
|
||||
}
|
||||
|
||||
.infio-toggle-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
/* 开关样式 */
|
||||
.infio-toggle-switch {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
width: 44px;
|
||||
height: 24px;
|
||||
cursor: pointer;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.infio-toggle-switch.disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.infio-toggle-switch input {
|
||||
opacity: 0;
|
||||
width: 0;
|
||||
height: 0;
|
||||
}
|
||||
|
||||
.infio-toggle-switch .slider {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: var(--background-modifier-border);
|
||||
transition: all 0.2s ease-in-out;
|
||||
border-radius: 24px;
|
||||
border: 1px solid var(--background-modifier-border-hover);
|
||||
}
|
||||
|
||||
.infio-toggle-switch .slider:before {
|
||||
position: absolute;
|
||||
content: "";
|
||||
height: 18px;
|
||||
width: 18px;
|
||||
left: 2px;
|
||||
bottom: 2px;
|
||||
background-color: var(--text-on-accent);
|
||||
transition: all 0.2s ease-in-out;
|
||||
border-radius: 50%;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.infio-toggle-switch input:checked + .slider {
|
||||
background-color: var(--interactive-accent);
|
||||
border-color: var(--interactive-accent);
|
||||
}
|
||||
|
||||
.infio-toggle-switch input:checked + .slider:before {
|
||||
transform: translateX(20px);
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
.infio-toggle-switch:not(.disabled):hover .slider {
|
||||
box-shadow: 0 0 0 2px var(--interactive-accent-hover);
|
||||
}
|
||||
|
||||
.infio-toggle-switch input:focus + .slider {
|
||||
box-shadow: 0 0 0 2px var(--interactive-accent-hover);
|
||||
}
|
||||
|
||||
.infio-toggle-switch input:disabled + .slider {
|
||||
background-color: var(--background-modifier-border);
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.infio-toggle-switch input:disabled + .slider:before {
|
||||
background-color: var(--text-faint);
|
||||
}
|
||||
|
||||
/* 深色模式适配 */
|
||||
.theme-dark .infio-toggle-switch .slider:before {
|
||||
background-color: var(--text-normal);
|
||||
}
|
||||
|
||||
.theme-dark .infio-toggle-switch input:checked + .slider:before {
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
.theme-dark .infio-toggle-switch input:disabled + .slider:before {
|
||||
background-color: var(--text-faint);
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
|
||||
export type ApiKeyComponentProps = {
|
||||
name: React.ReactNode;
|
||||
description?: React.ReactNode;
|
||||
placeholder: string;
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
onTest?: () => Promise<void>;
|
||||
}
|
||||
|
||||
export const ApiKeyComponent: React.FC<ApiKeyComponentProps> = ({
|
||||
name,
|
||||
description,
|
||||
placeholder,
|
||||
value,
|
||||
onChange,
|
||||
onTest,
|
||||
}) => {
|
||||
const [localValue, setLocalValue] = useState(value);
|
||||
const [isVisible, setIsVisible] = useState(false);
|
||||
const [isTestingConnection, setIsTestingConnection] = useState(false);
|
||||
const [testResult, setTestResult] = useState<'success' | 'error' | null>(null);
|
||||
|
||||
// Update local value when prop value changes (e.g., provider change)
|
||||
useEffect(() => {
|
||||
setLocalValue(value);
|
||||
}, [value]);
|
||||
|
||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setLocalValue(e.target.value);
|
||||
// Clear test result when user changes the key
|
||||
setTestResult(null);
|
||||
};
|
||||
|
||||
const handleBlur = () => {
|
||||
if (localValue !== value) {
|
||||
onChange(localValue);
|
||||
}
|
||||
};
|
||||
|
||||
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.currentTarget.blur();
|
||||
}
|
||||
};
|
||||
|
||||
const toggleVisibility = () => {
|
||||
setIsVisible(!isVisible);
|
||||
};
|
||||
|
||||
const handleTest = async () => {
|
||||
if (!onTest || !localValue.trim()) return;
|
||||
|
||||
setIsTestingConnection(true);
|
||||
setTestResult(null);
|
||||
|
||||
try {
|
||||
await onTest();
|
||||
setTestResult('success');
|
||||
} catch (error) {
|
||||
setTestResult('error');
|
||||
} finally {
|
||||
setIsTestingConnection(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="infio-api-key-setting-item">
|
||||
<div className="infio-api-key-info">
|
||||
<div className="infio-api-key-name">{name}</div>
|
||||
{description && <div className="infio-api-key-description">{description}</div>}
|
||||
</div>
|
||||
<div className="infio-api-key-control-container">
|
||||
<div className="infio-api-key-input-wrapper">
|
||||
<input
|
||||
type={isVisible ? "text" : "password"}
|
||||
className="infio-api-key-input"
|
||||
placeholder={placeholder}
|
||||
value={localValue}
|
||||
onChange={handleChange}
|
||||
onBlur={handleBlur}
|
||||
onKeyDown={handleKeyDown}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
className="infio-api-key-toggle"
|
||||
onClick={toggleVisibility}
|
||||
title={isVisible ? "隐藏API Key" : "显示API Key"}
|
||||
>
|
||||
{isVisible ? (
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"></path>
|
||||
<line x1="1" y1="1" x2="23" y2="23"></line>
|
||||
</svg>
|
||||
) : (
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"></path>
|
||||
<circle cx="12" cy="12" r="3"></circle>
|
||||
</svg>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{onTest && (
|
||||
<button
|
||||
type="button"
|
||||
className={`infio-api-key-test ${isTestingConnection ? 'testing' : ''} ${testResult ? testResult : ''}`}
|
||||
onClick={handleTest}
|
||||
disabled={isTestingConnection || !localValue.trim()}
|
||||
title="测试API连通性"
|
||||
>
|
||||
{isTestingConnection ? (
|
||||
<>
|
||||
<div className="loading-spinner"></div>
|
||||
<span>测试中</span>
|
||||
</>
|
||||
) : testResult === 'success' ? (
|
||||
<>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<polyline points="20,6 9,17 4,12"></polyline>
|
||||
</svg>
|
||||
<span>成功</span>
|
||||
</>
|
||||
) : testResult === 'error' ? (
|
||||
<>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<circle cx="12" cy="12" r="10"></circle>
|
||||
<line x1="15" y1="9" x2="9" y2="15"></line>
|
||||
<line x1="9" y1="9" x2="15" y2="15"></line>
|
||||
</svg>
|
||||
<span>失败</span>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<circle cx="12" cy="12" r="1"></circle>
|
||||
<path d="M20.2 20.2c2.04-2.03.02-7.36-4.5-11.9-4.54-4.52-9.87-6.54-11.9-4.5-2.04 2.03-.02 7.36 4.5 11.9 4.54 4.52 9.87 6.54 11.9 4.5z"></path>
|
||||
<path d="M15.7 15.7c4.52-4.54 6.54-9.87 4.5-11.9-2.03-2.04-7.36-.02-11.9 4.5-4.52 4.54-6.54 9.87-4.5 11.9 2.03 2.04 7.36.02 11.9-4.5z"></path>
|
||||
</svg>
|
||||
<span>测试</span>
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<style>{`
|
||||
.infio-api-key-setting-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: var(--size-4-6);
|
||||
padding: var(--size-4-3) 0;
|
||||
border-bottom: 1px solid var(--background-modifier-border);
|
||||
}
|
||||
|
||||
.infio-api-key-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
max-width: 60%;
|
||||
}
|
||||
|
||||
.infio-api-key-name {
|
||||
font-size: var(--font-ui-medium);
|
||||
font-weight: var(--font-weight-medium);
|
||||
color: var(--text-normal);
|
||||
margin-bottom: var(--size-2-1);
|
||||
}
|
||||
|
||||
.infio-api-key-description {
|
||||
font-size: var(--font-ui-small);
|
||||
color: var(--text-muted);
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.infio-api-key-control-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--size-2-3);
|
||||
min-width: 300px;
|
||||
max-width: 380px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.infio-api-key-input-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
position: relative;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.infio-api-key-input {
|
||||
width: 100%;
|
||||
padding: var(--size-2-2) var(--size-4-6) var(--size-2-2) var(--size-4-2);
|
||||
border: 1px solid var(--background-modifier-border);
|
||||
border-radius: var(--radius-s);
|
||||
background: var(--background-primary);
|
||||
color: var(--text-normal);
|
||||
font-size: var(--font-ui-small);
|
||||
font-family: var(--font-monospace);
|
||||
transition: all 0.15s ease-in-out;
|
||||
}
|
||||
|
||||
.infio-api-key-input:focus {
|
||||
outline: none;
|
||||
border-color: var(--interactive-accent);
|
||||
box-shadow: 0 0 0 2px var(--interactive-accent-hover);
|
||||
}
|
||||
|
||||
.infio-api-key-input::placeholder {
|
||||
color: var(--text-faint);
|
||||
}
|
||||
|
||||
.infio-api-key-toggle {
|
||||
position: absolute;
|
||||
right: var(--size-2-2);
|
||||
padding: var(--size-2-1);
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: var(--text-muted);
|
||||
cursor: pointer;
|
||||
transition: all 0.15s ease-in-out;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border-radius: var(--radius-s);
|
||||
}
|
||||
|
||||
.infio-api-key-toggle:hover {
|
||||
background: var(--background-modifier-hover);
|
||||
color: var(--text-normal);
|
||||
}
|
||||
|
||||
.infio-api-key-toggle:active {
|
||||
background: var(--background-modifier-active);
|
||||
}
|
||||
|
||||
.infio-api-key-test {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--size-2-1);
|
||||
padding: var(--size-2-2) var(--size-4-2);
|
||||
border: 1px solid var(--background-modifier-border);
|
||||
border-radius: var(--radius-s);
|
||||
background: var(--background-secondary);
|
||||
color: var(--text-normal);
|
||||
cursor: pointer;
|
||||
transition: all 0.15s ease-in-out;
|
||||
font-size: var(--font-ui-small);
|
||||
font-weight: var(--font-weight-medium);
|
||||
height: 34px;
|
||||
flex-shrink: 0;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.infio-api-key-test:hover:not(:disabled) {
|
||||
background: var(--background-modifier-hover);
|
||||
border-color: var(--background-modifier-border-hover);
|
||||
}
|
||||
|
||||
.infio-api-key-test:active:not(:disabled) {
|
||||
background: var(--background-modifier-active);
|
||||
}
|
||||
|
||||
.infio-api-key-test:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.infio-api-key-test.success {
|
||||
border-color: var(--color-green);
|
||||
background: var(--color-green);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.infio-api-key-test.error {
|
||||
border-color: var(--color-red);
|
||||
background: var(--color-red);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.infio-api-key-test.testing {
|
||||
border-color: var(--interactive-accent);
|
||||
}
|
||||
|
||||
.loading-spinner {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
border: 2px solid var(--background-modifier-border);
|
||||
border-top: 2px solid var(--interactive-accent);
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
/* 响应式设计 */
|
||||
@media (max-width: 768px) {
|
||||
.infio-api-key-setting-item {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: var(--size-4-2);
|
||||
}
|
||||
|
||||
.infio-api-key-control-container {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
min-width: auto;
|
||||
max-width: none;
|
||||
gap: var(--size-2-2);
|
||||
}
|
||||
|
||||
.infio-api-key-input-wrapper {
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.infio-api-key-test {
|
||||
align-self: flex-start;
|
||||
}
|
||||
}
|
||||
|
||||
/* 深色模式适配 */
|
||||
.theme-dark .infio-api-key-input {
|
||||
background: var(--background-primary-alt);
|
||||
border-color: var(--background-modifier-border-hover);
|
||||
}
|
||||
|
||||
.theme-dark .infio-api-key-toggle:hover {
|
||||
background: var(--background-modifier-hover);
|
||||
}
|
||||
|
||||
.theme-dark .infio-api-key-test {
|
||||
background: var(--background-secondary-alt);
|
||||
}
|
||||
|
||||
.theme-dark .infio-api-key-test:hover:not(:disabled) {
|
||||
background: var(--background-modifier-hover);
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export type CustomUrlComponentProps = {
|
||||
name: string;
|
||||
placeholder: string;
|
||||
useCustomUrl: boolean;
|
||||
baseUrl: string;
|
||||
onToggleCustomUrl: (value: boolean) => void;
|
||||
onChangeBaseUrl: (value: string) => void;
|
||||
}
|
||||
|
||||
export const CustomUrlComponent: React.FC<CustomUrlComponentProps> = ({
|
||||
name,
|
||||
placeholder,
|
||||
useCustomUrl,
|
||||
baseUrl,
|
||||
onToggleCustomUrl,
|
||||
onChangeBaseUrl,
|
||||
}) => {
|
||||
const [localValue, setLocalValue] = useState(baseUrl);
|
||||
|
||||
// Update local value when prop value changes (e.g., provider change)
|
||||
useEffect(() => {
|
||||
setLocalValue(baseUrl);
|
||||
}, [baseUrl]);
|
||||
|
||||
const handleUrlChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setLocalValue(e.target.value);
|
||||
};
|
||||
|
||||
const handleUrlBlur = () => {
|
||||
if (localValue !== baseUrl) {
|
||||
onChangeBaseUrl(localValue);
|
||||
}
|
||||
};
|
||||
|
||||
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.currentTarget.blur();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="infio-llm-setting-item">
|
||||
<div className="infio-custom-url-toggle-section">
|
||||
<div className="infio-custom-url-name">{name}</div>
|
||||
<label className="infio-toggle-switch">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={useCustomUrl}
|
||||
onChange={(e) => onToggleCustomUrl(e.target.checked)}
|
||||
/>
|
||||
<span className="slider"></span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{useCustomUrl && (
|
||||
<div className="infio-custom-url-input-section">
|
||||
<input
|
||||
type="text"
|
||||
className="infio-llm-setting-item-control"
|
||||
placeholder={placeholder}
|
||||
value={localValue}
|
||||
onChange={handleUrlChange}
|
||||
onBlur={handleUrlBlur}
|
||||
onKeyDown={handleKeyDown}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<style>{`
|
||||
.infio-custom-url-toggle-section {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.infio-custom-url-name {
|
||||
font-size: var(--font-ui-medium);
|
||||
font-weight: var(--font-weight-medium);
|
||||
color: var(--text-normal);
|
||||
margin-bottom: var(--size-2-1);
|
||||
}
|
||||
|
||||
|
||||
.infio-custom-url-input-section {
|
||||
margin-top: var(--size-4-2);
|
||||
}
|
||||
|
||||
/* 开关样式 */
|
||||
.infio-toggle-switch {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
width: 44px;
|
||||
height: 24px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.infio-toggle-switch input {
|
||||
opacity: 0;
|
||||
width: 0;
|
||||
height: 0;
|
||||
}
|
||||
|
||||
.slider {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: var(--background-modifier-border);
|
||||
transition: all 0.2s ease-in-out;
|
||||
border-radius: 24px;
|
||||
border: 1px solid var(--background-modifier-border-hover);
|
||||
}
|
||||
|
||||
.slider:before {
|
||||
position: absolute;
|
||||
content: "";
|
||||
height: 18px;
|
||||
width: 18px;
|
||||
left: 2px;
|
||||
bottom: 2px;
|
||||
background-color: var(--text-on-accent);
|
||||
transition: all 0.2s ease-in-out;
|
||||
border-radius: 50%;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.infio-toggle-switch input:checked + .slider {
|
||||
background-color: var(--interactive-accent);
|
||||
border-color: var(--interactive-accent);
|
||||
}
|
||||
|
||||
.infio-toggle-switch input:checked + .slider:before {
|
||||
transform: translateX(20px);
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
.infio-toggle-switch:hover .slider {
|
||||
box-shadow: 0 0 0 2px var(--interactive-accent-hover);
|
||||
}
|
||||
|
||||
.infio-toggle-switch input:focus + .slider {
|
||||
box-shadow: 0 0 0 2px var(--interactive-accent-hover);
|
||||
}
|
||||
|
||||
/* 深色模式适配 */
|
||||
.theme-dark .slider:before {
|
||||
background-color: var(--text-normal);
|
||||
}
|
||||
|
||||
.theme-dark .infio-toggle-switch input:checked + .slider:before {
|
||||
background-color: white;
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
import React, { useMemo, useState } from 'react';
|
||||
import React, { useState } from 'react';
|
||||
|
||||
import { t } from '../../lang/helpers';
|
||||
import InfioPlugin from "../../main";
|
||||
import { ApiProvider } from '../../types/llm/model';
|
||||
import { InfioSettings } from '../../types/settings';
|
||||
import { GetAllProviders } from '../../utils/api';
|
||||
import { getProviderApiUrl } from '../../utils/provider-urls';
|
||||
|
||||
import { DropdownComponent, TextComponent, ToggleComponent } from './FormComponents';
|
||||
import { ApiKeyComponent, CustomUrlComponent } from './FormComponents';
|
||||
import { ComboBoxComponent } from './ProviderModelsPicker';
|
||||
|
||||
type CustomProviderSettingsProps = {
|
||||
@ -49,31 +50,17 @@ const getProviderSettingKey = (provider: ApiProvider): ProviderSettingKey => {
|
||||
|
||||
const CustomProviderSettings: React.FC<CustomProviderSettingsProps> = ({ plugin, onSettingsUpdate }) => {
|
||||
const settings = plugin.settings;
|
||||
const [currProvider, setCurrProvider] = useState(settings.defaultProvider);
|
||||
const [activeTab, setActiveTab] = useState<ApiProvider>(ApiProvider.Infio);
|
||||
|
||||
const handleSettingsUpdate = async (newSettings: InfioSettings) => {
|
||||
await plugin.setSettings(newSettings);
|
||||
// Use the callback function passed from the parent component to refresh the entire container
|
||||
onSettingsUpdate?.();
|
||||
};
|
||||
|
||||
const providerSetting = useMemo(() => {
|
||||
const providerKey = getProviderSettingKey(currProvider);
|
||||
return settings[providerKey] || {};
|
||||
}, [currProvider, settings]);
|
||||
|
||||
const providers = GetAllProviders();
|
||||
|
||||
const updateProvider = (provider: ApiProvider) => {
|
||||
setCurrProvider(provider);
|
||||
handleSettingsUpdate({
|
||||
...settings,
|
||||
defaultProvider: provider
|
||||
});
|
||||
};
|
||||
|
||||
const updateProviderApiKey = (value: string) => {
|
||||
const providerKey = getProviderSettingKey(currProvider);
|
||||
const updateProviderApiKey = (provider: ApiProvider, value: string) => {
|
||||
const providerKey = getProviderSettingKey(provider);
|
||||
const providerSettings = settings[providerKey];
|
||||
|
||||
handleSettingsUpdate({
|
||||
@ -85,8 +72,8 @@ const CustomProviderSettings: React.FC<CustomProviderSettingsProps> = ({ plugin,
|
||||
});
|
||||
};
|
||||
|
||||
const updateProviderUseCustomUrl = (value: boolean) => {
|
||||
const providerKey = getProviderSettingKey(currProvider);
|
||||
const updateProviderUseCustomUrl = (provider: ApiProvider, value: boolean) => {
|
||||
const providerKey = getProviderSettingKey(provider);
|
||||
const providerSettings = settings[providerKey];
|
||||
|
||||
handleSettingsUpdate({
|
||||
@ -98,8 +85,8 @@ const CustomProviderSettings: React.FC<CustomProviderSettingsProps> = ({ plugin,
|
||||
});
|
||||
};
|
||||
|
||||
const updateProviderBaseUrl = (value: string) => {
|
||||
const providerKey = getProviderSettingKey(currProvider);
|
||||
const updateProviderBaseUrl = (provider: ApiProvider, value: string) => {
|
||||
const providerKey = getProviderSettingKey(provider);
|
||||
const providerSettings = settings[providerKey];
|
||||
|
||||
handleSettingsUpdate({
|
||||
@ -111,6 +98,25 @@ const CustomProviderSettings: React.FC<CustomProviderSettingsProps> = ({ plugin,
|
||||
});
|
||||
};
|
||||
|
||||
const testApiConnection = async (provider: ApiProvider) => {
|
||||
// TODO: 实现API连接测试逻辑
|
||||
// 这里应该根据provider类型调用对应的API测试接口
|
||||
console.log(`Testing connection for ${provider}...`);
|
||||
|
||||
// 模拟延迟
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
|
||||
// 模拟随机成功/失败(用于演示)
|
||||
if (Math.random() > 0.5) {
|
||||
throw new Error('Connection test failed');
|
||||
}
|
||||
};
|
||||
|
||||
const getProviderSetting = (provider: ApiProvider) => {
|
||||
const providerKey = getProviderSettingKey(provider);
|
||||
return settings[providerKey] || {};
|
||||
};
|
||||
|
||||
const updateChatModelId = (provider: ApiProvider, modelId: string) => {
|
||||
handleSettingsUpdate({
|
||||
...settings,
|
||||
@ -135,66 +141,288 @@ const CustomProviderSettings: React.FC<CustomProviderSettingsProps> = ({ plugin,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="infio-llm-setting-provider">
|
||||
<DropdownComponent
|
||||
name={t("settings.ApiProvider.label")}
|
||||
value={currProvider}
|
||||
options={providers}
|
||||
onChange={updateProvider}
|
||||
/>
|
||||
<div className="infio-llm-setting-divider"></div>
|
||||
{currProvider !== ApiProvider.Ollama && (
|
||||
<TextComponent
|
||||
name={currProvider + " api key:"}
|
||||
placeholder={t("settings.ApiProvider.enterApiKey")}
|
||||
value={providerSetting.apiKey || ''}
|
||||
onChange={updateProviderApiKey}
|
||||
type="password"
|
||||
/>
|
||||
)}
|
||||
<div className="infio-llm-setting-divider"></div>
|
||||
<ToggleComponent
|
||||
name={t("settings.ApiProvider.useCustomBaseUrl")}
|
||||
value={providerSetting.useCustomUrl || false}
|
||||
onChange={updateProviderUseCustomUrl}
|
||||
/>
|
||||
{providerSetting.useCustomUrl && (
|
||||
<TextComponent
|
||||
placeholder={t("settings.ApiProvider.enterCustomUrl")}
|
||||
value={providerSetting.baseUrl || ''}
|
||||
onChange={updateProviderBaseUrl}
|
||||
/>
|
||||
)}
|
||||
// 生成包含链接的API Key描述
|
||||
const generateApiKeyDescription = (provider: ApiProvider): React.ReactNode => {
|
||||
const apiUrl = getProviderApiUrl(provider);
|
||||
const baseDescription = t("settings.ApiProvider.enterApiKeyDescription");
|
||||
|
||||
if (!apiUrl) {
|
||||
// 如果没有URL,直接移除占位符
|
||||
return baseDescription.replace('{provider_api_url}', '');
|
||||
}
|
||||
|
||||
<div className="infio-llm-setting-divider"></div>
|
||||
<div className="infio-llm-setting-divider"></div>
|
||||
<ComboBoxComponent
|
||||
name={t("settings.Models.chatModel")}
|
||||
settings={settings}
|
||||
provider={settings.chatModelProvider || currProvider}
|
||||
modelId={settings.chatModelId}
|
||||
updateModel={updateChatModelId}
|
||||
/>
|
||||
<div className="infio-llm-setting-divider"></div>
|
||||
<ComboBoxComponent
|
||||
name={t("settings.Models.autocompleteModel")}
|
||||
settings={settings}
|
||||
provider={settings.applyModelProvider || currProvider}
|
||||
modelId={settings.applyModelId}
|
||||
updateModel={updateApplyModelId}
|
||||
/>
|
||||
<div className="infio-llm-setting-divider"></div>
|
||||
<ComboBoxComponent
|
||||
name={t("settings.Models.embeddingModel")}
|
||||
settings={settings}
|
||||
provider={settings.embeddingModelProvider || ApiProvider.Google}
|
||||
modelId={settings.embeddingModelId}
|
||||
isEmbedding={true}
|
||||
updateModel={updateEmbeddingModelId}
|
||||
/>
|
||||
<div className="infio-llm-setting-divider"></div>
|
||||
<div className="infio-llm-setting-divider"></div>
|
||||
// 将占位符替换为实际的链接元素
|
||||
const parts = baseDescription.split('{provider_api_url}');
|
||||
if (parts.length !== 2) {
|
||||
return baseDescription;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{parts[0]}
|
||||
<a
|
||||
href={apiUrl}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="provider-api-link"
|
||||
>
|
||||
{apiUrl}
|
||||
</a>
|
||||
{parts[1]}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const renderProviderConfig = (provider: ApiProvider) => {
|
||||
const providerSetting = getProviderSetting(provider);
|
||||
|
||||
return (
|
||||
<div className="provider-config">
|
||||
{provider !== ApiProvider.Ollama && (
|
||||
<ApiKeyComponent
|
||||
name={
|
||||
<>
|
||||
设置 <span className="provider-name-highlight">{provider}</span> API Key
|
||||
</>
|
||||
}
|
||||
placeholder={t("settings.ApiProvider.enterApiKey")}
|
||||
description={generateApiKeyDescription(provider)}
|
||||
value={providerSetting.apiKey || ''}
|
||||
onChange={(value) => updateProviderApiKey(provider, value)}
|
||||
onTest={() => testApiConnection(provider)}
|
||||
/>
|
||||
)}
|
||||
|
||||
<CustomUrlComponent
|
||||
name={t("settings.ApiProvider.useCustomBaseUrl")}
|
||||
placeholder={t("settings.ApiProvider.enterCustomUrl")}
|
||||
useCustomUrl={providerSetting.useCustomUrl || false}
|
||||
baseUrl={providerSetting.baseUrl || ''}
|
||||
onToggleCustomUrl={(value) => updateProviderUseCustomUrl(provider, value)}
|
||||
onChangeBaseUrl={(value) => updateProviderBaseUrl(provider, value)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="provider-settings-container">
|
||||
{/* 提供商配置区域 */}
|
||||
<div className="provider-config-section">
|
||||
<h2 className="section-title">{t("settings.ApiProvider.label")}</h2>
|
||||
<p className="section-description">{t("settings.ApiProvider.labelDescription")}</p>
|
||||
{/* 提供商标签页 */}
|
||||
<div className="provider-tabs">
|
||||
{providers.map((provider) => (
|
||||
<button
|
||||
key={provider}
|
||||
className={`provider-tab ${activeTab === provider ? 'active' : ''}`}
|
||||
onClick={() => setActiveTab(provider)}
|
||||
>
|
||||
{provider}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* 当前选中提供商的配置 */}
|
||||
<div className="provider-config-content">
|
||||
{renderProviderConfig(activeTab)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 模型选择区域 */}
|
||||
<div className="model-selection-section">
|
||||
<h2 className="section-title">模型选择</h2>
|
||||
|
||||
<div className="model-selectors">
|
||||
<ComboBoxComponent
|
||||
name={t("settings.Models.chatModel")}
|
||||
description={t("settings.Models.chatModelDescription")}
|
||||
settings={settings}
|
||||
provider={settings.chatModelProvider || ApiProvider.OpenAI}
|
||||
modelId={settings.chatModelId}
|
||||
updateModel={updateChatModelId}
|
||||
/>
|
||||
|
||||
<ComboBoxComponent
|
||||
name={t("settings.Models.autocompleteModel")}
|
||||
description={t("settings.Models.autocompleteModelDescription")}
|
||||
settings={settings}
|
||||
provider={settings.applyModelProvider || ApiProvider.OpenAI}
|
||||
modelId={settings.applyModelId}
|
||||
updateModel={updateApplyModelId}
|
||||
/>
|
||||
|
||||
<ComboBoxComponent
|
||||
name={t("settings.Models.embeddingModel")}
|
||||
description={t("settings.Models.embeddingModelDescription")}
|
||||
settings={settings}
|
||||
provider={settings.embeddingModelProvider || ApiProvider.Google}
|
||||
modelId={settings.embeddingModelId}
|
||||
isEmbedding={true}
|
||||
updateModel={updateEmbeddingModelId}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
{`
|
||||
/* 主容器样式 */
|
||||
.provider-settings-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--size-4-6);
|
||||
}
|
||||
|
||||
/* 区域样式 */
|
||||
.provider-config-section,
|
||||
.model-selection-section {
|
||||
background: var(--background-primary);
|
||||
border: 1px solid var(--background-modifier-border);
|
||||
border-radius: var(--radius-m);
|
||||
padding: var(--size-4-4);
|
||||
}
|
||||
|
||||
/* 标题样式 */
|
||||
.section-title {
|
||||
font-size: var(--font-ui-medium);
|
||||
font-weight: var(--font-weight-semibold);
|
||||
color: var(--text-normal);
|
||||
margin: 0 0 var(--size-4-3) 0;
|
||||
padding-bottom: var(--size-2-2);
|
||||
border-bottom: 1px solid var(--background-modifier-border);
|
||||
}
|
||||
|
||||
/* 提供商标签页容器 */
|
||||
.provider-tabs {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--size-2-2);
|
||||
margin-bottom: var(--size-4-4);
|
||||
padding-bottom: var(--size-4-3);
|
||||
border-bottom: 1px solid var(--background-modifier-border);
|
||||
}
|
||||
|
||||
/* 提供商标签页按钮 */
|
||||
.provider-tab {
|
||||
padding: var(--size-2-2) var(--size-4-2);
|
||||
background: var(--background-secondary);
|
||||
border: 1px solid var(--background-modifier-border);
|
||||
border-radius: var(--radius-s);
|
||||
cursor: pointer;
|
||||
transition: all 0.15s ease-in-out;
|
||||
font-size: var(--font-ui-small);
|
||||
font-weight: var(--font-weight-medium);
|
||||
color: var(--text-muted);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.provider-tab:hover {
|
||||
background: var(--background-modifier-hover);
|
||||
color: var(--text-normal);
|
||||
}
|
||||
|
||||
.provider-tab.active {
|
||||
background: var(--interactive-accent);
|
||||
border-color: var(--interactive-accent);
|
||||
color: var(--text-on-accent);
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
|
||||
font-weight: var(--font-weight-semibold);
|
||||
}
|
||||
|
||||
.provider-tab.active:hover {
|
||||
background: var(--interactive-accent-hover);
|
||||
border-color: var(--interactive-accent-hover);
|
||||
}
|
||||
|
||||
/* 提供商配置内容 */
|
||||
.provider-config-content {
|
||||
min-height: 120px;
|
||||
}
|
||||
|
||||
.provider-config {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--size-4-2);
|
||||
}
|
||||
|
||||
/* 模型选择器容器 */
|
||||
.model-selectors {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--size-4-3);
|
||||
}
|
||||
|
||||
/* 分隔线 */
|
||||
.setting-divider {
|
||||
height: 1px;
|
||||
background: var(--background-modifier-border);
|
||||
margin: var(--size-2-2) 0;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
/* 响应式设计 */
|
||||
@media (max-width: 768px) {
|
||||
.provider-settings-container {
|
||||
gap: var(--size-4-3);
|
||||
}
|
||||
|
||||
.provider-config-section,
|
||||
.model-selection-section {
|
||||
padding: var(--size-4-2);
|
||||
}
|
||||
|
||||
.provider-tabs {
|
||||
gap: var(--size-2-1);
|
||||
}
|
||||
|
||||
.provider-tab {
|
||||
padding: var(--size-2-1) var(--size-4-1);
|
||||
font-size: var(--font-ui-smaller);
|
||||
}
|
||||
}
|
||||
|
||||
/* 提供商名称高亮样式 */
|
||||
.provider-name-highlight {
|
||||
color: var(--interactive-accent);
|
||||
font-weight: var(--font-weight-medium);
|
||||
}
|
||||
|
||||
/* API 链接样式 */
|
||||
.provider-api-link {
|
||||
color: var(--text-accent);
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.provider-api-link:hover {
|
||||
color: var(--text-accent-hover);
|
||||
}
|
||||
|
||||
/* 深色模式适配 */
|
||||
.theme-dark .provider-tab {
|
||||
background: var(--background-secondary-alt);
|
||||
}
|
||||
|
||||
.theme-dark .provider-tab:hover {
|
||||
background: var(--background-modifier-hover);
|
||||
}
|
||||
|
||||
.theme-dark .provider-tab.active {
|
||||
background: var(--interactive-accent);
|
||||
color: var(--text-on-accent);
|
||||
}
|
||||
|
||||
.theme-dark .provider-tab.active:hover {
|
||||
background: var(--interactive-accent-hover);
|
||||
}
|
||||
|
||||
.theme-dark .provider-config-section,
|
||||
.theme-dark .model-selection-section {
|
||||
background: var(--background-primary-alt);
|
||||
border-color: var(--background-modifier-border-hover);
|
||||
}
|
||||
`}
|
||||
</style>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@ -152,6 +152,7 @@ export type ComboBoxComponentProps = {
|
||||
modelId: string;
|
||||
settings?: InfioSettings | null;
|
||||
isEmbedding?: boolean,
|
||||
description?: string;
|
||||
updateModel: (provider: ApiProvider, modelId: string) => void;
|
||||
};
|
||||
|
||||
@ -161,6 +162,7 @@ export const ComboBoxComponent: React.FC<ComboBoxComponentProps> = ({
|
||||
modelId,
|
||||
settings = null,
|
||||
isEmbedding = false,
|
||||
description,
|
||||
updateModel,
|
||||
}) => {
|
||||
// provider state
|
||||
@ -198,25 +200,37 @@ export const ComboBoxComponent: React.FC<ComboBoxComponentProps> = ({
|
||||
const fuse: Fuse<SearchableItem> = useMemo(() => {
|
||||
return new Fuse<SearchableItem>(searchableItems, {
|
||||
keys: ["html"],
|
||||
threshold: 0.6,
|
||||
threshold: 1,
|
||||
shouldSort: true,
|
||||
isCaseSensitive: false,
|
||||
ignoreLocation: false,
|
||||
includeMatches: true,
|
||||
minMatchCharLength: 1,
|
||||
minMatchCharLength: 4,
|
||||
})
|
||||
}, [searchableItems])
|
||||
|
||||
// 根据 searchTerm 得到过滤后的数据列表
|
||||
const filteredOptions = useMemo(() => {
|
||||
const results: HighlightedItem[] = searchTerm
|
||||
let results: HighlightedItem[] = searchTerm
|
||||
? highlight(fuse.search(searchTerm))
|
||||
: searchableItems.map(item => ({
|
||||
...item,
|
||||
html: typeof item.html === 'string' ? [{ text: item.html, isHighlighted: false }] : item.html
|
||||
}))
|
||||
|
||||
// 如果有搜索词,添加自定义选项(如果不存在完全匹配的话)
|
||||
if (searchTerm && searchTerm.trim()) {
|
||||
const exactMatch = searchableItems.some(item => item.id === searchTerm);
|
||||
if (!exactMatch) {
|
||||
results.unshift({
|
||||
id: searchTerm,
|
||||
html: [{ text: `${modelIds.length > 0 ? '自定义: ' : ''}${searchTerm}`, isHighlighted: false }]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return results
|
||||
}, [searchableItems, searchTerm, fuse])
|
||||
}, [searchableItems, searchTerm, fuse, modelIds.length])
|
||||
|
||||
const listRef = useRef<HTMLDivElement>(null);
|
||||
const itemRefs = useRef<Array<HTMLDivElement | null>>([]);
|
||||
@ -231,116 +245,379 @@ export const ComboBoxComponent: React.FC<ComboBoxComponentProps> = ({
|
||||
}
|
||||
}, [selectedIndex]);
|
||||
|
||||
// Handle provider change
|
||||
const handleProviderChange = (newProvider: string) => {
|
||||
// Use proper type checking without type assertion
|
||||
const availableProviders = providers;
|
||||
const isValidProvider = (value: string): value is ApiProvider => {
|
||||
// @ts-ignore
|
||||
return (availableProviders as readonly string[]).includes(value);
|
||||
};
|
||||
|
||||
if (isValidProvider(newProvider)) {
|
||||
setModelProvider(newProvider);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="infio-llm-setting-item">
|
||||
<div className="infio-llm-setting-item-name">{name}</div>
|
||||
<Popover.Root modal={false} open={isOpen} onOpenChange={setIsOpen}>
|
||||
<Popover.Trigger asChild>
|
||||
<div className="infio-llm-setting-item-control">
|
||||
<span className="infio-llm-setting-model-id">[{modelProvider}] {modelId}</span>
|
||||
</div>
|
||||
</Popover.Trigger>
|
||||
<Popover.Content
|
||||
side="bottom"
|
||||
align="start"
|
||||
sideOffset={4}
|
||||
className="infio-llm-setting-combobox-dropdown"
|
||||
>
|
||||
<div ref={listRef}>
|
||||
<div className="infio-llm-setting-search-container">
|
||||
<select
|
||||
className="infio-llm-setting-provider-switch"
|
||||
value={modelProvider}
|
||||
onChange={(e) => setModelProvider(e.target.value as ApiProvider)}
|
||||
{description && (
|
||||
<div className="infio-llm-setting-item-description">{description}</div>
|
||||
)}
|
||||
<div className="infio-llm-setting-item-content">
|
||||
{/* Provider Selection - Now visible outside */}
|
||||
<div className="infio-llm-setting-provider-container">
|
||||
<label className="infio-llm-setting-provider-label">提供商</label>
|
||||
<select
|
||||
className="dropdown infio-llm-setting-provider-select"
|
||||
value={modelProvider}
|
||||
onChange={(e) => handleProviderChange(e.target.value)}
|
||||
>
|
||||
{providers.map((providerOption) => (
|
||||
<option
|
||||
key={providerOption}
|
||||
value={providerOption}
|
||||
>
|
||||
{providers.map((provider) => (
|
||||
<option
|
||||
key={provider}
|
||||
value={provider}
|
||||
className={`infio-llm-setting-provider-option ${provider === modelProvider ? 'is-active' : ''}`}
|
||||
>
|
||||
{provider}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
{modelIds.length > 0 ? (
|
||||
<input
|
||||
type="text"
|
||||
className="infio-llm-setting-item-search"
|
||||
placeholder="search model..."
|
||||
value={searchTerm}
|
||||
onChange={(e) => {
|
||||
setSearchTerm(e.target.value);
|
||||
setSelectedIndex(0);
|
||||
}}
|
||||
onKeyDown={(e) => {
|
||||
switch (e.key) {
|
||||
case "ArrowDown":
|
||||
e.preventDefault();
|
||||
setSelectedIndex((prev) =>
|
||||
Math.min(prev + 1, filteredOptions.length - 1)
|
||||
);
|
||||
break;
|
||||
case "ArrowUp":
|
||||
e.preventDefault();
|
||||
setSelectedIndex((prev) => Math.max(prev - 1, 0));
|
||||
break;
|
||||
case "Enter": {
|
||||
e.preventDefault();
|
||||
const selectedOption = filteredOptions[selectedIndex];
|
||||
if (selectedOption) {
|
||||
updateModel(modelProvider, selectedOption.id);
|
||||
setSearchTerm("");
|
||||
setIsOpen(false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "Escape":
|
||||
e.preventDefault();
|
||||
setIsOpen(false);
|
||||
setSearchTerm("");
|
||||
break;
|
||||
}
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
{providerOption}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{/* Model Selection */}
|
||||
<div className="infio-llm-setting-model-container">
|
||||
<label className="infio-llm-setting-model-label">模型</label>
|
||||
<Popover.Root modal={false} open={isOpen} onOpenChange={setIsOpen}>
|
||||
<Popover.Trigger asChild>
|
||||
<button className="infio-llm-setting-model-trigger clickable-icon" type="button">
|
||||
<span className="infio-llm-setting-model-display">
|
||||
{modelId || "选择模型..."}
|
||||
</span>
|
||||
<svg
|
||||
className="infio-llm-setting-model-arrow"
|
||||
width="12"
|
||||
height="12"
|
||||
viewBox="0 0 12 12"
|
||||
fill="none"
|
||||
>
|
||||
<path
|
||||
d="M3 4.5L6 7.5L9 4.5"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
</Popover.Trigger>
|
||||
<Popover.Content
|
||||
side="bottom"
|
||||
align="start"
|
||||
sideOffset={4}
|
||||
className="infio-llm-setting-combobox-dropdown"
|
||||
>
|
||||
<div ref={listRef}>
|
||||
<div className="infio-llm-setting-search-container">
|
||||
<input
|
||||
type="text"
|
||||
className="infio-llm-setting-item-search"
|
||||
placeholder="input custom model name"
|
||||
placeholder={modelIds.length > 0 ? "搜索或输入模型名称..." : "输入自定义模型名称"}
|
||||
value={searchTerm}
|
||||
onChange={(e) => {
|
||||
setSearchTerm(e.target.value);
|
||||
setSelectedIndex(0);
|
||||
}}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
updateModel(modelProvider, searchTerm);
|
||||
setIsOpen(false);
|
||||
switch (e.key) {
|
||||
case "ArrowDown":
|
||||
e.preventDefault();
|
||||
setSelectedIndex((prev) =>
|
||||
Math.min(prev + 1, filteredOptions.length - 1)
|
||||
);
|
||||
break;
|
||||
case "ArrowUp":
|
||||
e.preventDefault();
|
||||
setSelectedIndex((prev) => Math.max(prev - 1, 0));
|
||||
break;
|
||||
case "Enter": {
|
||||
e.preventDefault();
|
||||
if (filteredOptions.length > 0) {
|
||||
const selectedOption = filteredOptions[selectedIndex];
|
||||
if (selectedOption) {
|
||||
updateModel(modelProvider, selectedOption.id);
|
||||
}
|
||||
} else if (searchTerm.trim()) {
|
||||
// 如果没有选项但有输入内容,直接使用输入内容
|
||||
updateModel(modelProvider, searchTerm.trim());
|
||||
}
|
||||
setSearchTerm("");
|
||||
setIsOpen(false);
|
||||
break;
|
||||
}
|
||||
case "Escape":
|
||||
e.preventDefault();
|
||||
setIsOpen(false);
|
||||
setSearchTerm("");
|
||||
break;
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
{filteredOptions.map((option, index) => (
|
||||
<Popover.Close key={option.id} asChild>
|
||||
<div
|
||||
ref={(el) => (itemRefs.current[index] = el)}
|
||||
onMouseEnter={() => setSelectedIndex(index)}
|
||||
onClick={() => {
|
||||
updateModel(modelProvider, option.id);
|
||||
setSearchTerm("");
|
||||
setIsOpen(false);
|
||||
}}
|
||||
className={`infio-llm-setting-combobox-option ${index === selectedIndex ? 'is-selected' : ''}`}
|
||||
>
|
||||
<HighlightedText segments={option.html} />
|
||||
</div>
|
||||
</Popover.Close>
|
||||
))}
|
||||
</div>
|
||||
</Popover.Content>
|
||||
</Popover.Root>
|
||||
{filteredOptions.length > 0 ? (
|
||||
<div className="infio-llm-setting-options-list">
|
||||
{filteredOptions.map((option, index) => (
|
||||
<Popover.Close key={option.id} asChild>
|
||||
<div
|
||||
ref={(el) => (itemRefs.current[index] = el)}
|
||||
onMouseEnter={() => setSelectedIndex(index)}
|
||||
onClick={() => {
|
||||
updateModel(modelProvider, option.id);
|
||||
setSearchTerm("");
|
||||
setIsOpen(false);
|
||||
}}
|
||||
className={`infio-llm-setting-combobox-option ${index === selectedIndex ? 'is-selected' : ''}`}
|
||||
>
|
||||
<HighlightedText segments={option.html} />
|
||||
</div>
|
||||
</Popover.Close>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</Popover.Content>
|
||||
</Popover.Root>
|
||||
</div>
|
||||
</div>
|
||||
<style>{`
|
||||
.infio-llm-setting-item {
|
||||
margin-bottom: 8px;
|
||||
padding: 12px;
|
||||
background: var(--background-secondary);
|
||||
border-radius: 6px;
|
||||
border: 1px solid var(--background-modifier-border);
|
||||
}
|
||||
|
||||
.infio-llm-setting-item-name {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--text-normal);
|
||||
margin-bottom: 8px;
|
||||
padding-bottom: 4px;
|
||||
border-bottom: 1px solid var(--background-modifier-border);
|
||||
}
|
||||
|
||||
.infio-llm-setting-item-description {
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
margin-bottom: 8px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.infio-llm-setting-item-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.infio-llm-setting-provider-container,
|
||||
.infio-llm-setting-model-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.infio-llm-setting-provider-label,
|
||||
.infio-llm-setting-model-label {
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
color: var(--text-muted);
|
||||
min-width: 50px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.infio-llm-setting-provider-select {
|
||||
max-width: 200px;
|
||||
min-width: 120px;
|
||||
padding: 6px 8px;
|
||||
border: 1px solid var(--background-modifier-border);
|
||||
border-radius: 4px;
|
||||
background: var(--background-primary);
|
||||
color: var(--text-normal);
|
||||
font-size: 13px;
|
||||
transition: all 0.2s ease;
|
||||
appearance: none;
|
||||
background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6,9 12,15 18,9'%3e%3c/polyline%3e%3c/svg%3e");
|
||||
background-repeat: no-repeat;
|
||||
background-position: right 8px center;
|
||||
background-size: 12px;
|
||||
padding-right: 28px;
|
||||
}
|
||||
|
||||
.infio-llm-setting-provider-select:hover {
|
||||
border-color: var(--interactive-accent);
|
||||
}
|
||||
|
||||
.infio-llm-setting-provider-select:focus {
|
||||
outline: none;
|
||||
border-color: var(--interactive-accent);
|
||||
box-shadow: 0 0 0 2px var(--interactive-accent-hover);
|
||||
}
|
||||
|
||||
.infio-llm-setting-model-trigger {
|
||||
max-width: 300px;
|
||||
min-width: 150px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 6px 8px;
|
||||
border: 1px solid var(--background-modifier-border);
|
||||
border-radius: 4px;
|
||||
background: var(--background-primary);
|
||||
color: var(--text-normal);
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
min-height: 32px;
|
||||
}
|
||||
|
||||
.infio-llm-setting-model-trigger:hover {
|
||||
border-color: var(--interactive-accent);
|
||||
background: var(--background-modifier-hover);
|
||||
}
|
||||
|
||||
.infio-llm-setting-model-trigger:focus {
|
||||
outline: none;
|
||||
border-color: var(--interactive-accent);
|
||||
box-shadow: 0 0 0 2px var(--interactive-accent-hover);
|
||||
}
|
||||
|
||||
.infio-llm-setting-model-display {
|
||||
flex: 1;
|
||||
text-align: left;
|
||||
color: var(--text-normal);
|
||||
font-family: var(--font-monospace);
|
||||
font-size: 12px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.infio-llm-setting-model-arrow {
|
||||
color: var(--text-muted);
|
||||
transition: transform 0.2s ease;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.infio-llm-setting-model-trigger[data-state="open"] .infio-llm-setting-model-arrow {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
|
||||
.infio-llm-setting-combobox-dropdown {
|
||||
background: var(--background-primary);
|
||||
border: 1px solid var(--background-modifier-border);
|
||||
border-radius: 6px;
|
||||
box-shadow: var(--shadow-s);
|
||||
padding: 6px;
|
||||
min-width: 300px;
|
||||
max-width: 500px;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.infio-llm-setting-search-container {
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.infio-llm-setting-item-search {
|
||||
width: 100%;
|
||||
padding: 6px 8px;
|
||||
border: 1px solid var(--background-modifier-border);
|
||||
border-radius: 4px;
|
||||
background: var(--background-primary);
|
||||
color: var(--text-normal);
|
||||
font-size: 13px;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.infio-llm-setting-item-search:focus {
|
||||
outline: none;
|
||||
border-color: var(--interactive-accent);
|
||||
box-shadow: 0 0 0 2px var(--interactive-accent-hover);
|
||||
}
|
||||
|
||||
.infio-llm-setting-options-list {
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.infio-llm-setting-combobox-option {
|
||||
padding: 6px 8px;
|
||||
border-radius: 3px;
|
||||
cursor: pointer;
|
||||
font-family: var(--font-monospace);
|
||||
font-size: 12px;
|
||||
color: var(--text-normal);
|
||||
transition: all 0.15s ease;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.infio-llm-setting-combobox-option:hover,
|
||||
.infio-llm-setting-combobox-option.is-selected {
|
||||
background: var(--background-modifier-hover);
|
||||
color: var(--text-accent);
|
||||
}
|
||||
|
||||
.infio-llm-setting-model-item-highlight {
|
||||
color: var(--text-accent);
|
||||
}
|
||||
|
||||
.infio-llm-setting-no-results {
|
||||
padding: 12px 8px;
|
||||
text-align: center;
|
||||
color: var(--text-muted);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
/* 滚动条样式 */
|
||||
.infio-llm-setting-options-list::-webkit-scrollbar {
|
||||
width: 4px;
|
||||
}
|
||||
|
||||
.infio-llm-setting-options-list::-webkit-scrollbar-track {
|
||||
background: var(--background-secondary);
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.infio-llm-setting-options-list::-webkit-scrollbar-thumb {
|
||||
background: var(--background-modifier-border);
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.infio-llm-setting-options-list::-webkit-scrollbar-thumb:hover {
|
||||
background: var(--text-muted);
|
||||
}
|
||||
|
||||
/* 响应式设计 */
|
||||
@media (max-width: 768px) {
|
||||
.infio-llm-setting-provider-container,
|
||||
.infio-llm-setting-model-container {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.infio-llm-setting-provider-label,
|
||||
.infio-llm-setting-model-label {
|
||||
min-width: auto;
|
||||
}
|
||||
|
||||
.infio-llm-setting-provider-select,
|
||||
.infio-llm-setting-model-trigger {
|
||||
width: 100%;
|
||||
max-width: none;
|
||||
}
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@ -218,7 +218,7 @@ export const InfioSettingsSchema = z.object({
|
||||
version: z.literal(SETTINGS_SCHEMA_VERSION).catch(SETTINGS_SCHEMA_VERSION),
|
||||
|
||||
// Provider
|
||||
defaultProvider: z.nativeEnum(ApiProvider).catch(ApiProvider.OpenRouter),
|
||||
defaultProvider: z.nativeEnum(ApiProvider).catch(ApiProvider.Infio),
|
||||
infioProvider: InfioProviderSchema,
|
||||
openrouterProvider: OpenRouterProviderSchema,
|
||||
siliconflowProvider: SiliconFlowProviderSchema,
|
||||
@ -242,15 +242,15 @@ export const InfioSettingsSchema = z.object({
|
||||
})).catch([]),
|
||||
|
||||
// Chat Model
|
||||
chatModelProvider: z.nativeEnum(ApiProvider).catch(ApiProvider.OpenRouter),
|
||||
chatModelProvider: z.nativeEnum(ApiProvider).catch(ApiProvider.Infio),
|
||||
chatModelId: z.string().catch(''),
|
||||
|
||||
// Apply Model
|
||||
applyModelProvider: z.nativeEnum(ApiProvider).catch(ApiProvider.OpenRouter),
|
||||
applyModelProvider: z.nativeEnum(ApiProvider).catch(ApiProvider.Infio),
|
||||
applyModelId: z.string().catch(''),
|
||||
|
||||
// Embedding Model
|
||||
embeddingModelProvider: z.nativeEnum(ApiProvider).catch(ApiProvider.Google),
|
||||
embeddingModelProvider: z.nativeEnum(ApiProvider).catch(ApiProvider.Infio),
|
||||
embeddingModelId: z.string().catch(''),
|
||||
|
||||
// fuzzyMatchThreshold
|
||||
|
||||
22
src/utils/provider-urls.ts
Normal file
22
src/utils/provider-urls.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { ApiProvider } from '../types/llm/model';
|
||||
|
||||
// Provider API Key获取地址映射
|
||||
export const providerApiUrls: Record<ApiProvider, string> = {
|
||||
[ApiProvider.Infio]: 'https://platform.infio.app/home',
|
||||
[ApiProvider.OpenRouter]: 'https://openrouter.ai/settings/keys',
|
||||
[ApiProvider.SiliconFlow]: 'https://cloud.siliconflow.cn/account/ak',
|
||||
[ApiProvider.AlibabaQwen]: 'https://help.aliyun.com/zh/dashscope/developer-reference/activate-dashscope-and-create-an-api-key',
|
||||
[ApiProvider.Anthropic]: 'https://console.anthropic.com/settings/keys',
|
||||
[ApiProvider.Deepseek]: 'https://platform.deepseek.com/api_keys/',
|
||||
[ApiProvider.OpenAI]: 'https://platform.openai.com/api-keys',
|
||||
[ApiProvider.Google]: 'https://aistudio.google.com/apikey',
|
||||
[ApiProvider.Groq]: 'https://console.groq.com/keys',
|
||||
[ApiProvider.Grok]: 'https://console.x.ai/',
|
||||
[ApiProvider.Ollama]: '', // Ollama 不需要API Key
|
||||
[ApiProvider.OpenAICompatible]: '', // 自定义兼容API,无固定URL
|
||||
};
|
||||
|
||||
// 获取指定provider的API Key获取URL
|
||||
export function getProviderApiUrl(provider: ApiProvider): string {
|
||||
return providerApiUrls[provider] || '';
|
||||
}
|
||||
@ -1453,10 +1453,7 @@ input[type='text'].infio-chat-list-dropdown-item-title-input {
|
||||
* Highlight styles
|
||||
*/
|
||||
.infio-llm-setting-model-item-highlight {
|
||||
background-color: var(--text-highlight-bg);
|
||||
color: var(--text-normal);
|
||||
border-radius: var(--radius-s);
|
||||
padding: 0 2px;
|
||||
}
|
||||
|
||||
.infio-llm-setting-item-control::placeholder {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user