Skip to content

Commit

Permalink
feat: add batch-processor feature
Browse files Browse the repository at this point in the history
  • Loading branch information
2214962083 committed Jul 31, 2024
1 parent dcb2438 commit b351230
Show file tree
Hide file tree
Showing 37 changed files with 1,131 additions and 479 deletions.
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@
"command": "aide.smartPaste",
"title": "%command.smartPaste%"
},
{
"command": "aide.batchProcessor",
"title": "%command.batchProcessor%"
},
{
"command": "aide.copyFileText",
"title": "%command.copyFileText%",
Expand Down Expand Up @@ -125,6 +129,11 @@
"when": "explorerResourceIsFolder || selectedFilesCount > 0 || resourceLangId",
"command": "aide.askAI",
"group": "0_aide@1"
},
{
"when": "explorerResourceIsFolder || selectedFilesCount > 0 || resourceLangId",
"command": "aide.batchProcessor",
"group": "0_aide@2"
}
],
"editor/context": [
Expand Down Expand Up @@ -174,6 +183,11 @@
"default": "https://api.openai.com/v1",
"markdownDescription": "%config.openaiBaseUrl.description%"
},
"aide.apiConcurrency": {
"type": "number",
"default": 1,
"markdownDescription": "%config.apiConcurrency.description%"
},
"aide.useSystemProxy": {
"type": "boolean",
"default": true,
Expand Down Expand Up @@ -311,6 +325,7 @@
"langchain": "^0.2.10",
"lint-staged": "^15.2.7",
"minimatch": "^9.0.5",
"p-limit": "^6.1.0",
"pnpm": "^9.6.0",
"prettier": "^3.3.3",
"rimraf": "^6.0.1",
Expand Down
9 changes: 7 additions & 2 deletions package.nls.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"command.codeViewerHelper": "✨ Aide: Code Viewer Helper",
"command.renameVariable": "✨ Aide: Rename Variable",
"command.smartPaste": "✨ Aide: Smart Paste",
"command.batchProcessor": "✨ Aide: AI Batch Processor",
"command.copyFileText": "Copy text",
"command.quickCloseFileWithoutSave": "Quick close",
"command.replaceFile": "Replace original",
Expand All @@ -13,6 +14,7 @@
"config.openaiKey.description": "OpenAI Key, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/openai-key)",
"config.openaiModel.description": "OpenAI Model, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/openai-model)",
"config.openaiBaseUrl.description": "OpenAI Base URL, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/openai-base-url)",
"config.apiConcurrency.description": "API request concurrency, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/api-concurrency)",
"config.useSystemProxy.description": "Use global proxy (`HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`), you need to restart `VSCode` to take effect after changing this setting, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/use-system-proxy)",
"config.codeViewerHelperPrompt.description": "Code viewer helper prompt template, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/code-viewer-helper-prompt)",
"config.convertLanguagePairs.description": "Default convert language pairs, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/convert-language-pairs)",
Expand All @@ -36,14 +38,14 @@
"error.configKeyRequired": "{0} configuration key is required",
"error.vscodeLLMModelNotFound": "VSCode LLM model not found, please check configuration",
"error.noSelection": "No file or folder selected",
"error.noActiveEditor": "No file is currently open",
"error.noActiveEditor": "Please open any file first to determine workspace",
"error.noTargetLanguage": "No target language selected",
"error.noContext": "Context not initialized",
"error.emptyClipboard": "Clipboard is empty",
"error.xclipNotFound": "xclip is not installed. Please install it using your package manager (e.g., sudo apt-get install xclip)",
"error.fileNotFound": "File not found",
"error.invalidInput": "Invalid input",
"info.copied": "File contents have been copied to clipboard",
"info.customLanguage": "Custom language",
"info.noAiSuggestionsVariableName": "AI thinks your variable name is already good",
"info.processing": "Aide is processing...",
"info.continueMessage": "Continue? I'm not sure if it's done yet, if there's still content not generated, you can click continue.",
Expand All @@ -52,11 +54,14 @@
"info.cancel": "Cancel",
"info.commandCopiedToClipboard": "AI command has been copied to clipboard",
"info.fileReplaceSuccess": "File content has been replaced successfully",
"info.batchProcessorSuccess": "AI batch processor success!\n\nTotal {0} files generated, you can review and replace manually.\n\nTasks completed:\n{1}",
"input.array.promptEnding": "Enter comma separated values",
"input.json.promptEnding": "Enter JSON formatted value",
"input.aiCommand.prompt": "Enter question for AI command",
"input.aiCommand.placeholder": "Enter question for AI command",
"input.codeConvertTargetLanguage.prompt": "Select convert target language",
"input.selectAiSuggestionsVariableName.prompt": "Select AI suggestions variable name",
"input.batchProcessor.prompt": "Let AI batch process your selected {0} files, what do you want AI to do?",
"input.batchProcessor.placeholder": "eg: help me migrate from python2 to python3",
"file.content": "File: {0}\n```{1}\n{2}\n```\n\n"
}
9 changes: 7 additions & 2 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"command.codeViewerHelper": "✨ Aide: Code Viewer Helper",
"command.renameVariable": "✨ Aide: Rename Variable",
"command.smartPaste": "✨ Aide: Smart Paste",
"command.batchProcessor": "✨ Aide: AI Batch Processor",
"command.copyFileText": "Copy text",
"command.quickCloseFileWithoutSave": "Quick close",
"command.replaceFile": "Replace original",
Expand All @@ -13,6 +14,7 @@
"config.openaiKey.description": "OpenAI Key, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/openai-key)",
"config.openaiModel.description": "OpenAI Model, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/openai-model)",
"config.openaiBaseUrl.description": "OpenAI Base URL, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/openai-base-url)",
"config.apiConcurrency.description": "API request concurrency, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/api-concurrency)",
"config.useSystemProxy.description": "Use global proxy (`HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`), you need to restart `VSCode` to take effect after changing this setting, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/use-system-proxy)",
"config.codeViewerHelperPrompt.description": "Code viewer helper prompt template, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/code-viewer-helper-prompt)",
"config.convertLanguagePairs.description": "Default convert language pairs, [click to view online documentation](https://aide.nicepkg.cn/guide/configuration/convert-language-pairs)",
Expand All @@ -36,14 +38,14 @@
"error.configKeyRequired": "{0} configuration key is required",
"error.vscodeLLMModelNotFound": "VSCode LLM model not found, please check configuration",
"error.noSelection": "No file or folder selected",
"error.noActiveEditor": "No file is currently open",
"error.noActiveEditor": "Please open any file first to determine workspace",
"error.noTargetLanguage": "No target language selected",
"error.noContext": "Context not initialized",
"error.emptyClipboard": "Clipboard is empty",
"error.xclipNotFound": "xclip is not installed. Please install it using your package manager (e.g., sudo apt-get install xclip)",
"error.fileNotFound": "File not found",
"error.invalidInput": "Invalid input",
"info.copied": "File contents have been copied to clipboard",
"info.customLanguage": "Custom language",
"info.noAiSuggestionsVariableName": "AI thinks your variable name is already good",
"info.processing": "Aide is processing...",
"info.continueMessage": "Continue? I'm not sure if it's done yet, if there's still content not generated, you can click continue.",
Expand All @@ -52,11 +54,14 @@
"info.cancel": "Cancel",
"info.commandCopiedToClipboard": "AI command has been copied to clipboard",
"info.fileReplaceSuccess": "File content has been replaced successfully",
"info.batchProcessorSuccess": "AI batch processor success!\n\nTotal {0} files generated, you can review and replace manually.\n\nTasks completed:\n{1}",
"input.array.promptEnding": "Enter comma separated values",
"input.json.promptEnding": "Enter JSON formatted value",
"input.aiCommand.prompt": "Enter question for AI command",
"input.aiCommand.placeholder": "Enter question for AI command",
"input.codeConvertTargetLanguage.prompt": "Select convert target language",
"input.selectAiSuggestionsVariableName.prompt": "Select AI suggestions variable name",
"input.batchProcessor.prompt": "Let AI batch process your selected {0} files, what do you want AI to do?",
"input.batchProcessor.placeholder": "eg: help me migrate from python2 to python3",
"file.content": "File: {0}\n```{1}\n{2}\n```\n\n"
}
9 changes: 7 additions & 2 deletions package.nls.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"command.codeViewerHelper": "✨ Aide: 代码查看器助手",
"command.renameVariable": "✨ Aide: 重命名变量",
"command.smartPaste": "✨ Aide: 智能粘贴",
"command.batchProcessor": "✨ Aide: AI 批量处理",
"command.copyFileText": "复制全文",
"command.quickCloseFileWithoutSave": "快速关闭",
"command.replaceFile": "替换原文",
Expand All @@ -13,6 +14,7 @@
"config.openaiKey.description": "OpenAI Key, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/openai-key)",
"config.openaiModel.description": "OpenAI Model, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/openai-model)",
"config.openaiBaseUrl.description": "OpenAI Base URL, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/openai-base-url)",
"config.apiConcurrency.description": "API 请求并发数, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/api-concurrency)",
"config.useSystemProxy.description": "是否使用全局代理 (`HTTP_PROXY`、`HTTPS_PROXY`、`ALL_PROXY`) , 更改此设置后需要重启 `VSCode` 才生效, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/use-system-proxy)",
"config.codeViewerHelperPrompt.description": "代码查看器助手 prompt 模板, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/code-viewer-helper-prompt)",
"config.convertLanguagePairs.description": "默认转换语言对照表, [点击查看在线文档](https://aide.nicepkg.cn/zh/guide/configuration/convert-language-pairs)",
Expand All @@ -36,14 +38,14 @@
"error.configKeyRequired": "{0} 配置键是必需的",
"error.vscodeLLMModelNotFound": "未找到 VSCode LLM 模型,请检查配置",
"error.noSelection": "未选择任何文件或文件夹",
"error.noActiveEditor": "未打开任何文件",
"error.noActiveEditor": "请先打开任意一个文件以确定 workspace",
"error.noTargetLanguage": "未选择目标语言",
"error.noContext": "上下文未初始化",
"error.emptyClipboard": "剪贴板为空",
"error.xclipNotFound": "xclip 未安装。请使用你的包管理器安装它 (例如,sudo apt-get install xclip)",
"error.fileNotFound": "文件未找到",
"error.invalidInput": "无效的输入",
"info.copied": "文件内容已复制到剪贴板",
"info.customLanguage": "自定义语言",
"info.noAiSuggestionsVariableName": " AI 觉得你这个变量名字已经很好了",
"info.processing": "Aide 正在处理中...",
"info.continueMessage": "继续吗?我不确定是否已经完成了,如果还有内容没生成,你可以点击继续。",
Expand All @@ -52,11 +54,14 @@
"info.cancel": "取消",
"info.commandCopiedToClipboard": "AI 命令已复制到剪贴板",
"info.fileReplaceSuccess": "文件内容已成功替换",
"info.batchProcessorSuccess": "AI 批量处理成功!\n\n共生成了 {0} 个文件, 你可以自己 review 手动替换。\n\n已完成任务:\n{1}",
"input.array.promptEnding": "输入逗号分隔的值",
"input.json.promptEnding": "输入 JSON 格式的值",
"input.aiCommand.prompt": "输入 AI 命令的问题",
"input.aiCommand.placeholder": "输入 AI 命令的问题",
"input.codeConvertTargetLanguage.prompt": "选择转换目标语言",
"input.selectAiSuggestionsVariableName.prompt": "选择 AI 建议的变量名",
"input.batchProcessor.prompt": "让 AI 批量处理你选中的 {0} 个文件,你想 AI 做什么?",
"input.batchProcessor.placeholder": "比如:帮我从 python2 迁移到 python3",
"file.content": "File: {0}\n```{1}\n{2}\n```\n\n"
}
17 changes: 17 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/ai/get-reference-file-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ export const getReferenceFilePaths = async ({
useHistory: false,
zodSchema: z.object({
referenceFileRelativePaths: z.array(z.string()).min(0).max(3).describe(`
The relative paths of the up to three most useful files related to the currently edited file. This can include 0 to 3 files.
Required! The relative paths of the up to three most useful files related to the currently edited file. This can include 0 to 3 files.
`),
dependenceFileRelativePath: z.string().describe(`
The relative path of the dependency file for the current file. If the dependency file is not found, return an empty string.
Required! The relative path of the dependency file for the current file. If the dependency file is not found, return an empty string.
`)
})
})
Expand Down
2 changes: 1 addition & 1 deletion src/ai/model-providers/claude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class AnthropicModelProvider extends BaseModelProvider<ChatAnthropic> {
},
model: openaiModel,
temperature: 0.95, // never use 1.0, some models do not support it
maxRetries: 3,
maxRetries: 6,
verbose: isDev
})

