Skip to content

assistant: handle no chat providers and add provider filter dropdown in modal #8292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions extensions/positron-assistant/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@
"category": "%commands.category%",
"enablement": "config.positron.assistant.enable"
},
{
"command": "positron-assistant.configureChatModels",
"title": "%commands.configureChatModels.title%",
"category": "%commands.category%",
"enablement": "config.positron.assistant.enable"
},
{
"command": "positron-assistant.configureCompletionModels",
"title": "%commands.configureCompletionModels.title%",
"category": "%commands.category%",
"enablement": "config.positron.assistant.enable"
},
{
"command": "positron-assistant.logStoredModels",
"title": "%commands.logStoredModels.title%",
Expand Down
2 changes: 2 additions & 0 deletions extensions/positron-assistant/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"displayName": "Positron Assistant",
"description": "Provides default assistant and language models for Positron.",
"commands.configureModels.title": "Configure Language Model Providers",
"commands.configureChatModels.title": "Configure Language Model Providers: Chat",
"commands.configureCompletionModels.title": "Configure Language Model Providers: Completions",
"commands.logStoredModels.title": "Log the stored language models",
"commands.copilot.signin.title": "Copilot Sign In",
"commands.copilot.signout.title": "Copilot Sign Out",
Expand Down
50 changes: 27 additions & 23 deletions extensions/positron-assistant/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export async function getEnabledProviders(): Promise<string[]> {
return enabledProviders;
}

export async function showConfigurationDialog(context: vscode.ExtensionContext, storage: SecretStorage) {
export async function showConfigurationDialog(context: vscode.ExtensionContext, storage: SecretStorage, providerTypes?: positron.PositronLanguageModelType[]): Promise<void> {

// Gather model sources; ignore disabled providers
const enabledProviders = await getEnabledProviders();
Expand All @@ -147,28 +147,32 @@ export async function showConfigurationDialog(context: vscode.ExtensionContext,
});

// Show a modal asking user for configuration details
return positron.ai.showLanguageModelConfig(sources, async (userConfig, action) => {
switch (action) {
case 'save':
await saveModel(userConfig, sources, storage, context);
break;
case 'delete':
await deleteConfigurationByProvider(context, storage, userConfig.provider);
break;
case 'oauth-signin':
await oauthSignin(userConfig, sources, storage, context);
break;
case 'oauth-signout':
await oauthSignout(userConfig, sources, storage, context);
break;
case 'cancel':
// User cancelled the dialog, clean up any pending operations
CopilotService.instance().cancelCurrentOperation();
break;
default:
throw new Error(vscode.l10n.t('Invalid Language Model action: {0}', action));
}
});
return positron.ai.showLanguageModelConfig(
sources,
async (userConfig, action) => {
switch (action) {
case 'save':
await saveModel(userConfig, sources, storage, context);
break;
case 'delete':
await deleteConfigurationByProvider(context, storage, userConfig.provider);
break;
case 'oauth-signin':
await oauthSignin(userConfig, sources, storage, context);
break;
case 'oauth-signout':
await oauthSignout(userConfig, sources, storage, context);
break;
case 'cancel':
// User cancelled the dialog, clean up any pending operations
CopilotService.instance().cancelCurrentOperation();
break;
default:
throw new Error(vscode.l10n.t('Invalid Language Model action: {0}', action));
}
},
providerTypes
);

}

Expand Down
10 changes: 8 additions & 2 deletions extensions/positron-assistant/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,14 @@ async function registerModelWithAPI(modelConfig: ModelConfig, context: vscode.Ex

function registerConfigureModelsCommand(context: vscode.ExtensionContext, storage: SecretStorage) {
context.subscriptions.push(
vscode.commands.registerCommand('positron-assistant.configureModels', async () => {
await showConfigurationDialog(context, storage);
vscode.commands.registerCommand('positron-assistant.configureModels', async (providerTypes?: positron.PositronLanguageModelType[]) => {
await showConfigurationDialog(context, storage, providerTypes);
}),
vscode.commands.registerCommand('positron-assistant.configureChatModels', async () => {
await showConfigurationDialog(context, storage, [positron.PositronLanguageModelType.Chat]);
}),
vscode.commands.registerCommand('positron-assistant.configureCompletionModels', async () => {
await showConfigurationDialog(context, storage, [positron.PositronLanguageModelType.Completion]);
}),
vscode.commands.registerCommand('positron-assistant.logStoredModels', async () => {
logStoredModels(context);
Expand Down
1 change: 1 addition & 0 deletions src/positron-dts/positron.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2070,6 +2070,7 @@ declare module 'positron' {
export function showLanguageModelConfig(
sources: LanguageModelSource[],
onAction: (config: LanguageModelConfig, action: string) => Thenable<void>,
providerTypes?: PositronLanguageModelType[],
): Thenable<void>;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Licensed under the Elastic License 2.0. See LICENSE.txt for license information.
*--------------------------------------------------------------------------------------------*/

import { PositronLanguageModelType } from 'positron';
import { Disposable, DisposableMap } from '../../../../base/common/lifecycle.js';
import { revive } from '../../../../base/common/marshalling.js';
import { URI, UriComponents } from '../../../../base/common/uri.js';
Expand Down Expand Up @@ -50,7 +51,7 @@ export class MainThreadAiFeatures extends Disposable implements MainThreadAiFeat
* Show a modal dialog for language model configuration. Return a promise resolving to the
* configuration saved by the user.
*/
$languageModelConfig(id: string, sources: IPositronLanguageModelSource[]): Thenable<void> {
$languageModelConfig(id: string, sources: IPositronLanguageModelSource[], providerTypes?: PositronLanguageModelType[]): Thenable<void> {
return new Promise((resolve, reject) => {
this._positronAssistantService.showLanguageModelModalDialog(
sources,
Expand All @@ -59,6 +60,7 @@ export class MainThreadAiFeatures extends Disposable implements MainThreadAiFeat
resolve();
},
() => this._proxy.$onCompleteLanguageModelConfig(id),
providerTypes,
);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ export function createPositronApiFactoryAndRegisterActors(accessor: ServicesAcce
getCurrentPlotUri(): Thenable<string | undefined> {
return extHostAiFeatures.getCurrentPlotUri();
},
showLanguageModelConfig(sources: positron.ai.LanguageModelSource[], onAction: (config: positron.ai.LanguageModelConfig, action: string) => Thenable<void>): Thenable<void> {
return extHostAiFeatures.showLanguageModelConfig(sources, onAction);
showLanguageModelConfig(sources: positron.ai.LanguageModelSource[], onAction: (config: positron.ai.LanguageModelConfig, action: string) => Thenable<void>, providerTypes?: positron.PositronLanguageModelType[]): Thenable<void> {
return extHostAiFeatures.showLanguageModelConfig(sources, onAction, providerTypes);
},
registerChatAgent(agentData: positron.ai.ChatAgentData): Thenable<vscode.Disposable> {
return extHostAiFeatures.registerChatAgent(extension, agentData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { createProxyIdentifier, IRPCProtocol, SerializableObjectWithBuffers } fr
import { MainContext, IWebviewPortMapping, WebviewExtensionDescription, IChatProgressDto, ExtHostQuickOpenShape } from '../extHost.protocol.js';
import { URI, UriComponents } from '../../../../base/common/uri.js';
import { IEditorContext } from '../../../services/frontendMethods/common/editorContext.js';
import { RuntimeClientType, LanguageRuntimeSessionChannel } from './extHostTypes.positron.js';
import { RuntimeClientType, LanguageRuntimeSessionChannel, PositronLanguageModelType } from './extHostTypes.positron.js';
import { EnvironmentVariableAction, LanguageRuntimeDynState, RuntimeSessionMetadata } from 'positron';
import { IDriverMetadata, Input } from '../../../services/positronConnections/common/interfaces/positronConnectionsDriver.js';
import { IAvailableDriverMethods } from '../../browser/positron/mainThreadConnections.js';
Expand Down Expand Up @@ -151,7 +151,7 @@ export interface MainThreadAiFeaturesShape {
$getCurrentPlotUri(): Promise<string | undefined>;
$getPositronChatContext(request: IChatRequestData): Thenable<IPositronChatContext>;
$responseProgress(sessionId: string, dto: IChatProgressDto): void;
$languageModelConfig(id: string, sources: IPositronLanguageModelSource[]): Thenable<void>;
$languageModelConfig(id: string, sources: IPositronLanguageModelSource[], providerTypes?: PositronLanguageModelType[]): Thenable<void>;
$getSupportedProviders(): Thenable<string[]>;
$addLanguageModelConfig(source: IPositronLanguageModelSource): void;
$removeLanguageModelConfig(source: IPositronLanguageModelSource): void;
Expand Down
5 changes: 3 additions & 2 deletions src/vs/workbench/api/common/positron/extHostAiFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { IChatRequestData, IPositronChatContext, IPositronLanguageModelConfig, I
import { IExtensionDescription } from '../../../../platform/extensions/common/extensions.js';
import { generateUuid } from '../../../../base/common/uuid.js';
import { ChatAgentLocation, ChatMode } from '../../../contrib/chat/common/constants.js';
import { PositronLanguageModelType } from './extHostTypes.positron.js';

export class ExtHostAiFeatures implements extHostProtocol.ExtHostAiFeaturesShape {

Expand Down Expand Up @@ -46,12 +47,12 @@ export class ExtHostAiFeatures implements extHostProtocol.ExtHostAiFeaturesShape
});
}

async showLanguageModelConfig(sources: positron.ai.LanguageModelSource[], onAction: (config: positron.ai.LanguageModelConfig, action: string) => Thenable<void>): Promise<void> {
async showLanguageModelConfig(sources: positron.ai.LanguageModelSource[], onAction: (config: positron.ai.LanguageModelConfig, action: string) => Thenable<void>, providerTypes?: PositronLanguageModelType[]): Promise<void> {
const id = generateUuid();
this._languageModelRequestRegistry.set(id, onAction);

try {
await this._proxy.$languageModelConfig(id, sources);
await this._proxy.$languageModelConfig(id, sources, providerTypes);
} catch (err) {
throw err;
}
Expand Down
25 changes: 22 additions & 3 deletions src/vs/workbench/contrib/chat/browser/chatWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -741,13 +741,16 @@ export class ChatWidget extends Disposable implements IChatWidget {
if (!this.configurationService.getValue('positron.assistant.enable')) {
welcomeTitle = localize('positronAssistant.comingSoonTitle', "Coming Soon");
welcomeText = localize('positronAssistant.comingSoonMessage', "Positron Assistant is under development and will be available in a future version of Positron.\n");
} else if (this.languageModelsService.getLanguageModelIds().length === 0) {
} else if (!this.languageModelsService.currentProvider) {
welcomeTitle = localize('positronAssistant.gettingStartedTitle', "Set Up Positron Assistant");
const addLanguageModelMessage = localize('positronAssistant.addLanguageModelMessage', "Add Language Model Provider");
firstLinkToButton = true;
// create a multi-line message
welcomeText = localize('positronAssistant.welcomeMessage', "To use Positron Assistant you must first select and authenticate with a language model provider.\n");
welcomeText += `\n\n[${addLanguageModelMessage}](command:positron-assistant.configureModels)`;
welcomeText = localize('positronAssistant.welcomeMessage', "To use Positron Assistant you must first select and authenticate with a language model provider that supports Chat.\n");
welcomeText += `\n\n[${addLanguageModelMessage}](command:positron-assistant.configureChatModels)`;

// Disable input for chat
this.toggleChatInputVisibility(false);
} else {
const guideLinkMessage = localize('positronAssistant.guideLinkMessage', "Positron Assistant User Guide");
welcomeTitle = localize('positronAssistant.welcomeMessageTitle', "Welcome to Positron Assistant");
Expand All @@ -765,6 +768,9 @@ Click on $(attach) or type \`#\` to add context, such as files to your chat.
Type \`/\` to use predefined commands such as \`/help\` or \`/quarto\`.`,
), { supportThemeIcons: true, isTrusted: true });
welcomeText = welcomeText.replace('{guide-link}', `[${guideLinkMessage}](https://positron.posit.co/assistant)`);

// Enable input for chat
this.toggleChatInputVisibility(true);
}

dom.clearNode(this.welcomeMessageContainer);
Expand Down Expand Up @@ -807,6 +813,19 @@ Type \`/\` to use predefined commands such as \`/help\` or \`/quarto\`.`,
dom.setVisibility(numItems !== 0, this.listContainer);
}
}

private toggleChatInputVisibility(visible: boolean): void {
const input = this.container.querySelector('.interactive-input-part') as HTMLElement;
if (!input) {
console.error('ChatWidget#toggleChatInputVisibility: no input part found');
}
if (visible) {
dom.show(input);
this.inputPart.focus();
} else {
dom.hide(input);
}
}
// --- End Positron ---

private getWelcomeViewContent(): IChatWelcomeMessageContent {
Expand Down
52 changes: 38 additions & 14 deletions src/vs/workbench/contrib/chat/browser/positron/chatActionBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ interface ChatActionBarProps {
onModelSelect: (newLanguageModel: IPositronChatProvider | undefined) => void;
}

const addModelProviderLabel = () => localize('positronChatSelector.addModelProvider', 'Add Model Provider...');
const addModelProviderTooltip = () => localize('positronChatSelector.addModelProviderTooltip', 'Add a Language Model Provider');
const addChatModelProviderLabel = () => localize('positronChatSelector.addChatModelProvider', 'Add Chat Model Provider...');
const addCompletionsModelProviderLabel = () => localize('positronChatSelector.addCompletionsModelProvider', 'Add Completions Model Provider...');
const configureModelProvidersLabel = () => localize('positronChatSelector.configureModelProviders', 'Configure All Model Providers...');
const addModelProviderTooltip = () => localize('positronChatSelector.addModelProviderTooltip', 'Add a Chat Model Provider');

export const ChatActionBar: React.FC<ChatActionBarProps> = ((props) => {
const positronActionBarContext = usePositronActionBarContext();
Expand All @@ -47,27 +49,49 @@ export const ChatActionBar: React.FC<ChatActionBarProps> = ((props) => {
});
});

const otherActions = [{
id: 'add-model-provider',
label: addModelProviderLabel(),
enabled: true,
class: undefined,
tooltip: addModelProviderTooltip(),
run: async () => {
await positronActionBarContext.commandService.executeCommand('positron-assistant.configureModels');
}
}];
const otherActions = [
{
id: 'add-chat-model-provider',
label: addChatModelProviderLabel(),
enabled: true,
class: undefined,
tooltip: addModelProviderTooltip(),
run: async () => {
await positronActionBarContext.commandService.executeCommand('positron-assistant.configureChatModels');
}
},
{
id: 'add-completion-model-provider',
label: addCompletionsModelProviderLabel(),
enabled: true,
class: undefined,
tooltip: addModelProviderTooltip(),
run: async () => {
await positronActionBarContext.commandService.executeCommand('positron-assistant.configureCompletionModels');
}
},
{
id: 'configure-model-providers',
label: configureModelProvidersLabel(),
enabled: true,
class: undefined,
tooltip: addModelProviderTooltip(),
run: async () => {
await positronActionBarContext.commandService.executeCommand('positron-assistant.configureModels');
}
},
];

return Separator.join(providerActions, otherActions);
}, [props, providers, currentProvider, positronActionBarContext.commandService]);

const renderCurrentProvider = () => {
if (!currentProvider) {
return <ActionBarButton
label={addModelProviderLabel()}
label={addChatModelProviderLabel()}
tooltip={addModelProviderTooltip()}
onPressed={async () => {
await positronActionBarContext.commandService.executeCommand('positron-assistant.configureModels');
await positronActionBarContext.commandService.executeCommand('positron-assistant.configureChatModels');
}}
/>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,13 @@ interface LanguageModelConfigComponentProps {
type IProvider = IPositronLanguageModelSource['provider'];

const positEulaLabel = localize('positron.languageModelConfig.positEula', 'Posit EULA');
const completionsOnlyEmphasizedText = localize('positron.languageModelConfig.completionsOnly', 'code completions only');
const providerTermsOfServiceLabel = localize('positron.languageModelConfig.termsOfService', 'Terms of Service');
const providerPrivacyPolicyLabel = localize('positron.languageModelConfig.privacyPolicy', 'Privacy Policy');

const apiKeyInputLabel = localize('positron.languageModelConfig.apiKeyInputLabel', 'API Key');
const signInButtonLabel = localize('positron.languageModelConfig.signIn', 'Sign in');
const signOutButtonLabel = localize('positron.languageModelConfig.signOut', 'Sign out');

function getProviderCompletionsOnlyNoticeText(providerDisplayName: string) {
return localize(
'positron.languageModelConfig.completionsOnlyNotice',
'{0} functions for {code-completions-only} in Positron at this time.',
providerDisplayName,
);
}

function getProviderTermsOfServiceText(providerDisplayName: string) {
return localize(
'positron.languageModelConfig.tos',
Expand Down Expand Up @@ -81,19 +72,6 @@ function getProviderPrivacyPolicyLink(providerId: string) {
}
}

function getProviderCompletionsOnlyNotice(provider: IProvider) {
if (provider.id === 'copilot') {
const text = getProviderCompletionsOnlyNoticeText(provider.displayName);
return interpolate(
text,
(key) => key === 'code-completions-only' ?
<strong>{completionsOnlyEmphasizedText}</strong> :
undefined
);
}
return undefined;
}

/**
* Interpolates placeholders in a string with React nodes.
*
Expand Down Expand Up @@ -190,8 +168,6 @@ const SignInButton = (props: { authMethod: AuthMethod, authStatus: AuthStatus, o
}

const ProviderNotice = (props: { provider: IProvider }) => {
const completionsOnlyNotice = getProviderCompletionsOnlyNotice(props.provider);

const termsOfServiceText = getProviderTermsOfServiceText(props.provider.displayName);
const termsOfService = interpolate(
termsOfServiceText,
Expand Down Expand Up @@ -220,7 +196,6 @@ const ProviderNotice = (props: { provider: IProvider }) => {
const disclaimerText = getProviderUsageDisclaimerText(props.provider.displayName);

return <div className='language-model-dialog-tos' id='model-tos'>
{completionsOnlyNotice ? <p>{completionsOnlyNotice}</p> : null}
<p>{termsOfService}</p>
<p>{disclaimerText}</p>
</div>;
Expand Down
Loading
Loading