diff --git a/packages/jupyter-ai/src/components/chat-settings.tsx b/packages/jupyter-ai/src/components/chat-settings.tsx index 168d608c4..c59089eb5 100644 --- a/packages/jupyter-ai/src/components/chat-settings.tsx +++ b/packages/jupyter-ai/src/components/chat-settings.tsx @@ -146,31 +146,20 @@ export function ChatSettings(props: ChatSettingsProps): JSX.Element { const newApiKeys: Record = {}; const lmAuth = lmProvider?.auth_strategy; const emAuth = emProvider?.auth_strategy; - if ( - lmAuth?.type === 'env' && - !server.config.api_keys.includes(lmAuth.name) - ) { + if (lmAuth?.type === 'env') { newApiKeys[lmAuth.name] = ''; } if (lmAuth?.type === 'multienv') { lmAuth.names.forEach(apiKey => { - if (!server.config.api_keys.includes(apiKey)) { - newApiKeys[apiKey] = ''; - } + newApiKeys[apiKey] = ''; }); } - - if ( - emAuth?.type === 'env' && - !server.config.api_keys.includes(emAuth.name) - ) { + if (emAuth?.type === 'env') { newApiKeys[emAuth.name] = ''; } if (emAuth?.type === 'multienv') { emAuth.names.forEach(apiKey => { - if (!server.config.api_keys.includes(apiKey)) { - newApiKeys[apiKey] = ''; - } + newApiKeys[apiKey] = ''; }); } @@ -303,89 +292,102 @@ export function ChatSettings(props: ChatSettingsProps): JSX.Element { > Language model - - {showLmLocalId && ( - setLmLocalId(e.target.value)} - fullWidth - /> - )} - {chatHelpMarkdown && ( - - )} - {lmGlobalId && ( - + + {server.lmProviders.providers + .map(lmp => lmp.chat_models.length) + .reduce((partialSum, num) => partialSum + num, 0) > 0 ? ( + + + {showLmLocalId && ( + setLmLocalId(e.target.value)} + fullWidth + /> + )} + {chatHelpMarkdown && ( + + )} + {lmGlobalId && ( + + )} + + ) : ( +

No language models available.

)} {/* Embedding model section */}

Embedding model

- + {server.emProviders.providers.length > 0 ? ( + + ) : ( +

No embedding models available.

+ )} {/* Completer language model section */}

@@ -397,86 +399,100 @@ export function ChatSettings(props: ChatSettingsProps): JSX.Element { selection={clmProvider} />

- - {showClmLocalId && ( - setClmLocalId(e.target.value)} - fullWidth - /> - )} - {completionHelpMarkdown && ( - - )} - {clmGlobalId && ( - + {server.lmProviders.providers + .map(lmp => lmp.completion_models.length) + .reduce((partialSum, num) => partialSum + num, 0) > 0 ? ( + + + {showClmLocalId && ( + setClmLocalId(e.target.value)} + fullWidth + /> + )} + {completionHelpMarkdown && ( + + )} + {clmGlobalId && ( + + )} + + ) : ( +

No Inline Completion models.

)} {/* API Keys section */}

API Keys

{/* API key inputs for newly-used providers */} - {Object.entries(apiKeys).map(([apiKeyName, apiKeyValue], idx) => ( - - setApiKeys(apiKeys => ({ - ...apiKeys, - [apiKeyName]: e.target.value - })) - } - /> - ))} + {Object.entries(apiKeys).length === 0 ? ( +

No API Keys needed for selected model.

+ ) : ( + Object.entries(apiKeys).map(([apiKeyName, apiKeyValue], idx) => + !server.config.api_keys.includes(apiKeyName) ? ( + + setApiKeys(apiKeys => ({ + ...apiKeys, + [apiKeyName]: e.target.value + })) + } + /> + ) : null + ) + )} {/* Pre-existing API keys */}