Expand Down
57 changes: 57 additions & 0 deletions src/auto-open-corresponding-files.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import * as vscode from 'vscode'

import { getOriginalFileUri, isTmpFileUri } from './file-utils/create-tmp-file'
import { VsCodeFS } from './file-utils/vscode-fs'
import { logger } from './logger'

let isHandlingEditorChange = false

const openCorrespondingFiles = async (tmpUri: vscode.Uri): Promise<void> => {
if (isHandlingEditorChange || !isTmpFileUri(tmpUri)) return
isHandlingEditorChange = true
const originalUri = getOriginalFileUri(tmpUri)

try {
// check if the original file exists
await VsCodeFS.stat(originalUri.fsPath)

// open original file
const originalDocument =
await vscode.workspace.openTextDocument(originalUri)
await vscode.window.showTextDocument(
originalDocument,
vscode.ViewColumn.One
)

// 重新聚焦到 .aide.vue 文件
// refocus on the .aide file
const tmpDocument = await vscode.workspace.openTextDocument(tmpUri)
await vscode.window.showTextDocument(tmpDocument, vscode.ViewColumn.Two)
} catch (e) {
logger.warn('openCorrespondingFiles error', e)
} finally {
isHandlingEditorChange = false
}
}

export const autoOpenCorrespondingFiles = (
context: vscode.ExtensionContext
) => {
context.subscriptions.push(
vscode.workspace.onDidOpenTextDocument(async document => {
const maybeTmpUri = document.uri
if (isTmpFileUri(maybeTmpUri)) {
await openCorrespondingFiles(maybeTmpUri)
}
})
)

context.subscriptions.push(
vscode.window.onDidChangeActiveTextEditor(editor => {
const maybeTmpUri = editor?.document.uri
if (maybeTmpUri && isTmpFileUri(maybeTmpUri) && !isHandlingEditorChange) {
openCorrespondingFiles(maybeTmpUri)
}
})
)
}
File renamed without changes.
Loading

0 comments on commit b351230

Please sign in to comment.