Skip to content

Commit

Permalink
fix settings save
Browse files Browse the repository at this point in the history
  • Loading branch information
dlqqq committed Aug 5, 2024
1 parent 4d69962 commit 970cd50
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions packages/jupyter-ai/src/components/chat-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,31 @@ export function ChatSettings(props: ChatSettingsProps): JSX.Element {
const newApiKeys: Record<string, string> = {};
const lmAuth = lmProvider?.auth_strategy;
const emAuth = emProvider?.auth_strategy;
if (lmAuth?.type === 'env') {
if (
lmAuth?.type === 'env' &&
!server.config.api_keys.includes(lmAuth.name)
) {
newApiKeys[lmAuth.name] = '';
}
if (lmAuth?.type === 'multienv') {
lmAuth.names.forEach(apiKey => {
newApiKeys[apiKey] = '';
if (!server.config.api_keys.includes(apiKey)) {
newApiKeys[apiKey] = '';
}
});
}
if (emAuth?.type === 'env') {

if (
emAuth?.type === 'env' &&
!server.config.api_keys.includes(emAuth.name)
) {
newApiKeys[emAuth.name] = '';
}
if (emAuth?.type === 'multienv') {
emAuth.names.forEach(apiKey => {
newApiKeys[apiKey] = '';
if (!server.config.api_keys.includes(apiKey)) {
newApiKeys[apiKey] = '';
}
});
}

Expand Down Expand Up @@ -472,27 +483,21 @@ export function ChatSettings(props: ChatSettingsProps): JSX.Element {
{/* API Keys section */}
<h2 className="jp-ai-ChatSettings-header">API Keys</h2>
{/* API key inputs for newly-used providers */}
{Object.entries(apiKeys).length === 0 ? (
<p>No API Keys needed for selected model.</p>
) : (
Object.entries(apiKeys).map(([apiKeyName, apiKeyValue], idx) =>
!server.config.api_keys.includes(apiKeyName) ? (
<TextField
key={idx}
label={apiKeyName}
value={apiKeyValue}
fullWidth
type="password"
onChange={e =>
setApiKeys(apiKeys => ({
...apiKeys,
[apiKeyName]: e.target.value
}))
}
/>
) : null
)
)}
{Object.entries(apiKeys).map(([apiKeyName, apiKeyValue], idx) => (
<TextField
key={idx}
label={apiKeyName}
value={apiKeyValue}
fullWidth
type="password"
onChange={e =>
setApiKeys(apiKeys => ({
...apiKeys,
[apiKeyName]: e.target.value
}))
}
/>
))}
{/* Pre-existing API keys */}
<ExistingApiKeys
alert={apiKeysAlert}
Expand Down

0 comments on commit 970cd50

Please sign in to comment.