Merge pull request #343 from devchat-ai/install_command_python
clear Command python install functions
This commit is contained in:
commit
1e09a858a5
25
package.json
25
package.json
@ -533,13 +533,7 @@
|
|||||||
"order": 14,
|
"order": 14,
|
||||||
"description": "Limit the number of prompts in the chat view."
|
"description": "Limit the number of prompts in the chat view."
|
||||||
},
|
},
|
||||||
"DevChat.askcode.supportedFileTypes": {
|
"DevChat.PythonForChat": {
|
||||||
"type": "string",
|
|
||||||
"default": ".+\\.js$, .+\\.ts$, .+\\.jsx$, .+\\.tsx$, .+\\.java$, .+\\.py$, .+\\.go$, .+\\.rb$, .+\\.php$, .+\\.cpp$, .+\\.c$, .+\\.cs$, .+\\.swift$, .+\\.rs$, .+\\.sh$, .+\\.bash$, .+\\.zsh$, .+\\.m$, .+\\.mm$, .+\\.h$, .+\\.hpp$, .+\\.hh$, .+\\.html$, .+\\.htm$, .+\\.xhtml$, .+\\.xml$, .+\\.css$, .+\\.scss$, .+\\.sass$, .+\\.less$, .+\\.json$, .+\\.yaml$, .+\\.yml$, .+\\.toml$, .+\\.ini$, .+\\.md$, .+\\.markdown$, .+\\.txt$, .+\\.csv$, .+\\.sql$, .+\\.sqlite$, .+\\.db$, .+\\.hql$, .+\\.psql$, .+\\.pgsql$, .+\\.plpgsql$",
|
|
||||||
"order": 15,
|
|
||||||
"description": "Comma-separated list of regular expressions for supported file types for analysis."
|
|
||||||
},
|
|
||||||
"DevChat.PythonPath": {
|
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "",
|
"default": "",
|
||||||
"input": {
|
"input": {
|
||||||
@ -552,7 +546,7 @@
|
|||||||
},
|
},
|
||||||
"description": "Which Python interpreter to use with DevChat?"
|
"description": "Which Python interpreter to use with DevChat?"
|
||||||
},
|
},
|
||||||
"DevChat.PythonVirtualEnv": {
|
"DevChat.PythonForCommands": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "",
|
"default": "",
|
||||||
"description": "Path to the Python virtual environment for AskCode."
|
"description": "Path to the Python virtual environment for AskCode."
|
||||||
@ -659,16 +653,6 @@
|
|||||||
"command": "devchat.askForFile_chinese",
|
"command": "devchat.askForFile_chinese",
|
||||||
"title": "添加到DevChat"
|
"title": "添加到DevChat"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"command": "DevChat.AskCodeIndexStart",
|
|
||||||
"title": "Start AskCode Index",
|
|
||||||
"category": "DevChat"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"command": "DevChat.AskCodeIndexStop",
|
|
||||||
"title": "Stop AskCode Index",
|
|
||||||
"category": "DevChat"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"command": "DevChat.InstallCommands",
|
"command": "DevChat.InstallCommands",
|
||||||
"title": "Install slash commands",
|
"title": "Install slash commands",
|
||||||
@ -678,6 +662,11 @@
|
|||||||
"command": "DevChat.UpdataChatModels",
|
"command": "DevChat.UpdataChatModels",
|
||||||
"title": "Update Chat Models",
|
"title": "Update Chat Models",
|
||||||
"category": "DevChat"
|
"category": "DevChat"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "DevChat.InstallCommandPython",
|
||||||
|
"title": "Install Python for Commands",
|
||||||
|
"category": "DevChat"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"menus": {
|
"menus": {
|
||||||
|
@ -83,10 +83,10 @@ export class CustomActions {
|
|||||||
const tempDir = await createTempSubdirectory('devchat/action');
|
const tempDir = await createTempSubdirectory('devchat/action');
|
||||||
const tempFile = path.join(tempDir, 'apply.json');
|
const tempFile = path.join(tempDir, 'apply.json');
|
||||||
|
|
||||||
if (UiUtilWrapper.getConfiguration('DevChat', 'PythonVirtualEnv')) {
|
if (UiUtilWrapper.getConfiguration('DevChat', 'PythonForCommands')) {
|
||||||
args['PythonVirtualEnv'] = UiUtilWrapper.getConfiguration('DevChat', 'PythonVirtualEnv')!;
|
args['PythonForCommands'] = UiUtilWrapper.getConfiguration('DevChat', 'PythonForCommands')!;
|
||||||
} else {
|
} else {
|
||||||
args['PythonVirtualEnv'] = 'python';
|
args['PythonForCommands'] = 'python';
|
||||||
}
|
}
|
||||||
|
|
||||||
const contextMap = {
|
const contextMap = {
|
||||||
|
@ -126,10 +126,12 @@ class CommandManager {
|
|||||||
|
|
||||||
async processText(text: string): Promise<string> {
|
async processText(text: string): Promise<string> {
|
||||||
let result = text.trim();
|
let result = text.trim();
|
||||||
|
const messageTextArr = result.split(/ |\n|\t/);
|
||||||
|
const commandName = messageTextArr[0];
|
||||||
|
|
||||||
for (const commandObj of await this.getCommandListByDevChatRun()) {
|
for (const commandObj of await this.getCommandListByDevChatRun()) {
|
||||||
const commandObjNamePattern = "/" + commandObj.name + " ";
|
const commandObjNamePattern = "/" + commandObj.name + " ";
|
||||||
if (commandObj.name === result || result.indexOf(commandObjNamePattern) === 0) {
|
if (commandObjNamePattern === commandName) {
|
||||||
const newInstructFile = await commandObj.handler(commandObj.name, "");
|
const newInstructFile = await commandObj.handler(commandObj.name, "");
|
||||||
result = newInstructFile + result;
|
result = newInstructFile + result;
|
||||||
break;
|
break;
|
||||||
|
@ -1,50 +0,0 @@
|
|||||||
import * as path from 'path';
|
|
||||||
import * as fs from 'fs';
|
|
||||||
import { ChatContext } from './contextManager';
|
|
||||||
import { createTempSubdirectory, runCommandStringAndWriteOutput } from '../util/commonUtil';
|
|
||||||
|
|
||||||
import { logger } from '../util/logger';
|
|
||||||
import { UiUtilWrapper } from '../util/uiUtil';
|
|
||||||
import { askcodeSummaryIndex, addSummaryContextFun } from '../contributes/commands';
|
|
||||||
|
|
||||||
|
|
||||||
export const askSummaryContext: ChatContext = {
|
|
||||||
name: 'askcode summary',
|
|
||||||
description: 'summary of file or directory',
|
|
||||||
|
|
||||||
handler: async () => {
|
|
||||||
const uriPath = await UiUtilWrapper.showInputBox({
|
|
||||||
prompt: 'File or directory to summary',
|
|
||||||
placeHolder: 'for example: /some/src'
|
|
||||||
});
|
|
||||||
|
|
||||||
if (uriPath) {
|
|
||||||
// check uriPath is absolute path or relative path
|
|
||||||
let uriPathAbs = uriPath;
|
|
||||||
if (!path.isAbsolute(uriPath)) {
|
|
||||||
// covert uriPath to absolute path, base path is workspacePath
|
|
||||||
const workspacePath = UiUtilWrapper.workspaceFoldersFirstPath();
|
|
||||||
if (!workspacePath) {
|
|
||||||
logger.channel()?.error(`The workspace is not opened!`);
|
|
||||||
logger.channel()?.show();
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
uriPathAbs = path.join(workspacePath, uriPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.channel()?.info(`Your input path is: ${uriPathAbs}`);
|
|
||||||
if (!fs.existsSync(uriPathAbs)) {
|
|
||||||
logger.channel()?.error(`The path ${uriPath} is not exist!`);
|
|
||||||
logger.channel()?.show();
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
// index the file or directory
|
|
||||||
await askcodeSummaryIndex(uriPathAbs);
|
|
||||||
|
|
||||||
// summary the file or directory
|
|
||||||
await addSummaryContextFun(uriPathAbs);
|
|
||||||
}
|
|
||||||
return [];
|
|
||||||
},
|
|
||||||
};
|
|
@ -4,8 +4,6 @@ import { gitDiffContext } from './contextGitDiff';
|
|||||||
import { customCommandContext } from './contextCustomCommand';
|
import { customCommandContext } from './contextCustomCommand';
|
||||||
import { refDefsContext } from './contextRefDefs';
|
import { refDefsContext } from './contextRefDefs';
|
||||||
import { defRefsContext } from './contextDefRefs';
|
import { defRefsContext } from './contextDefRefs';
|
||||||
import { askSummaryContext } from './contextSummary';
|
|
||||||
import { FT } from '../util/feature_flags/feature_toggles';
|
|
||||||
|
|
||||||
|
|
||||||
const chatContextManager = ChatContextManager.getInstance();
|
const chatContextManager = ChatContextManager.getInstance();
|
||||||
@ -16,6 +14,3 @@ chatContextManager.registerContext(gitDiffContext);
|
|||||||
chatContextManager.registerContext(refDefsContext);
|
chatContextManager.registerContext(refDefsContext);
|
||||||
chatContextManager.registerContext(defRefsContext);
|
chatContextManager.registerContext(defRefsContext);
|
||||||
chatContextManager.registerContext(customCommandContext);
|
chatContextManager.registerContext(customCommandContext);
|
||||||
if (FT("ask-code-summary")) {
|
|
||||||
chatContextManager.registerContext(askSummaryContext);
|
|
||||||
}
|
|
@ -1,5 +1,6 @@
|
|||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
import * as os from 'os';
|
||||||
import { sendFileSelectMessage, sendCodeSelectMessage } from './util';
|
import { sendFileSelectMessage, sendCodeSelectMessage } from './util';
|
||||||
import ExtensionContextHolder from '../util/extensionContext';
|
import ExtensionContextHolder from '../util/extensionContext';
|
||||||
import { TopicManager } from '../topic/topicManager';
|
import { TopicManager } from '../topic/topicManager';
|
||||||
@ -10,22 +11,14 @@ import { UiUtilWrapper } from '../util/uiUtil';
|
|||||||
import { isValidApiKey } from '../handler/historyMessagesBase';
|
import { isValidApiKey } from '../handler/historyMessagesBase';
|
||||||
|
|
||||||
import { logger } from '../util/logger';
|
import { logger } from '../util/logger';
|
||||||
import { CommandRun, createTempSubdirectory, runCommandAndWriteOutput, runCommandStringAndWriteOutput, runCommandStringArrayAndWriteOutput } from '../util/commonUtil';
|
import { CommandRun} from '../util/commonUtil';
|
||||||
import { updateIndexingStatus, updateLastModifyTime } from '../util/askCodeUtil';
|
|
||||||
import { installAskCode as installAskCodeFun } from '../util/python_installer/install_askcode';
|
|
||||||
|
|
||||||
import { ProgressBar } from '../util/progressBar';
|
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { MessageHandler } from '../handler/messageHandler';
|
|
||||||
import { FT } from '../util/feature_flags/feature_toggles';
|
|
||||||
import { getPackageVersion } from '../util/python_installer/pip_package_version';
|
|
||||||
|
|
||||||
import { exec } from 'child_process';
|
|
||||||
import { sendCommandListByDevChatRun, updateChatModels } from '../handler/regCommandList';
|
import { sendCommandListByDevChatRun, updateChatModels } from '../handler/regCommandList';
|
||||||
import DevChat from "../toolwrapper/devchat";
|
import DevChat from "../toolwrapper/devchat";
|
||||||
|
import { createEnvByConda, createEnvByMamba } from '../util/python_installer/app_install';
|
||||||
let indexProcess: CommandRun | null = null;
|
import { installRequirements } from '../util/python_installer/package_install';
|
||||||
let summaryIndexProcess: CommandRun | null = null;
|
|
||||||
|
|
||||||
function registerOpenChatPanelCommand(context: vscode.ExtensionContext) {
|
function registerOpenChatPanelCommand(context: vscode.ExtensionContext) {
|
||||||
let disposable = vscode.commands.registerCommand('devchat.openChatPanel', async () => {
|
let disposable = vscode.commands.registerCommand('devchat.openChatPanel', async () => {
|
||||||
@ -212,7 +205,7 @@ export function regPythonPathCommand(context: vscode.ExtensionContext) {
|
|||||||
}) ?? '';
|
}) ?? '';
|
||||||
|
|
||||||
if (pythonPath) {
|
if (pythonPath) {
|
||||||
vscode.workspace.getConfiguration("DevChat").update("PythonPath", pythonPath, vscode.ConfigurationTarget.Global);
|
vscode.workspace.getConfiguration("DevChat").update("PythonForChat", pythonPath, vscode.ConfigurationTarget.Global);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -246,233 +239,6 @@ export function regApplyDiffResultCommand(context: vscode.ExtensionContext) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function TestDevChatCommand(context: vscode.ExtensionContext) {
|
|
||||||
context.subscriptions.push(
|
|
||||||
vscode.commands.registerCommand('devchat.', async () => {
|
|
||||||
TopicManager.getInstance().loadTopics();
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export function registerAskCodeIndexStartCommand(context: vscode.ExtensionContext) {
|
|
||||||
let disposable = vscode.commands.registerCommand('DevChat.AskCodeIndexStart', async () => {
|
|
||||||
if (!FT("ask-code")) {
|
|
||||||
UiUtilWrapper.showErrorMessage("This command is a beta version command and has not been released yet.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const config = getConfig();
|
|
||||||
let pythonVirtualEnv: any = config.pythonVirtualEnv;
|
|
||||||
const supportedFileTypes = config.supportedFileTypes;
|
|
||||||
|
|
||||||
updateIndexingStatus("started");
|
|
||||||
|
|
||||||
if (pythonVirtualEnv) {
|
|
||||||
// check whether pythonVirtualEnv is stisfy the requirement version
|
|
||||||
const devchatAskVersion = getPackageVersion(pythonVirtualEnv, "devchat-ask");
|
|
||||||
|
|
||||||
let requireAskVersion = "0.1.7";
|
|
||||||
|
|
||||||
if (!devchatAskVersion || devchatAskVersion < requireAskVersion) {
|
|
||||||
logger.channel()?.info(`The version of devchat-ask is ${devchatAskVersion}`);
|
|
||||||
pythonVirtualEnv = undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (!pythonVirtualEnv) {
|
|
||||||
const progressBar = new ProgressBar();
|
|
||||||
progressBar.init();
|
|
||||||
logger.channel()?.show();
|
|
||||||
|
|
||||||
progressBar.update("Check devchat-ask package ...", 0);
|
|
||||||
|
|
||||||
progressBar.update("Installing devchat-ask. See OUTPUT for progress...", 0);
|
|
||||||
await installAskCode(supportedFileTypes, progressBar, indexCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateIndexingStatus("stopped");
|
|
||||||
});
|
|
||||||
context.subscriptions.push(disposable);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getConfig() {
|
|
||||||
return {
|
|
||||||
pythonVirtualEnv: vscode.workspace.getConfiguration('DevChat').get('PythonVirtualEnv'),
|
|
||||||
supportedFileTypes: vscode.workspace.getConfiguration('DevChat.askcode').get('supportedFileTypes'),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async function installAskCode(supportedFileTypes, progressBar: any, callback: Function) {
|
|
||||||
const pythonEnvPath : string = await installAskCodeFun();
|
|
||||||
if (!pythonEnvPath) {
|
|
||||||
logger.channel()?.error(`Installation failed!`);
|
|
||||||
logger.channel()?.show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await UiUtilWrapper.updateConfiguration("DevChat", "PythonVirtualEnv", pythonEnvPath.trim());
|
|
||||||
logger.channel()?.info(`Installation finished.`);
|
|
||||||
|
|
||||||
// Execute the callback function after the installation is finished
|
|
||||||
await callback(pythonEnvPath, supportedFileTypes, progressBar);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function indexCode(pythonVirtualEnv, supportedFileTypes, progressBar: any) {
|
|
||||||
progressBar.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export function registerAskCodeIndexStopCommand(context: vscode.ExtensionContext) {
|
|
||||||
let disposable = vscode.commands.registerCommand('DevChat.AskCodeIndexStop', async () => {
|
|
||||||
if (!FT("ask-code")) {
|
|
||||||
UiUtilWrapper.showErrorMessage("This command is a beta version command and has not been released yet.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (indexProcess) {
|
|
||||||
indexProcess.stop();
|
|
||||||
indexProcess = null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
context.subscriptions.push(disposable);
|
|
||||||
}
|
|
||||||
|
|
||||||
let summaryIndexTargetDir: string | undefined = undefined;
|
|
||||||
|
|
||||||
export async function askcodeSummaryIndex(targetDir: string|undefined) {
|
|
||||||
if (!FT("ask-code-summary")) {
|
|
||||||
UiUtilWrapper.showErrorMessage("This command is a beta version command and has not been released yet.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
summaryIndexTargetDir = targetDir;
|
|
||||||
|
|
||||||
const progressBar = new ProgressBar();
|
|
||||||
progressBar.init();
|
|
||||||
logger.channel()?.show();
|
|
||||||
|
|
||||||
progressBar.update("Index source code files for ask codebase summary...", 0);
|
|
||||||
|
|
||||||
const config = getConfig();
|
|
||||||
let pythonVirtualEnv: any = config.pythonVirtualEnv;
|
|
||||||
const supportedFileTypes = config.supportedFileTypes;
|
|
||||||
|
|
||||||
updateIndexingStatus("started");
|
|
||||||
|
|
||||||
if (pythonVirtualEnv) {
|
|
||||||
// check whether pythonVirtualEnv is stisfy the requirement version
|
|
||||||
const devchatAskVersion = getPackageVersion(pythonVirtualEnv, "devchat-ask");
|
|
||||||
|
|
||||||
let requireAskVersion = "0.1.3";
|
|
||||||
|
|
||||||
if (!devchatAskVersion || devchatAskVersion < requireAskVersion) {
|
|
||||||
logger.channel()?.info(`The version of devchat-ask is ${devchatAskVersion}`);
|
|
||||||
pythonVirtualEnv = undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!pythonVirtualEnv) {
|
|
||||||
progressBar.update("Installing devchat-ask. See OUTPUT for progress...", 0);
|
|
||||||
await installAskCode(supportedFileTypes, progressBar, indexCodeSummary);
|
|
||||||
} else {
|
|
||||||
progressBar.update("Index source files. See OUTPUT for progress...", 0);
|
|
||||||
await indexCodeSummary(pythonVirtualEnv, supportedFileTypes, progressBar);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateIndexingStatus("stopped");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function registerAskCodeSummaryIndexStartCommand(context: vscode.ExtensionContext) {
|
|
||||||
let disposable = vscode.commands.registerCommand('DevChat.AskCodeSummaryIndexStart', async () => {
|
|
||||||
askcodeSummaryIndex("*");
|
|
||||||
});
|
|
||||||
context.subscriptions.push(disposable);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function indexCodeSummary(pythonVirtualEnv, supportedFileTypes, progressBar: any) {
|
|
||||||
let envs = {};
|
|
||||||
|
|
||||||
const llmModelData = await ApiKeyManager.llmModel();
|
|
||||||
if (!llmModelData) {
|
|
||||||
logger.channel()?.error('No valid llm model is selected!');
|
|
||||||
logger.channel()?.show();
|
|
||||||
|
|
||||||
progressBar.endWithError("No valid llm model is selected!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let openaiApiKey = llmModelData.api_key;
|
|
||||||
if (!openaiApiKey) {
|
|
||||||
logger.channel()?.error('The OpenAI key is invalid!');
|
|
||||||
logger.channel()?.show();
|
|
||||||
|
|
||||||
progressBar.endWithError("The OpenAI key is invalid!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
envs['OPENAI_API_KEY'] = openaiApiKey;
|
|
||||||
|
|
||||||
const openAiApiBase = llmModelData.api_base;
|
|
||||||
if (openAiApiBase) {
|
|
||||||
envs['OPENAI_API_BASE'] = openAiApiBase;
|
|
||||||
}
|
|
||||||
|
|
||||||
const workspaceDir = UiUtilWrapper.workspaceFoldersFirstPath();
|
|
||||||
|
|
||||||
const command = pythonVirtualEnv.trim();
|
|
||||||
const args = [UiUtilWrapper.extensionPath() + "/tools/askcode_summary_index.py", "index", supportedFileTypes, summaryIndexTargetDir];
|
|
||||||
const options = { env: envs, cwd: workspaceDir };
|
|
||||||
|
|
||||||
summaryIndexProcess = new CommandRun();
|
|
||||||
const result = await summaryIndexProcess.spawnAsync(command, args, options, (data) => {
|
|
||||||
if (data.includes('Skip file:')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
logger.channel()?.info(`${data}`);
|
|
||||||
}, (data) => {
|
|
||||||
if (data.includes('Skip file:')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
logger.channel()?.info(`${data}`);
|
|
||||||
}, undefined, undefined);
|
|
||||||
|
|
||||||
if (result.exitCode !== 0) {
|
|
||||||
if (result.exitCode === null) {
|
|
||||||
logger.channel()?.info(`Indexing stopped!`);
|
|
||||||
progressBar.endWithError(`Indexing stopped!`);
|
|
||||||
} else {
|
|
||||||
logger.channel()?.error(`Indexing failed: ${result.stderr}`);
|
|
||||||
logger.channel()?.show();
|
|
||||||
progressBar.endWithError(`Indexing failed: ${result.stderr}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
updateLastModifyTime();
|
|
||||||
logger.channel()?.info(`index finished.`);
|
|
||||||
|
|
||||||
progressBar.update("Indexing finished.");
|
|
||||||
progressBar.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
export function registerAskCodeSummaryIndexStopCommand(context: vscode.ExtensionContext) {
|
|
||||||
let disposable = vscode.commands.registerCommand('DevChat.AskCodeIndexSummaryStop', async () => {
|
|
||||||
if (!FT("ask-code-summary")) {
|
|
||||||
UiUtilWrapper.showErrorMessage("This command is a beta version command and has not been released yet.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (summaryIndexProcess) {
|
|
||||||
summaryIndexProcess.stop();
|
|
||||||
summaryIndexProcess = null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
context.subscriptions.push(disposable);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export function registerInstallCommandsCommand(context: vscode.ExtensionContext) {
|
export function registerInstallCommandsCommand(context: vscode.ExtensionContext) {
|
||||||
let disposable = vscode.commands.registerCommand('DevChat.InstallCommands', async () => {
|
let disposable = vscode.commands.registerCommand('DevChat.InstallCommands', async () => {
|
||||||
@ -493,44 +259,69 @@ export function registerUpdateChatModelsCommand(context: vscode.ExtensionContext
|
|||||||
context.subscriptions.push(disposable);
|
context.subscriptions.push(disposable);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function addSummaryContextFun(fsPath: string ) {
|
export function registerInstallCommandsPython(context: vscode.ExtensionContext) {
|
||||||
if (!FT("ask-code-summary")) {
|
let disposable = vscode.commands.registerCommand('DevChat.InstallCommandPython', async () => {
|
||||||
UiUtilWrapper.showErrorMessage("This command is a beta version command and has not been released yet.");
|
// steps of install command python
|
||||||
return;
|
// 1. install python >= 3.11
|
||||||
}
|
// 2. check requirements.txt in ~/.chat dir
|
||||||
|
// 3. install requirements.txt
|
||||||
|
|
||||||
const workspaceDir = UiUtilWrapper.workspaceFoldersFirstPath();
|
|
||||||
if (!workspaceDir) {
|
// 1. install python >= 3.11
|
||||||
return ;
|
logger.channel()?.info(`create env for python ...`);
|
||||||
}
|
logger.channel()?.info(`try to create env by mamba ...`);
|
||||||
// check whether workspaceDir/.chat/.summary.json文件存在
|
let pythonCommand = await createEnvByMamba("devchat-commands", "", "3.11.4");
|
||||||
if (!fs.existsSync(path.join(workspaceDir, '.chat', '.summary.json'))) {
|
|
||||||
logger.channel()?.info(`You should index this workspace first.`);
|
|
||||||
logger.channel()?.show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const config = getConfig();
|
if (!pythonCommand || pythonCommand === "") {
|
||||||
const pythonVirtualEnv: any = config.pythonVirtualEnv;
|
logger.channel()?.info(`create env by mamba failed, try to create env by conda ...`);
|
||||||
|
pythonCommand = await createEnvByConda("devchat-commands", "", "3.11.4");
|
||||||
const tempDir = await createTempSubdirectory('devchat/context');
|
}
|
||||||
const summaryFile = path.join(tempDir, 'summary.txt');
|
|
||||||
|
|
||||||
const summaryArgs = [pythonVirtualEnv, UiUtilWrapper.extensionPath() + "/tools/askcode_summary_index.py", "desc", fsPath];
|
if (!pythonCommand || pythonCommand === "") {
|
||||||
const result = await runCommandStringArrayAndWriteOutput(summaryArgs, summaryFile);
|
logger.channel()?.error(`create virtual python env failed, you need create it by yourself with command: "conda create -n devchat-commands python=3.11.4"`);
|
||||||
logger.channel()?.info(` exit code:`, result.exitCode);
|
logger.channel()?.show();
|
||||||
|
|
||||||
logger.channel()?.debug(` stdout:`, result.stdout);
|
return ;
|
||||||
logger.channel()?.debug(` stderr:`, result.stderr);
|
}
|
||||||
MessageHandler.sendMessage(ExtensionContextHolder.provider?.view()!, { command: 'appendContext', context: `[context|${summaryFile}]` });
|
|
||||||
|
// 2. check requirements.txt in ~/.chat dir
|
||||||
|
// ~/.chat/requirements.txt
|
||||||
|
const requirementsFile = path.join(os.homedir(), '.chat', "workflows", 'requirements.txt');
|
||||||
|
if (!fs.existsSync(requirementsFile)) {
|
||||||
|
logger.channel()?.warn(`requirements.txt not found in ~/.chat/workflows dir.`);
|
||||||
|
logger.channel()?.show();
|
||||||
|
vscode.window.showErrorMessage(`Error: see OUTPUT for more detail!`);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. install requirements.txt
|
||||||
|
// run command: pip install -r {requirementsFile}
|
||||||
|
let isInstalled = false;
|
||||||
|
// try 3 times
|
||||||
|
for (let i = 0; i < 4; i++) {
|
||||||
|
let otherSource: string | undefined = undefined;
|
||||||
|
if (i>1) {
|
||||||
|
otherSource = 'https://pypi.tuna.tsinghua.edu.cn/simple/';
|
||||||
|
}
|
||||||
|
isInstalled = await installRequirements(pythonCommand, requirementsFile, otherSource);
|
||||||
|
if (isInstalled) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
logger.channel()?.info(`Install packages failed, try again: ${i + 1}`);
|
||||||
|
}
|
||||||
|
if (!isInstalled) {
|
||||||
|
logger.channel()?.error(`Install packages failed, you can install it with command: "${pythonCommand} -m pip install -r ~/.chat/requirements.txt"`);
|
||||||
|
logger.channel()?.show();
|
||||||
|
vscode.window.showErrorMessage(`Error: see OUTPUT for more detail!`);
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
UiUtilWrapper.updateConfiguration("DevChat", "PythonForCommands", pythonCommand.trim());
|
||||||
|
vscode.window.showInformationMessage(`All slash Command has ready to use! Please input / to try it!`);
|
||||||
|
});
|
||||||
|
|
||||||
|
context.subscriptions.push(disposable);
|
||||||
}
|
}
|
||||||
export function registerAddSummaryContextCommand(context: vscode.ExtensionContext) {
|
|
||||||
const callback = async (uri: { fsPath: any; }) => {
|
|
||||||
addSummaryContextFun(uri.fsPath);
|
|
||||||
};
|
|
||||||
context.subscriptions.push(vscode.commands.registerCommand('devchat.addSummaryContext', callback));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
registerOpenChatPanelCommand,
|
registerOpenChatPanelCommand,
|
||||||
|
@ -42,14 +42,14 @@ function getDefaultPythonCommand(): string | undefined {
|
|||||||
|
|
||||||
export function getValidPythonCommand(): string | undefined {
|
export function getValidPythonCommand(): string | undefined {
|
||||||
try {
|
try {
|
||||||
const pythonCommand = UiUtilWrapper.getConfiguration('DevChat', 'PythonPath');
|
const pythonCommand = UiUtilWrapper.getConfiguration('DevChat', 'PythonForChat');
|
||||||
if (pythonCommand) {
|
if (pythonCommand) {
|
||||||
return pythonCommand;
|
return pythonCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultPythonCommand = getDefaultPythonCommand();
|
const defaultPythonCommand = getDefaultPythonCommand();
|
||||||
if (defaultPythonCommand) {
|
if (defaultPythonCommand) {
|
||||||
UiUtilWrapper.updateConfiguration('DevChat', 'PythonPath', defaultPythonCommand);
|
UiUtilWrapper.updateConfiguration('DevChat', 'PythonForChat', defaultPythonCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
return defaultPythonCommand;
|
return defaultPythonCommand;
|
||||||
|
@ -14,13 +14,9 @@ import {
|
|||||||
regApplyDiffResultCommand,
|
regApplyDiffResultCommand,
|
||||||
registerStatusBarItemClickCommand,
|
registerStatusBarItemClickCommand,
|
||||||
regPythonPathCommand,
|
regPythonPathCommand,
|
||||||
registerAskCodeIndexStartCommand,
|
|
||||||
registerAskCodeIndexStopCommand,
|
|
||||||
registerAskCodeSummaryIndexStartCommand,
|
|
||||||
registerAskCodeSummaryIndexStopCommand,
|
|
||||||
registerAddSummaryContextCommand,
|
|
||||||
registerInstallCommandsCommand,
|
registerInstallCommandsCommand,
|
||||||
registerUpdateChatModelsCommand,
|
registerUpdateChatModelsCommand,
|
||||||
|
registerInstallCommandsPython
|
||||||
} from './contributes/commands';
|
} from './contributes/commands';
|
||||||
import { regLanguageContext } from './contributes/context';
|
import { regLanguageContext } from './contributes/context';
|
||||||
import { regDevChatView, regTopicView } from './contributes/views';
|
import { regDevChatView, regTopicView } from './contributes/views';
|
||||||
@ -233,6 +229,7 @@ async function activate(context: vscode.ExtensionContext) {
|
|||||||
|
|
||||||
registerInstallCommandsCommand(context);
|
registerInstallCommandsCommand(context);
|
||||||
registerUpdateChatModelsCommand(context);
|
registerUpdateChatModelsCommand(context);
|
||||||
|
registerInstallCommandsPython(context);
|
||||||
|
|
||||||
createStatusBarItem(context);
|
createStatusBarItem(context);
|
||||||
|
|
||||||
@ -244,12 +241,5 @@ async function activate(context: vscode.ExtensionContext) {
|
|||||||
regApplyDiffResultCommand(context);
|
regApplyDiffResultCommand(context);
|
||||||
|
|
||||||
regPythonPathCommand(context);
|
regPythonPathCommand(context);
|
||||||
|
|
||||||
registerAskCodeIndexStartCommand(context);
|
|
||||||
registerAskCodeIndexStopCommand(context);
|
|
||||||
|
|
||||||
registerAskCodeSummaryIndexStartCommand(context);
|
|
||||||
registerAskCodeSummaryIndexStopCommand(context);
|
|
||||||
registerAddSummaryContextCommand(context);
|
|
||||||
}
|
}
|
||||||
exports.activate = activate;
|
exports.activate = activate;
|
@ -1,28 +0,0 @@
|
|||||||
import * as vscode from 'vscode';
|
|
||||||
import { MessageHandler } from './messageHandler';
|
|
||||||
import { regInMessage, regOutMessage } from '../util/reg_messages';
|
|
||||||
import { getPackageVersion } from '../util/python_installer/pip_package_version';
|
|
||||||
|
|
||||||
|
|
||||||
export async function isDevChatInstalledImpl() {
|
|
||||||
let pythonVirtualEnv: string | undefined = vscode.workspace.getConfiguration('DevChat').get('PythonVirtualEnv');
|
|
||||||
|
|
||||||
if (pythonVirtualEnv) {
|
|
||||||
// check whether pythonVirtualEnv is stisfy the requirement version
|
|
||||||
const devchatAskVersion = getPackageVersion(pythonVirtualEnv, "devchat-ask");
|
|
||||||
if (!devchatAskVersion || devchatAskVersion < "0.1.7") {
|
|
||||||
pythonVirtualEnv = undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return pythonVirtualEnv ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
regInMessage({command: 'isDevChatInstalled'});
|
|
||||||
regOutMessage({command: 'isDevChatInstalled', result: true});
|
|
||||||
export async function isDevChatInstalled(message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise<void> {
|
|
||||||
const installed = await isDevChatInstalledImpl();
|
|
||||||
MessageHandler.sendMessage(panel, { command: 'isDevChatInstalled', result: installed });
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -20,7 +20,6 @@ import { getSetting, updateSetting } from './updateConfig';
|
|||||||
import { featureToggle, featureToggles } from './featureToggle';
|
import { featureToggle, featureToggles } from './featureToggle';
|
||||||
import { getUserAccessKey } from './userAccessKey';
|
import { getUserAccessKey } from './userAccessKey';
|
||||||
import { regModelList } from './regValidModelList';
|
import { regModelList } from './regValidModelList';
|
||||||
import { isDevChatInstalled } from './checkDevChatAsk';
|
|
||||||
|
|
||||||
|
|
||||||
// According to the context menu selected by the user, add the corresponding context file
|
// According to the context menu selected by the user, add the corresponding context file
|
||||||
@ -95,6 +94,5 @@ messageHandler.registerHandler('featureToggles', featureToggles);
|
|||||||
messageHandler.registerHandler('getUserAccessKey', getUserAccessKey);
|
messageHandler.registerHandler('getUserAccessKey', getUserAccessKey);
|
||||||
|
|
||||||
messageHandler.registerHandler('regModelList', regModelList);
|
messageHandler.registerHandler('regModelList', regModelList);
|
||||||
messageHandler.registerHandler('isDevChatInstalled', isDevChatInstalled);
|
|
||||||
|
|
||||||
messageHandler.registerHandler('userInput', userInput);
|
messageHandler.registerHandler('userInput', userInput);
|
||||||
|
@ -17,7 +17,6 @@ import DevChat from '../toolwrapper/devchat';
|
|||||||
|
|
||||||
const exec = promisify(execCb);
|
const exec = promisify(execCb);
|
||||||
|
|
||||||
let askcodeRunner : CommandRun | null = null;
|
|
||||||
let commandRunner : WorkflowRunner | null = null;
|
let commandRunner : WorkflowRunner | null = null;
|
||||||
|
|
||||||
let _lastMessage: any = undefined;
|
let _lastMessage: any = undefined;
|
||||||
|
@ -1,9 +1,3 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
// 临时解决方案,后续需要修改
|
|
||||||
|
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import { UiUtilWrapper } from "../util/uiUtil";
|
import { UiUtilWrapper } from "../util/uiUtil";
|
||||||
import { MessageHandler } from "../handler/messageHandler";
|
import { MessageHandler } from "../handler/messageHandler";
|
||||||
@ -48,18 +42,6 @@ async function handleWorkflowRequest(request): Promise<string | undefined> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
// 临时解决方案,后续需要修改
|
|
||||||
// 执行workflow
|
|
||||||
|
|
||||||
// workflow执行时,都是通过启动一个进程的方式来执行。
|
|
||||||
// 与一般进程不同的是:
|
|
||||||
// 1. 通过UI交互可以停止该进程;
|
|
||||||
// 2. 需要在进程启动前初始化相关的环境变量
|
|
||||||
// 3. 需要处理进程的通信
|
|
||||||
|
|
||||||
|
|
||||||
export class WorkflowRunner {
|
export class WorkflowRunner {
|
||||||
private _commandRunner: CommandRun | null = null;
|
private _commandRunner: CommandRun | null = null;
|
||||||
private _stop: boolean = false;
|
private _stop: boolean = false;
|
||||||
@ -220,37 +202,30 @@ export class WorkflowRunner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async run(workflow: string, commandDefines: any, message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise<void> {
|
public async run(workflow: string, commandDefines: any, message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise<void> {
|
||||||
/*
|
|
||||||
1. 判断workflow是否有输入存在
|
|
||||||
2. 获取workflow的环境变量信息
|
|
||||||
3. 执行workflow command
|
|
||||||
4. 处理workflow command输出
|
|
||||||
*/
|
|
||||||
|
|
||||||
this._panel = panel;
|
this._panel = panel;
|
||||||
|
|
||||||
// 获取workflow的python命令
|
// all workflow run in decchat-command virtual env
|
||||||
const pythonVirtualEnv: string | undefined = vscode.workspace.getConfiguration('DevChat').get('PythonVirtualEnv');
|
const pythonVirtualEnv: string | undefined = vscode.workspace.getConfiguration('DevChat').get('PythonForCommands');
|
||||||
if (!pythonVirtualEnv) {
|
if (!pythonVirtualEnv) {
|
||||||
MessageHandler.sendMessage(panel, { command: 'receiveMessage', text: "Index code fail.", hash: "", user: "", date: 0, isError: true });
|
MessageHandler.sendMessage(panel, { command: 'receiveMessage', text: "Python for Commands is not ready, please see OUTPUT for more detail.", hash: "", user: "", date: 0, isError: true });
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取扩展路径
|
// devchat-core packages are installed in extensionPath/tools/site-packages
|
||||||
const extensionPath = UiUtilWrapper.extensionPath();
|
const extensionPath = UiUtilWrapper.extensionPath();
|
||||||
|
|
||||||
// 获取api_key 和 api_base
|
// api_key and api_base
|
||||||
const [apiKey, aipBase] = await this._getApiKeyAndApiBase();
|
const [apiKey, aipBase] = await this._getApiKeyAndApiBase();
|
||||||
if (!apiKey) {
|
if (!apiKey) {
|
||||||
MessageHandler.sendMessage(panel, { command: 'receiveMessage', text: "The OpenAI key is invalid!", hash: "", user: "", date: 0, isError: true });
|
MessageHandler.sendMessage(panel, { command: 'receiveMessage', text: "The OpenAI key is invalid!", hash: "", user: "", date: 0, isError: true });
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构建子进程环境变量
|
// envs for Command
|
||||||
const workflowEnvs = {
|
const workflowEnvs = {
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
"PYTHONUTF8":1,
|
"PYTHONUTF8":1,
|
||||||
"DEVCHATPYTHON": UiUtilWrapper.getConfiguration("DevChat", "PythonPath") || "python3",
|
"DEVCHATPYTHON": UiUtilWrapper.getConfiguration("DevChat", "PythonForChat") || "python3",
|
||||||
"PYTHONLIBPATH": `${extensionPath}/tools/site-packages`,
|
"PYTHONLIBPATH": `${extensionPath}/tools/site-packages`,
|
||||||
"PARENT_HASH": message.parent_hash,
|
"PARENT_HASH": message.parent_hash,
|
||||||
...process.env,
|
...process.env,
|
||||||
@ -290,7 +265,6 @@ export class WorkflowRunner {
|
|||||||
logger.channel()?.show();
|
logger.channel()?.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
//MessageHandler.sendMessage(panel, { command: 'receiveMessagePartial', text: resultOut, hash:logHash, user:"", isError: false });
|
|
||||||
MessageHandler.sendMessage(panel, { command: 'receiveMessage', text: resultOut, hash:logHash, user:"", date:0, isError: false });
|
MessageHandler.sendMessage(panel, { command: 'receiveMessage', text: resultOut, hash:logHash, user:"", date:0, isError: false });
|
||||||
|
|
||||||
const dateStr = Math.floor(Date.now()/1000).toString();
|
const dateStr = Math.floor(Date.now()/1000).toString();
|
||||||
|
@ -55,8 +55,9 @@ export function createStatusBarItem(context: vscode.ExtensionContext): vscode.St
|
|||||||
progressBar.end();
|
progressBar.end();
|
||||||
|
|
||||||
// execute command: DevChat.InstallCommands
|
// execute command: DevChat.InstallCommands
|
||||||
vscode.commands.executeCommand('DevChat.InstallCommands');
|
await vscode.commands.executeCommand('DevChat.InstallCommands');
|
||||||
ExtensionContextHolder.provider?.reloadWebview();
|
ExtensionContextHolder.provider?.reloadWebview();
|
||||||
|
vscode.commands.executeCommand('DevChat.InstallCommandPython');
|
||||||
clearInterval(timer);
|
clearInterval(timer);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
statusBarItem.text = `$(warning)DevChat`;
|
statusBarItem.text = `$(warning)DevChat`;
|
||||||
|
@ -256,7 +256,7 @@ class DevChat {
|
|||||||
OPENAI_API_KEY: newActiveLlmModelKey ,
|
OPENAI_API_KEY: newActiveLlmModelKey ,
|
||||||
...openAiApiBaseObject
|
...openAiApiBaseObject
|
||||||
};
|
};
|
||||||
const pythonApp = UiUtilWrapper.getConfiguration("DevChat", "PythonPath") || "python3";
|
const pythonApp = UiUtilWrapper.getConfiguration("DevChat", "PythonForChat") || "python3";
|
||||||
|
|
||||||
logger.channel()?.info(`Running devchat with arguments: ${args.join(" ")}`);
|
logger.channel()?.info(`Running devchat with arguments: ${args.join(" ")}`);
|
||||||
logger.channel()?.info(`Running devchat with environment: ${JSON.stringify(keyInfo)}`);
|
logger.channel()?.info(`Running devchat with environment: ${JSON.stringify(keyInfo)}`);
|
||||||
@ -329,7 +329,7 @@ class DevChat {
|
|||||||
OPENAI_API_KEY: openaiApiKey,
|
OPENAI_API_KEY: openaiApiKey,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const pythonApp = UiUtilWrapper.getConfiguration("DevChat", "PythonPath") || "python3";
|
const pythonApp = UiUtilWrapper.getConfiguration("DevChat", "PythonForChat") || "python3";
|
||||||
const { exitCode: code, stdout, stderr } = await this.commandRun.spawnAsync(pythonApp, ["-m", "devchat"].concat(args), spawnOptions, undefined, undefined, undefined, undefined);
|
const { exitCode: code, stdout, stderr } = await this.commandRun.spawnAsync(pythonApp, ["-m", "devchat"].concat(args), spawnOptions, undefined, undefined, undefined, undefined);
|
||||||
|
|
||||||
logger.channel()?.info(`Finish devchat with arguments: ${args.join(" ")}`);
|
logger.channel()?.info(`Finish devchat with arguments: ${args.join(" ")}`);
|
||||||
@ -369,7 +369,7 @@ class DevChat {
|
|||||||
OPENAI_API_KEY: openaiApiKey,
|
OPENAI_API_KEY: openaiApiKey,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const pythonApp = UiUtilWrapper.getConfiguration("DevChat", "PythonPath") || "python3";
|
const pythonApp = UiUtilWrapper.getConfiguration("DevChat", "PythonForChat") || "python3";
|
||||||
const { exitCode: code, stdout, stderr } = await this.commandRun.spawnAsync(pythonApp, ["-m", "devchat"].concat(args), spawnOptions, undefined, undefined, undefined, undefined);
|
const { exitCode: code, stdout, stderr } = await this.commandRun.spawnAsync(pythonApp, ["-m", "devchat"].concat(args), spawnOptions, undefined, undefined, undefined, undefined);
|
||||||
|
|
||||||
logger.channel()?.info(`Finish devchat with arguments: ${args.join(" ")}`);
|
logger.channel()?.info(`Finish devchat with arguments: ${args.join(" ")}`);
|
||||||
@ -409,7 +409,7 @@ class DevChat {
|
|||||||
OPENAI_API_KEY: openaiApiKey,
|
OPENAI_API_KEY: openaiApiKey,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const pythonApp = UiUtilWrapper.getConfiguration("DevChat", "PythonPath") || "python3";
|
const pythonApp = UiUtilWrapper.getConfiguration("DevChat", "PythonForChat") || "python3";
|
||||||
const { exitCode: code, stdout, stderr } = await this.commandRun.spawnAsync(pythonApp, ["-m", "devchat"].concat(args), spawnOptions, undefined, undefined, undefined, undefined);
|
const { exitCode: code, stdout, stderr } = await this.commandRun.spawnAsync(pythonApp, ["-m", "devchat"].concat(args), spawnOptions, undefined, undefined, undefined, undefined);
|
||||||
|
|
||||||
logger.channel()?.info(`Finish devchat with arguments: ${args.join(" ")}`);
|
logger.channel()?.info(`Finish devchat with arguments: ${args.join(" ")}`);
|
||||||
@ -463,7 +463,7 @@ class DevChat {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const pythonApp = UiUtilWrapper.getConfiguration("DevChat", "PythonPath") || "python3";
|
const pythonApp = UiUtilWrapper.getConfiguration("DevChat", "PythonForChat") || "python3";
|
||||||
const { exitCode: code, stdout, stderr } = await this.commandRun.spawnAsync(pythonApp, ["-m", "devchat"].concat(args), spawnOptions, undefined, undefined, undefined, undefined);
|
const { exitCode: code, stdout, stderr } = await this.commandRun.spawnAsync(pythonApp, ["-m", "devchat"].concat(args), spawnOptions, undefined, undefined, undefined, undefined);
|
||||||
logger.channel()?.info(`Finish devchat with arguments: ${args.join(" ")}`);
|
logger.channel()?.info(`Finish devchat with arguments: ${args.join(" ")}`);
|
||||||
if (stderr) {
|
if (stderr) {
|
||||||
@ -498,7 +498,7 @@ class DevChat {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const pythonApp = UiUtilWrapper.getConfiguration("DevChat", "PythonPath") || "python3";
|
const pythonApp = UiUtilWrapper.getConfiguration("DevChat", "PythonForChat") || "python3";
|
||||||
const { exitCode: code, stdout, stderr } = await this.commandRun.spawnAsync(pythonApp, ["-m", "devchat"].concat(args), spawnOptions, undefined, undefined, undefined, undefined);
|
const { exitCode: code, stdout, stderr } = await this.commandRun.spawnAsync(pythonApp, ["-m", "devchat"].concat(args), spawnOptions, undefined, undefined, undefined, undefined);
|
||||||
logger.channel()?.info(`Finish devchat with arguments: ${args.join(" ")}`);
|
logger.channel()?.info(`Finish devchat with arguments: ${args.join(" ")}`);
|
||||||
if (stderr) {
|
if (stderr) {
|
||||||
@ -524,7 +524,7 @@ class DevChat {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const pythonApp = UiUtilWrapper.getConfiguration("DevChat", "PythonPath") || "python3";
|
const pythonApp = UiUtilWrapper.getConfiguration("DevChat", "PythonForChat") || "python3";
|
||||||
const { exitCode: code, stdout, stderr } = await this.commandRun.spawnAsync(pythonApp, ["-m", "devchat"].concat(args), spawnOptions, undefined, undefined, undefined, undefined);
|
const { exitCode: code, stdout, stderr } = await this.commandRun.spawnAsync(pythonApp, ["-m", "devchat"].concat(args), spawnOptions, undefined, undefined, undefined, undefined);
|
||||||
logger.channel()?.info(`Finish devchat with arguments: ${args.join(" ")}`);
|
logger.channel()?.info(`Finish devchat with arguments: ${args.join(" ")}`);
|
||||||
if (stderr) {
|
if (stderr) {
|
||||||
@ -551,7 +551,7 @@ class DevChat {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const pythonApp = UiUtilWrapper.getConfiguration("DevChat", "PythonPath") || "python3";
|
const pythonApp = UiUtilWrapper.getConfiguration("DevChat", "PythonForChat") || "python3";
|
||||||
const { exitCode: code, stdout, stderr } = await this.commandRun.spawnAsync(pythonApp, ["-m", "devchat"].concat(args), spawnOptions, undefined, undefined, undefined, undefined);
|
const { exitCode: code, stdout, stderr } = await this.commandRun.spawnAsync(pythonApp, ["-m", "devchat"].concat(args), spawnOptions, undefined, undefined, undefined, undefined);
|
||||||
|
|
||||||
logger.channel()?.info(`Finish devchat with arguments: ${args.join(" ")}`);
|
logger.channel()?.info(`Finish devchat with arguments: ${args.join(" ")}`);
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
/*
|
|
||||||
Install DevChat with python=3.11.4
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { FT } from "../feature_flags/feature_toggles";
|
|
||||||
import { logger } from "../logger";
|
|
||||||
import { appInstall } from "./app_install"
|
|
||||||
|
|
||||||
|
|
||||||
// python version: 3.11.4
|
|
||||||
// pkg name: devchat
|
|
||||||
// return: path to devchat, devchat is located in the same directory as python
|
|
||||||
export async function installAskCode(): Promise<string> {
|
|
||||||
try {
|
|
||||||
logger.channel()?.info(`start installing AskCode with python=3.11.4 ...`);
|
|
||||||
let devchatAskVersion = '>=0.1.7';
|
|
||||||
const pythonCommand = await appInstall("devchat-ask", devchatAskVersion, '3.11.4');
|
|
||||||
if (!pythonCommand) {
|
|
||||||
logger.channel()?.error(`failed to install devchat-ask with python=3.11.4`);
|
|
||||||
logger.channel()?.show();
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.channel()?.info(`installed devchat-ask with python=3.11.4 at ${pythonCommand}`);
|
|
||||||
return pythonCommand;
|
|
||||||
} catch (error) {
|
|
||||||
logger.channel()?.error(`${error}`);
|
|
||||||
logger.channel()?.show();
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
|
@ -43,8 +43,8 @@ export async function installDevchat(): Promise<string> {
|
|||||||
// write content to pythonPathFile
|
// write content to pythonPathFile
|
||||||
fs.writeFileSync(pythonPathFile, content);
|
fs.writeFileSync(pythonPathFile, content);
|
||||||
|
|
||||||
// update DevChat.PythonPath configration
|
// update DevChat.PythonForChat configration
|
||||||
await UiUtilWrapper.updateConfiguration("DevChat", "PythonPath", pythonApp);
|
await UiUtilWrapper.updateConfiguration("DevChat", "PythonForChat", pythonApp);
|
||||||
return pythonApp;
|
return pythonApp;
|
||||||
} else {
|
} else {
|
||||||
// if current os is not windows, we need to get default python path
|
// if current os is not windows, we need to get default python path
|
||||||
@ -69,7 +69,7 @@ export async function installDevchat(): Promise<string> {
|
|||||||
}
|
}
|
||||||
logger.channel()?.info(`Create env success: ${pythonCommand}`);
|
logger.channel()?.info(`Create env success: ${pythonCommand}`);
|
||||||
|
|
||||||
await UiUtilWrapper.updateConfiguration("DevChat", "PythonPath", pythonCommand);
|
await UiUtilWrapper.updateConfiguration("DevChat", "PythonForChat", pythonCommand);
|
||||||
return pythonCommand;
|
return pythonCommand;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -39,6 +39,45 @@ export async function installPackage(pythonCommand: string, pkgName: string, oth
|
|||||||
resolve(false);
|
resolve(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
child.on('close', (code) => {
|
||||||
|
if (code !== 0 && errorOut !== "") {
|
||||||
|
resolve(false);
|
||||||
|
} else {
|
||||||
|
resolve(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function installRequirements(pythonCommand: string, requirementsFile: string, otherSource: string | undefined) : Promise<boolean> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let errorOut = '';
|
||||||
|
|
||||||
|
const cmd = pythonCommand;
|
||||||
|
let args = ['-m', 'pip', 'install', '-r', requirementsFile];
|
||||||
|
if (otherSource) {
|
||||||
|
args.push("-i");
|
||||||
|
args.push(otherSource);
|
||||||
|
}
|
||||||
|
const child = spawn(cmd, args);
|
||||||
|
logger.channel()?.info(`Run command: ${cmd} ${args.join(' ')}`);
|
||||||
|
|
||||||
|
child.stdout.on('data', (data) => {
|
||||||
|
logger.channel()?.info(`${data}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
child.stderr.on('data', (data) => {
|
||||||
|
logger.channel()?.error(`${data}`);
|
||||||
|
logger.channel()?.show();
|
||||||
|
errorOut += data;
|
||||||
|
});
|
||||||
|
|
||||||
|
child.on('error', (error) => {
|
||||||
|
logger.channel()?.error(`exec error: ${error}`);
|
||||||
|
logger.channel()?.show();
|
||||||
|
resolve(false);
|
||||||
|
});
|
||||||
|
|
||||||
child.on('close', (code) => {
|
child.on('close', (code) => {
|
||||||
if (code !== 0 && errorOut !== "") {
|
if (code !== 0 && errorOut !== "") {
|
||||||
resolve(false);
|
resolve(false);
|
||||||
|
@ -114,7 +114,6 @@ Generate a professionally written and formatted release note in markdown with th
|
|||||||
const handleButton = (value: string | number | readonly string[] | undefined) => {
|
const handleButton = (value: string | number | readonly string[] | undefined) => {
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case "settings": messageUtil.sendMessage({ command: 'doCommand', content: ['workbench.action.openSettings', 'DevChat'] }); break;
|
case "settings": messageUtil.sendMessage({ command: 'doCommand', content: ['workbench.action.openSettings', 'DevChat'] }); break;
|
||||||
case "start_askcode": messageUtil.sendMessage({ command: 'doCommand', content: ['DevChat.AskCodeIndexStart'] }); break;
|
|
||||||
case "setting_openai_key": messageUtil.sendMessage({ command: 'doCommand', content: ['DevChat.AccessKey.OpenAI'] }); break;
|
case "setting_openai_key": messageUtil.sendMessage({ command: 'doCommand', content: ['DevChat.AccessKey.OpenAI'] }); break;
|
||||||
case "setting_devchat_key": messageUtil.sendMessage({ command: 'doCommand', content: ['DevChat.AccessKey.DevChat'] }); break;
|
case "setting_devchat_key": messageUtil.sendMessage({ command: 'doCommand', content: ['DevChat.AccessKey.DevChat'] }); break;
|
||||||
}
|
}
|
||||||
|
@ -46,18 +46,6 @@ interface DevChatInstalledMessage {
|
|||||||
result: boolean;
|
result: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const isDevChatInstalled = async () => {
|
|
||||||
return new Promise<boolean>((resolve, reject) => {
|
|
||||||
try {
|
|
||||||
messageUtil.sendMessage({ command: 'isDevChatInstalled'});
|
|
||||||
messageUtil.registerHandler('isDevChatInstalled', (message:DevChatInstalledMessage) => {
|
|
||||||
resolve(message.result);
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
reject(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const deleteMessage = async (messageHash: string) => {
|
export const deleteMessage = async (messageHash: string) => {
|
||||||
return new Promise<{ hash: string }>((resolve, reject) => {
|
return new Promise<{ hash: string }>((resolve, reject) => {
|
||||||
@ -227,7 +215,7 @@ You can configure DevChat from [Settings](#settings).`;
|
|||||||
contexts: chatContexts,
|
contexts: chatContexts,
|
||||||
message: userMessage
|
message: userMessage
|
||||||
});
|
});
|
||||||
const isInstalled = yield isDevChatInstalled();
|
const isInstalled = true;
|
||||||
|
|
||||||
if (isInstalled){
|
if (isInstalled){
|
||||||
// self.disabled = true;
|
// self.disabled = true;
|
||||||
@ -242,18 +230,8 @@ You can configure DevChat from [Settings](#settings).`;
|
|||||||
message: ''
|
message: ''
|
||||||
});
|
});
|
||||||
startGenerating(userMessage, chatContexts);
|
startGenerating(userMessage, chatContexts);
|
||||||
} else {
|
|
||||||
self.messages.push({
|
|
||||||
type: 'bot',
|
|
||||||
message: `The ask-code workflow hasn't been installed.
|
|
||||||
|
|
||||||
Please click the button below to install the necessary components.
|
|
||||||
|
|
||||||
The process might take a few minutes, depending on your network connection. In the meantime, feel free to chat with me about other topics.
|
|
||||||
|
|
||||||
<button value="start_askcode">Install Now</button>`
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// goto bottom
|
// goto bottom
|
||||||
goScrollBottom();
|
goScrollBottom();
|
||||||
}),
|
}),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user