From 2d3ecadc4ea55bee10f367ef6238571532d988b5 Mon Sep 17 00:00:00 2001 From: Rankin Zheng Date: Fri, 2 Feb 2024 19:40:58 +0800 Subject: [PATCH] Update devchat.help message --- .../components/MessageMarkdown/index.tsx | 83 ++----------------- src/views/i18n/zh.json | 2 +- src/views/stores/ChatStore.ts | 28 ++++--- 3 files changed, 24 insertions(+), 89 deletions(-) diff --git a/src/views/components/MessageMarkdown/index.tsx b/src/views/components/MessageMarkdown/index.tsx index 9a9da5f..9dc7601 100644 --- a/src/views/components/MessageMarkdown/index.tsx +++ b/src/views/components/MessageMarkdown/index.tsx @@ -77,69 +77,6 @@ const MessageMarkdown = observer((props: MessageMarkdownProps) => { const { i18n, t } = useTranslation(); const platform = process.env.platform; - const handleExplain = (value: string | undefined) => { - switch (value) { - case "#ask_code": - chat.addMessages([ - Message.create({ - type: "user", - message: "Explain /ask-code", - }), - Message.create({ - type: "bot", - message: `***/ask-code*** - -Ask anything about your codebase and get answers from our AI agent. - -DevChat intelligently navigates your codebase using GPT-4. It automatically selects and analyzes up to ten most relevant source files to answer your question. Stay tuned — we're soon integrating the more cost-efficient LLama 2 - 70B model. - -Sample questions: -- Why does the lead time for changes sometimes show as null? -- How is store.findAllAccounts implemented? -- The recursive retriever currently drops any TextNodes and only queries the IndexNodes. It's a bug. How can we fix it? - `, - }), - ]); - break; - case "#code": - chat.addMessages([ - Message.create({ - type: "user", - message: "Explain /code", - }), - Message.create({ - type: "bot", - message: `***/code*** - -Use this DevChat workflow to request code writing. Please input your specific requirements and supply the appropriate context for implementation. You can select the relevant code or files and right-click to "Add to DevChat". If you find the context is still insufficient, you can enhance my understanding of your code by providing class/function definitions of the selected code. To do this, click the "+" button for the selected code and choose "symbol definitions". Please note, it may take a few seconds for this information to appear in DevChat. - `, - }), - ]); - break; - case "#release_note": - chat.addMessages([ - Message.create({ - type: "user", - message: "Explain /release_note", - }), - Message.create({ - type: "bot", - message: `***/release_note*** - -Generate a professionally written and formatted release note in markdown with this workflow. I just need some basic information about the commits for the release. Add this to the context by clicking the "+" button and selecting \`git_log_releasenote\`. If the scope of commits differs from the default command, you can also select \`\` and input a command line such as \`git log 579398b^..HEAD --pretty=format:"%h - %B"\` to include the commit 579398b (inclusive) up to the latest. - `, - }), - ]); - break; - case "#settings": - messageUtil.sendMessage({ - command: "doCommand", - content: ["workbench.action.openSettings", "@ext:merico.devchat"], - }); - break; - } - chat.goScrollBottom(); - }; const handleButton = ( value: string | number | readonly string[] | undefined ) => { @@ -223,8 +160,8 @@ Generate a professionally written and formatted release note in markdown with th if (i18n && i18n.language === "zh") { // 目前只有中文需要单独翻译 if (children) { - if (children.includes("You can configure DevChat from")) { - return t("devchat.help"); + if (children.includes("Do you want to write some code or have a question about the project? ")) { + return t("devchat.help") + chat.helpWorkflowCommands(); } if ( children.includes( @@ -440,20 +377,14 @@ Generate a professionally written and formatted release note in markdown with th ); }, a({ node, className, children, href, ...props }) { - const customAnchors = [ - "#code", - "#commit_message", - "#release_note", - "#ask_code", - "#extension", - "#settings", - ].filter((item) => item === href); - return customAnchors.length > 0 ? ( + return className === "workflow_command" ? ( { - handleExplain(href); + if(href){ + chat.commonMessage(`/${href}`,[]); + } }} > {children} diff --git a/src/views/i18n/zh.json b/src/views/i18n/zh.json index 68fb096..6d237c9 100644 --- a/src/views/i18n/zh.json +++ b/src/views/i18n/zh.json @@ -8,7 +8,7 @@ "Ask DevChat a question or type ‘/’ for workflow": "向 DevChat 直接提问或输入 '/' 以查看可用的工作流", "How do I use DevChat?": "如何使用 DevChat?", "balance": "你的账户余额为 {{formatedCurrency}},登录 <4>web.devchat.ai 获得更多 tokens", - "devchat.help": "你想生成一些代码还是对这个项目有疑问?请首先右键单击相关的文件或代码片段,将它们添加到 DevChat 中作为上下文,然后在输入框中写下你的请求或问题,我将基于添加的上下文生成代码或回答你的问题。

你还可以点击输入框左侧的“+”按钮,查看更多添加上下文的快捷方法。此外,在输入框中键入“/”,DevChat 会列出可供使用的各类工作流,按 Tab 键或输入完整命令触发你需要的工作流。聊天愉快!

下面是一些工作流的示例:

[/code: 基于你的提示词和上下文生成代码](#code)

[/release_note: 根据加入上下文中的提交历史生成提交说明](#release_note)

[/ask-code: 询问任何关于当前代码库的信息,并从这位人工智能代理那里获得答案](#ask_code)

你可以点击[设置](#settings)来配置 DevChat", + "devchat.help": "你想生成一些代码还是对这个项目有疑问?请首先右键单击相关的文件或代码片段,将它们添加到 DevChat 中作为上下文,然后在输入框中写下你的请求或问题,我将基于添加的上下文生成代码或回答你的问题。

你还可以点击输入框左侧的“+”按钮,查看更多添加上下文的快捷方法。此外,在输入框中键入“/”,DevChat 会列出可供使用的各类工作流,按 Tab 键或输入完整命令触发你需要的工作流。聊天愉快!

下面是一些工作流的示例:

", "devchat.setkey": "你的环境或设置中缺少 DevChat 访问密钥。请输入你的 DevChat 访问密钥,这样我就可以开始正常工作了。

", "devchat.setkey_vscode": "你的环境或设置中缺少 DevChat 访问密钥。请输入你的 DevChat 访问密钥,这样我就可以开始正常工作了。

", "Is DevChat Access Key ready?": "DevChat 访问密钥是否已经设置好?", diff --git a/src/views/stores/ChatStore.ts b/src/views/stores/ChatStore.ts index 0170969..e53ca47 100644 --- a/src/views/stores/ChatStore.ts +++ b/src/views/stores/ChatStore.ts @@ -1,7 +1,8 @@ -import { types, flow, Instance } from "mobx-state-tree"; +import { types, flow, Instance ,getParent} from "mobx-state-tree"; import messageUtil from "@/util/MessageUtil"; import { ChatContext } from "@/views/stores/InputStore"; import yaml from "js-yaml"; +import { RootInstance } from "./RootStore"; interface Context { content: string; @@ -104,6 +105,17 @@ export const ChatStore = types self.scrollBottom++; }; + const helpWorkflowCommands = () =>{ + const rootStore = getParent(self); + + return rootStore.input.commandMenus.map((item) => { + if(item.name === "help"){ + return ""; + } + return `/${item.name}: ${item.description}`; + }).join("\n\n"); + }; + const lastNonEmptyHash = () => { let lastNonEmptyHash; for (let i = self.messages.length - 1; i >= 0; i--) { @@ -130,6 +142,7 @@ export const ChatStore = types }); const helpMessage = (originalMessage = false) => { + let helps = ` Do you want to write some code or have a question about the project? Simply right-click on your chosen files or code snippets and add them to DevChat. Feel free to ask me anything or let me help you with coding. @@ -137,17 +150,7 @@ Don't forget to check out the "+" button on the left of the input to add more co To get started, here are some of the things that I can do for you: -[/code: write code based on your prompt](#code) - -[/release_note: draft a release note based on your latest commits](#release_note) - -${ - self.features["ask-code"] - ? "[/ask-code: ask anything about your codebase and get answers from our AI agent](#ask_code)" - : "" -} - -You can configure DevChat from [Settings](#settings).`; +${helpWorkflowCommands()}`; const setKeyMessage = ` Devchat key is missing from your environment or settings. Kindly input your DevChat key, and I'll ensure DevChat is all set for you. @@ -268,6 +271,7 @@ Thinking... startGenerating, commonMessage, userInput, + helpWorkflowCommands, devchatAsk: flow(function* (userMessage, chatContexts) { self.messages.push({ type: "user",