Skip to content

Commit

Permalink
Merge pull request #60 from kshitij79/kshitij79/BugBash/All-fixes
Browse files Browse the repository at this point in the history
Fix for issues identified during bug bash and Release Notes
  • Loading branch information
dselman authored Nov 1, 2024
2 parents 9b255cd + c6be109 commit 2286065
Show file tree
Hide file tree
Showing 20 changed files with 168 additions and 119 deletions.
43 changes: 15 additions & 28 deletions client/src/copilot/generators/suggestionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,28 @@ import * as vscode from 'vscode';
import { LanguageClient } from 'vscode-languageclient/browser';
import { log } from '../../log';
import { Documents, ModelConfig, PromptConfig } from '../utils/types';
import { DEFAULT_LLM_MODELS, DEFAULT_LLM_ENDPOINTS } from '../utils/constants';
import { DEFAULT_LLM_ENDPOINTS } from '../utils/constants';
import { setLLMHealthStatus } from '../healthCheck';

export async function getSuggestion(client: LanguageClient, documents: Documents, promptConfig: PromptConfig): Promise<string | null> {
const config = vscode.workspace.getConfiguration('cicero-vscode-extension');
const apiKey = config.get<string>('apiKey');
const provider = config.get<string>('provider');
let llmModel = config.get<string>('llmModel');
let apiUrl;

if (!llmModel) {
switch (provider) {
case 'gemini':
llmModel = DEFAULT_LLM_MODELS.GEMINI;
apiUrl = DEFAULT_LLM_ENDPOINTS.GEMINI;
break;
case 'openai':
llmModel = DEFAULT_LLM_MODELS.OPENAI;
apiUrl = DEFAULT_LLM_ENDPOINTS.OPENAI;
break;
case 'mistralai':
llmModel = DEFAULT_LLM_MODELS.MISTRALAI;
apiUrl = DEFAULT_LLM_ENDPOINTS.MISTRALAI;
break;
default:
llmModel = '';
apiUrl = '';
}
let apiUrl;
switch (provider) {
case 'gemini':
apiUrl = DEFAULT_LLM_ENDPOINTS.GEMINI;
break;
case 'openai':
apiUrl = DEFAULT_LLM_ENDPOINTS.OPENAI;
break;
case 'mistral':
apiUrl = DEFAULT_LLM_ENDPOINTS.MISTRALAI;
break;
default:
apiUrl = '';
}

// keys like maxTokens, temperature, topP comes from additionalParams
Expand All @@ -40,16 +34,9 @@ export async function getSuggestion(client: LanguageClient, documents: Documents
llmModel,
apiUrl,
accessToken: apiKey,
additionalParams: {}
additionalParams: {...additionalParams}
};

if (additionalParams) {
modelConfig.additionalParams = {
...modelConfig.additionalParams,
...additionalParams
};
}

try {
log('Generating content...');
const response: string = await client.sendRequest('generateContent', {
Expand Down
10 changes: 7 additions & 3 deletions client/src/copilot/modelGeneratorWizard/modelGeneratorPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export function createFileGeneratorPanel(context: vscode.ExtensionContext, clien
});

currentPanel.onDidChangeViewState(e => {
if (currentPanel) {
preloadFileLists(currentPanel, context);
if (currentPanel.visible) {
preloadFileLists(currentPanel);
}
});

Expand All @@ -53,19 +53,23 @@ export function createFileGeneratorPanel(context: vscode.ExtensionContext, clien
try {
await generateGrammarFile(client, message.filePath);
updateGeneratingState('grammar', false);
vscode.window.showInformationMessage('Grammar file generated successfully');
} catch (error) {
log(`Error generating grammar file: ${error.message}`);
updateGeneratingState('grammar', false, error.message);
vscode.window.showErrorMessage('Error generating grammar file');
}
break;
case FILE_GENERATORS.GENERATE_MODEL_FILE:
updateGeneratingState('model', true);
try {
await generateModelFile(client, message.packageFile, message.grammarFile);
updateGeneratingState('model', false);
vscode.window.showInformationMessage('Model file generated successfully');
} catch (error) {
log(`Error generating model file: ${error.message}`);
updateGeneratingState('model', false, error.message);
vscode.window.showErrorMessage('Error generating model file');
}
break;
case FILE_GENERATORS.REQUEST_FILE_LIST:
Expand All @@ -80,7 +84,7 @@ export function createFileGeneratorPanel(context: vscode.ExtensionContext, clien
currentPanel.webview.html = getWebviewContent(currentPanel.webview, context.extensionUri);
}

async function preloadFileLists(panel: vscode.WebviewPanel, context: vscode.ExtensionContext) {
async function preloadFileLists(panel: vscode.WebviewPanel) {
const mdFiles = await getFileList('md');
const jsonFiles = await getFileList('json');

Expand Down
5 changes: 4 additions & 1 deletion client/src/copilot/quickPick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function registerQuickPickCommand(context: vscode.ExtensionContext, clien
{ label: GENERAL.QUICK_PICK_OPTION_SETTINGS },
{ label: GENERAL.QUICK_PICK_OPTION_SUGGESTIONS },
{ label: GENERAL.QUICK_PICK_OPTION_CHAT_AGENT },
{ label: GENERAL.QUICK_PICK_OPTION_GENERATOR },
{ label: '', kind: vscode.QuickPickItemKind.Separator },
{ label: enableInlineSuggestions ? GENERAL.QUICK_PICK_OPTION_DISABLE_INLINE_SUGGESTIONS : GENERAL.QUICK_PICK_OPTION_ENABLE_INLINE_SUGGESTIONS },
{ label: enableCodeActions ? GENERAL.QUICK_PICK_OPTION_DISABLE_CODE_ACTIONS : GENERAL.QUICK_PICK_OPTION_ENABLE_CODE_ACTIONS }
Expand All @@ -28,8 +29,10 @@ export function registerQuickPickCommand(context: vscode.ExtensionContext, clien
vscode.commands.executeCommand('cicero-vscode-extension.configureSettings');
} else if (selection?.label === GENERAL.QUICK_PICK_OPTION_SUGGESTIONS) {
vscode.commands.executeCommand('cicero-vscode-extension.startPromptProviderUI');
} else if (selection?.label === 'Open Chat Agent') {
} else if (selection?.label === GENERAL.QUICK_PICK_OPTION_CHAT_AGENT) {
createOrShowChatPanel(client, context);
} else if (selection?.label === GENERAL.QUICK_PICK_OPTION_GENERATOR) {
vscode.commands.executeCommand('cicero-vscode-extension.openFileGenerator');
} else if (selection?.label === GENERAL.QUICK_PICK_OPTION_ENABLE_INLINE_SUGGESTIONS || selection?.label === GENERAL.QUICK_PICK_OPTION_DISABLE_INLINE_SUGGESTIONS) {
vscode.commands.executeCommand('cicero-vscode-extension.toggleInlineSuggestions');
} else if (selection?.label === GENERAL.QUICK_PICK_OPTION_ENABLE_CODE_ACTIONS || selection?.label === GENERAL.QUICK_PICK_OPTION_DISABLE_CODE_ACTIONS) {
Expand Down
58 changes: 42 additions & 16 deletions client/src/copilot/settingsView/configSetting.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as vscode from 'vscode';
import { ASSETS, CONFIG_DEFAULTS } from '../utils/constants';
import { ASSETS, CONFIG_DEFAULTS, COPILOT_SETTINGS } from '../utils/constants';
import { htmlTemplate } from './templates/settingsView';
import { cssTemplate } from './templates/settingsStyle';
import { scriptTemplate } from './templates/settingScript';
import { checkCopilotHealth, copilotHealthStatus } from '../healthCheck';
import { log } from '../../log';

export function createSettingsWebview(context: vscode.ExtensionContext, client: any) {
const column = vscode.ViewColumn.Beside;
Expand All @@ -25,35 +26,60 @@ export function createSettingsWebview(context: vscode.ExtensionContext, client:
panel.iconPath = iconPath;

const config = vscode.workspace.getConfiguration('cicero-vscode-extension');
const configValues = {
apiKey: config.get<string>('apiKey', CONFIG_DEFAULTS.apiKey),
apiUrl: config.get<string>('apiUrl', CONFIG_DEFAULTS.apiUrl),
provider: config.get<string>('provider', CONFIG_DEFAULTS.provider),
llmModel: config.get<string>('llmModel', CONFIG_DEFAULTS.llmModel),
additionalParams: JSON.stringify(config.get<object>('additionalParams', CONFIG_DEFAULTS.additionalParams), null, 2)
};

panel.webview.html = htmlTemplate(cssTemplate, scriptTemplate, configValues);

panel.webview.onDidReceiveMessage(async message => {
switch (message.command) {
case 'saveSettings':
const target = message.scope === 'workspace' ? vscode.ConfigurationTarget.Workspace : vscode.ConfigurationTarget.Global;

if (message.scope === 'workspace' && !vscode.workspace.workspaceFolders) {
vscode.window.showErrorMessage(COPILOT_SETTINGS.CONNECTION_FAILED);
panel.webview.postMessage({ command: 'showError', message: COPILOT_SETTINGS.WORKSPACE_REQUIRED });
return;
}

const sanitizedLLMModel = message.llmModel.trim();

await config.update('apiKey', message.apiKey, target);
await config.update('provider', message.provider, target);
await config.update('llmModel', message.llmModel, target);
await config.update('llmModel', sanitizedLLMModel, target);
await config.update('additionalParams', JSON.parse(message.additionalParams), target);

vscode.window.showInformationMessage('Configuration updated successfully!');
vscode.window.showInformationMessage(COPILOT_SETTINGS.CONFIG_UPDATED_SUCCESS);

await checkCopilotHealth(client)
if (copilotHealthStatus === true)
vscode.window.showInformationMessage('Connection to Copilot established successfully!');
else
vscode.window.showErrorMessage('Connection to Copilot failed!');
log('Copilot settings updated'+copilotHealthStatus);
if (copilotHealthStatus === true){
vscode.window.showInformationMessage(COPILOT_SETTINGS.CONNECTION_SUCCESS);
panel.webview.postMessage({ command: 'hideError' });
}
else {
vscode.window.showErrorMessage(COPILOT_SETTINGS.CONNECTION_FAILED);
panel.webview.postMessage({ command: 'showError', message: COPILOT_SETTINGS.CONNECTION_FAILED_MESSAGE });
}

break;
}
});

panel.onDidChangeViewState(() => {
if (panel.visible) {
let config = vscode.workspace.getConfiguration('cicero-vscode-extension');
const updatedConfigValues = {
apiKey: config.get<string>('apiKey', CONFIG_DEFAULTS.apiKey),
apiUrl: config.get<string>('apiUrl', CONFIG_DEFAULTS.apiUrl),
provider: config.get<string>('provider', CONFIG_DEFAULTS.provider),
llmModel: config.get<string>('llmModel', CONFIG_DEFAULTS.llmModel),
additionalParams: JSON.stringify(config.get<object>('additionalParams', CONFIG_DEFAULTS.additionalParams), null, 2)
};
panel.webview.html = htmlTemplate(cssTemplate, scriptTemplate, updatedConfigValues);
}
});

panel.onDidDispose(() => {
panel.dispose();
});

panel.options
}

33 changes: 33 additions & 0 deletions client/src/copilot/settingsView/templates/settingScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,37 @@ export const scriptTemplate = `
}
}
function updateLLMModel() {
const provider = document.getElementById('provider').value;
const llmModelInput = document.getElementById('llmModel');
let defaultModel = '';
switch (provider) {
case 'gemini':
defaultModel = 'gemini-pro';
break;
case 'openai':
defaultModel = 'gpt-3.5-turbo';
break;
case 'mistral':
defaultModel = 'mistral-large-latest';
break;
}
llmModelInput.value = defaultModel;
}
window.addEventListener('message', event => {
const message = event.data;
const errorElement = document.getElementById('copilotHealthError');
switch (message.command) {
case 'showError':
errorElement.innerText = message.message;
errorElement.style.display = 'block';
break;
case 'hideError':
errorElement.style.display = 'none';
break;
}
});
`;
2 changes: 1 addition & 1 deletion client/src/copilot/settingsView/templates/settingsStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const cssTemplate = `
color: var(--input-foreground);
}
.error-message { /* New class for error messages */
color: var(--error-foreground);
color: var(--vscode-list-errorForeground);
margin-top: 5px;
font-size: 0.9em;
display: none; /* Hidden by default */
Expand Down
9 changes: 5 additions & 4 deletions client/src/copilot/settingsView/templates/settingsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const htmlTemplate = (css: string, script: string, configValues: { [key:
<label for="provider">Provider <span class="required-asterisk">*</span></label>
<p>Select the AI provider.</p>
<div class="select-container">
<select id="provider" style="width: 100%;">
<select id="provider" style="width: 100%;" onchange="updateLLMModel()">
<option value="gemini" ${configValues.provider === 'gemini' ? 'selected' : ''}>Gemini</option>
<option value="openai" ${configValues.provider === 'openai' ? 'selected' : ''}>OpenAI</option>
<option value="mistral" ${configValues.provider === 'mistral' ? 'selected' : ''}>MistralAI</option>
Expand All @@ -39,7 +39,7 @@ export const htmlTemplate = (css: string, script: string, configValues: { [key:
<span class="error-message" id="providerError"></span>
</div>
<div class="form-group">
<label for="llmModel">LLM Model</label>
<label for="llmModel">LLM Model <span class="required-asterisk">*</span></label>
<p>The specific language model (default: Gemini - gemini-pro, OpenAI - gpt-3.5-turbo, MistralAI - mistral-large-latest).</p>
<input type="text" id="llmModel" value="${configValues.llmModel}">
<span class="error-message" id="llmModelError"></span>
Expand All @@ -54,13 +54,14 @@ export const htmlTemplate = (css: string, script: string, configValues: { [key:
<p>Select whether to save the settings globally (for all projects) or for the current workspace only.</p>
<div class="select-container">
<select id="scope" style="width: 100%;">
<option value="workspace" selected>Workspace</option>
<option value="global">Global</option>
<option value="workspace">Workspace</option>
<option value="global" selected>Global</option>
</select>
<i class="codicon codicon-chevron-down"></i>
</div>
</div>
<button class="button" onclick="saveSettings()">Save Settings</button>
<span class="error-message" id="copilotHealthError"></span>
</div>
<script>
${script}
Expand Down
14 changes: 11 additions & 3 deletions client/src/copilot/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export const GENERAL = {
QUICK_PICK_STATUS_OK: '$(copilot) Status: Ready',
QUICK_PICK_STATUS_ERROR: '$(copilot) Status: Configuration Error',
QUICK_PICK_PLACEHOLDER: 'Choose an action',
QUICK_PICK_OPTION_CHAT_AGENT: 'Open Chat Agent',
QUICK_PICK_OPTION_CHAT_AGENT: '$(comment-discussion) Open Chat Agent',
QUICK_PICK_OPTION_GENERATOR: '$(wand) Model Generation Wizard',
QUICK_PICK_OPTION_SETTINGS: '$(gear) Open Copilot Settings',
QUICK_PICK_OPTION_SUGGESTIONS: '$(copilot) Get Inline Suggestions',
QUICK_PICK_OPTION_ENABLE_INLINE_SUGGESTIONS: 'Enable Inline Suggestions',
Expand Down Expand Up @@ -87,7 +88,7 @@ export const DEFAULT_LLM_MODELS = {
export const DEFAULT_LLM_ENDPOINTS = {
GEMINI: 'https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent',
OPENAI: 'https://api.openai.com/v1/chat/completions',
MISTRALAI: 'https://api.mistralai.com/v1/chat/completions'
MISTRALAI: 'https://api.mistral.ai/v1/chat/completions'
};

// Constants for Panel Manager
Expand Down Expand Up @@ -120,4 +121,11 @@ export const ASSETS = {
ACCORD_LOGO_DARK: 'assets/dark/accord_logo.png',
ACCORD_LOGO_LIGHT: 'assets/light/accord_logo.png'
};


export const COPILOT_SETTINGS = {
CONFIG_UPDATED_SUCCESS: 'Configuration updated successfully!',
CONNECTION_SUCCESS: 'Connection to Copilot established successfully!',
CONNECTION_FAILED: 'Connection to Copilot failed!',
CONNECTION_FAILED_MESSAGE: 'Connection to Copilot failed! Please check your API key, billing status, and LLM model.',
WORKSPACE_REQUIRED: 'Cannot save settings with "Workspace" scope because no workspace is open. Please save them as Global settings.'
};
25 changes: 0 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,28 +167,6 @@
"title": "Open File Generator"
}
],
"viewsContainers": {
"activitybar": [
{
"id": "chat",
"title": "Chat",
"icon": "comments-view-icon"
},
{
"id": "fileGenerator",
"title": "File Generator",
"icon": "file-generator-view-icon"
}
]
},
"views": {
"chat": [
{
"id": "chatPanel",
"name": "Accord Assistant"
}
]
},
"submenus": [
{
"id": "accordProjectSubmenu",
Expand Down Expand Up @@ -239,9 +217,6 @@
},
{
"command": "cicero-vscode-extension.configureSettings"
},
{
"command": "cicero-vscode-extension.openFileGenerator"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/commands/commandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export async function loadProjectFiles(fileExtensions:string[]) {
log(`Document count: ${GLOBAL_STATE.documents.all().length}`);
GLOBAL_STATE.documents.all().forEach(async document => {
const change: TextDocumentChangeEvent<TextDocument> = { document };
handleConcertoDocumentChange(GLOBAL_STATE, change);
await handleConcertoDocumentChange(GLOBAL_STATE, change);
});
} else {
log('GLOBAL_STATE.connection is null');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function getConcertoInlineTemplate(beforeCursor: string, afterCursor: str
role: "user"
},
{
content: `${beforeCursor} /* Analyze the following code in concerto and complete the code based on the context. ${instruction}. Remove this commented instruction in complete code. */ ${afterCursor}`,
content: `${beforeCursor} /* The user's cursor is here. Analyze the following code in concerto language and provide a suggestion to complete it according to this instruction from user: ${instruction}. Only add new code at the cursor position without modifying the existing code. Remove this comment in the final output. */ ${afterCursor}. Start output from here ${beforeCursor}`,
role: "user"
}
];
Expand Down
Loading

0 comments on commit 2286065

Please sign in to comment.