Skip to content

Commit fd6b889

Browse files
author
Jia Liu
committed
feat: add nature language directory for support Chinese prompts template
1 parent fab0f21 commit fd6b889

File tree

37 files changed

+248
-16
lines changed

37 files changed

+248
-16
lines changed

exts/database/src/main/kotlin/cc/unitmesh/database/actions/GenerateEntityAction.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import cc.unitmesh.devti.AutoDevBundle
55
import cc.unitmesh.devti.gui.sendToChatWindow
66
import cc.unitmesh.devti.intentions.action.base.ChatBaseIntention
77
import cc.unitmesh.devti.provider.ContextPrompter
8+
import cc.unitmesh.devti.template.GENIUS_MIGRATION
89
import cc.unitmesh.devti.template.TemplateRender
910
import com.intellij.openapi.diagnostic.logger
1011
import com.intellij.openapi.editor.Editor
@@ -31,7 +32,7 @@ class GenerateEntityAction : ChatBaseIntention() {
3132
if (editor == null || file == null) return
3233
val selectedText = editor.selectionModel.selectedText ?: return
3334

34-
val templateRender = TemplateRender("genius/migration")
35+
val templateRender = TemplateRender(GENIUS_MIGRATION)
3536
val template = templateRender.getTemplate("gen-entity.vm")
3637
templateRender.context = SqlMigrationContext(
3738
lang = file.language.displayName,

exts/database/src/main/kotlin/cc/unitmesh/database/actions/GenerateFunctionAction.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import cc.unitmesh.devti.AutoDevBundle
55
import cc.unitmesh.devti.gui.sendToChatWindow
66
import cc.unitmesh.devti.intentions.action.base.ChatBaseIntention
77
import cc.unitmesh.devti.provider.ContextPrompter
8+
import cc.unitmesh.devti.template.GENIUS_MIGRATION
89
import cc.unitmesh.devti.template.TemplateRender
910
import com.intellij.openapi.diagnostic.logger
1011
import com.intellij.openapi.editor.Editor
@@ -38,7 +39,7 @@ class GenerateFunctionAction : ChatBaseIntention() {
3839
if (editor == null || file == null) return
3940
val selectedText = editor.selectionModel.selectedText ?: return
4041

41-
val templateRender = TemplateRender("genius/migration")
42+
val templateRender = TemplateRender(GENIUS_MIGRATION)
4243
val template = templateRender.getTemplate("gen-function.vm")
4344
templateRender.context = SqlMigrationContext(
4445
lang = file.language.displayName,

exts/database/src/main/kotlin/cc/unitmesh/database/actions/GenerateUnittestAction.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import cc.unitmesh.devti.AutoDevBundle
55
import cc.unitmesh.devti.gui.sendToChatWindow
66
import cc.unitmesh.devti.intentions.action.base.ChatBaseIntention
77
import cc.unitmesh.devti.provider.ContextPrompter
8+
import cc.unitmesh.devti.template.GENIUS_MIGRATION
89
import cc.unitmesh.devti.template.TemplateRender
910
import com.intellij.openapi.diagnostic.logger
1011
import com.intellij.openapi.editor.Editor
@@ -30,7 +31,7 @@ class GenerateUnittestAction : ChatBaseIntention() {
3031
if (editor == null || file == null) return
3132
val selectedText = editor.selectionModel.selectedText ?: return
3233

33-
val templateRender = TemplateRender("genius/migration")
34+
val templateRender = TemplateRender(GENIUS_MIGRATION)
3435
val template = templateRender.getTemplate("gen-unittest.vm")
3536
templateRender.context = SqlMigrationContext(
3637
lang = file.language.displayName,

exts/database/src/main/kotlin/cc/unitmesh/database/flow/AutoSqlFlow.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import cc.unitmesh.devti.AutoDevBundle
55
import cc.unitmesh.devti.flow.TaskFlow
66
import cc.unitmesh.devti.gui.chat.ChatCodingPanel
77
import cc.unitmesh.devti.llms.LLMProvider
8+
import cc.unitmesh.devti.template.GENIUS_SQL
89
import cc.unitmesh.devti.template.TemplateRender
910
import com.intellij.openapi.diagnostic.logger
1011
import kotlinx.coroutines.runBlocking
@@ -43,7 +44,7 @@ class AutoSqlFlow(
4344
}
4445

4546
private fun generateStepOnePrompt(context: AutoSqlContext, actions: DbContextActionProvider): String {
46-
val templateRender = TemplateRender("genius/sql")
47+
val templateRender = TemplateRender(GENIUS_SQL)
4748
val template = templateRender.getTemplate("sql-gen-clarify.vm")
4849

4950
templateRender.context = context
@@ -60,7 +61,7 @@ class AutoSqlFlow(
6061
actions: DbContextActionProvider,
6162
tableInfos: List<String>
6263
): String {
63-
val templateRender = TemplateRender("genius/sql")
64+
val templateRender = TemplateRender(GENIUS_SQL)
6465
val template = templateRender.getTemplate("sql-gen-design.vm")
6566

6667
genSqlContext.tableInfos = actions.getTableColumns(tableInfos)

exts/ext-harmonyos/src/main/kotlin/cc/unitmesh/harmonyos/actions/auto/AutoArkUiFlow.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import cc.unitmesh.devti.AutoDevBundle
44
import cc.unitmesh.devti.flow.TaskFlow
55
import cc.unitmesh.devti.gui.chat.ChatCodingPanel
66
import cc.unitmesh.devti.llms.LLMProvider
7+
import cc.unitmesh.devti.template.GENIUS_HARMONYOS
78
import cc.unitmesh.devti.template.TemplateRender
89
import kotlinx.coroutines.runBlocking
910

@@ -22,7 +23,7 @@ class AutoArkUiFlow(val panel: ChatCodingPanel, val llm: LLMProvider, val contex
2223
}
2324

2425
private fun generateStepOnePrompt(context: AutoArkUiContext): String {
25-
val templateRender = TemplateRender("genius/harmonyos")
26+
val templateRender = TemplateRender(GENIUS_HARMONYOS)
2627
val template = templateRender.getTemplate("arkui-clarify.vm")
2728

2829
templateRender.context = context
@@ -46,7 +47,7 @@ class AutoArkUiFlow(val panel: ChatCodingPanel, val llm: LLMProvider, val contex
4647
}
4748

4849
private fun generateStepTwoPrompt(selectedComponents: List<String>): String {
49-
val templateRender = TemplateRender("genius/harmonyos")
50+
val templateRender = TemplateRender(GENIUS_HARMONYOS)
5051
val template = templateRender.getTemplate("arkui-design.vm")
5152

5253
context.elements = selectedComponents.mapNotNull {

javascript/src/main/kotlin/cc/unitmesh/ide/javascript/flow/AutoPageFlow.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import cc.unitmesh.devti.AutoDevBundle
44
import cc.unitmesh.devti.flow.TaskFlow
55
import cc.unitmesh.devti.gui.chat.ChatCodingPanel
66
import cc.unitmesh.devti.llms.LLMProvider
7+
import cc.unitmesh.devti.template.GENIUS_PAGE
78
import cc.unitmesh.devti.template.TemplateRender
89
import cc.unitmesh.ide.javascript.flow.model.AutoPageContext
910
import cc.unitmesh.ide.javascript.flow.model.DsComponent
@@ -24,7 +25,7 @@ class AutoPageFlow(val context: AutoPageContext, val panel: ChatCodingPanel, val
2425
}
2526

2627
private fun generateStepOnePrompt(context: AutoPageContext): String {
27-
val templateRender = TemplateRender("genius/page")
28+
val templateRender = TemplateRender(GENIUS_PAGE)
2829
val template = templateRender.getTemplate("page-gen-clarify.vm")
2930

3031
templateRender.context = context
@@ -48,7 +49,7 @@ class AutoPageFlow(val context: AutoPageContext, val panel: ChatCodingPanel, val
4849
}
4950

5051
private fun generateStepTwoPrompt(selectedComponents: List<DsComponent>): String {
51-
val templateRender = TemplateRender("genius/page")
52+
val templateRender = TemplateRender(GENIUS_PAGE)
5253
val template = templateRender.getTemplate("page-gen-design.vm")
5354

5455
context.pages = selectedComponents.map { it.format() }

src/main/kotlin/cc/unitmesh/devti/actions/vcs/CodeReviewAction.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import cc.unitmesh.devti.provider.context.ChatContextProvider
1212
import cc.unitmesh.devti.provider.context.ChatCreationContext
1313
import cc.unitmesh.devti.provider.context.ChatOrigin
1414
import cc.unitmesh.devti.settings.AutoDevSettingsState
15+
import cc.unitmesh.devti.template.GENIUS_PRACTISES
1516
import cc.unitmesh.devti.template.TemplateRender
1617
import com.intellij.dvcs.repo.Repository
1718
import com.intellij.dvcs.repo.VcsRepositoryManager
@@ -96,7 +97,7 @@ open class CodeReviewAction : ChatBaseAction() {
9697
}
9798

9899
fun doCodeReview(project: Project, context: CodeReviewContext) {
99-
val templateRender = TemplateRender("genius/practises")
100+
val templateRender = TemplateRender(GENIUS_PRACTISES)
100101
val template = templateRender.getTemplate("code-review.vm")
101102
templateRender.context = context
102103
val messages = templateRender.buildMsgs(template)

src/main/kotlin/cc/unitmesh/devti/actions/vcs/CommitMessageSuggestionAction.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import cc.unitmesh.devti.AutoDevNotifications
55
import cc.unitmesh.devti.actions.chat.base.ChatBaseAction
66
import cc.unitmesh.devti.gui.chat.ChatActionType
77
import cc.unitmesh.devti.llms.LlmFactory
8+
import cc.unitmesh.devti.template.GENIUS_PRACTISES
89
import cc.unitmesh.devti.vcs.VcsPrompting
910
import cc.unitmesh.devti.statusbar.AutoDevStatus
1011
import cc.unitmesh.devti.template.TemplateRender
@@ -149,7 +150,7 @@ class CommitMessageSuggestionAction : ChatBaseAction() {
149150
}
150151

151152
private fun generateCommitMessage(diff: String, project: Project): String {
152-
val templateRender = TemplateRender("genius/practises")
153+
val templateRender = TemplateRender(GENIUS_PRACTISES)
153154
val template = templateRender.getTemplate("gen-commit-msg.vm")
154155

155156
val historyExamples = try {

src/main/kotlin/cc/unitmesh/devti/intentions/action/task/TestCodeGenTask.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import cc.unitmesh.devti.llms.LlmFactory
99
import cc.unitmesh.devti.util.parser.parseCodeFromString
1010
import cc.unitmesh.devti.provider.AutoTestService
1111
import cc.unitmesh.devti.provider.context.*
12+
import cc.unitmesh.devti.template.GENIUS_CODE
1213
import cc.unitmesh.devti.statusbar.AutoDevStatus
1314
import cc.unitmesh.devti.statusbar.AutoDevStatusService
1415
import cc.unitmesh.devti.template.TemplateRender
@@ -48,7 +49,7 @@ class TestCodeGenTask(val request: TestCodeGenRequest) :
4849
val commenter = LanguageCommenters.INSTANCE.forLanguage(request.file.language) ?: null
4950
val comment = commenter?.lineCommentPrefix ?: "//"
5051

51-
val templateRender = TemplateRender("genius/code")
52+
val templateRender = TemplateRender(GENIUS_CODE)
5253
val template = templateRender.getTemplate("test-gen.vm")
5354

5455
override fun run(indicator: ProgressIndicator) {

src/main/kotlin/cc/unitmesh/devti/template/TemplateRender.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,25 @@ package cc.unitmesh.devti.template
22

33
import cc.unitmesh.cf.core.llms.LlmMsg
44
import cc.unitmesh.devti.custom.team.TeamPromptsBuilder
5+
import cc.unitmesh.devti.settings.AutoDevSettingsState
56
import cc.unitmesh.template.TemplateRoleSplitter
67
import com.intellij.openapi.project.ProjectManager
78
import org.apache.velocity.VelocityContext
89
import org.apache.velocity.app.Velocity
910
import java.io.StringWriter
1011
import java.nio.charset.Charset
1112

13+
val ROOT = "genius"
14+
val GENIUS_SRE = "/sre"
15+
val GENIUS_MIGRATION = "/migration"
16+
val GENIUS_SQL = "/sql"
17+
val GENIUS_HARMONYOS = "/harmonyos"
18+
val GENIUS_PAGE = "/page"
19+
val GENIUS_PRACTISES = "/practises"
20+
val GENIUS_CODE = "/code"
21+
val GENIUS_CICD = "/cicd"
22+
val GENIUS_ERROR = "/error"
1223
class TemplateRender(val pathPrefix: String) {
13-
private val defaultPrefix: String = pathPrefix.trimEnd('/')
1424
private val velocityContext = VelocityContext()
1525
private val splitter = TemplateRoleSplitter()
1626
var context: Any = ""
@@ -41,6 +51,7 @@ class TemplateRender(val pathPrefix: String) {
4151
* @throws TemplateNotFoundError if the specified file cannot be found
4252
*/
4353
private fun getDefaultTemplate(filename: String): String {
54+
val defaultPrefix = "$ROOT/${AutoDevSettingsState.language}".trimEnd('/')
4455
val path = "$defaultPrefix/$filename"
4556
val resourceUrl = javaClass.classLoader.getResource(path) ?: throw TemplateNotFoundError(path)
4657
val bytes = resourceUrl.readBytes()

src/main/kotlin/cc/unitmesh/genius/actions/GenerateDockerfileAction.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cc.unitmesh.genius.actions
22

33
import cc.unitmesh.devti.custom.tasks.FileGenerateTask
44
import cc.unitmesh.devti.provider.BuildSystemProvider
5+
import cc.unitmesh.devti.template.GENIUS_SRE
56
import cc.unitmesh.devti.template.TemplateRender
67
import cc.unitmesh.genius.actions.context.DevOpsContext
78
import com.intellij.openapi.actionSystem.AnAction
@@ -16,7 +17,7 @@ class GenerateDockerfileAction : AnAction("Generate Dockerfile") {
1617
val project = e.project ?: return
1718

1819
val dockerContexts = BuildSystemProvider.guess(project)
19-
val templateRender = TemplateRender("genius/sre")
20+
val templateRender = TemplateRender(GENIUS_SRE)
2021
templateRender.context = DevOpsContext.from(dockerContexts)
2122
val template = templateRender.getTemplate("generate-dockerfile.vm")
2223

src/main/kotlin/cc/unitmesh/genius/actions/GenerateGitHubActionsAction.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cc.unitmesh.genius.actions
33
import cc.unitmesh.devti.AutoDevBundle
44
import cc.unitmesh.devti.custom.tasks.FileGenerateTask
55
import cc.unitmesh.devti.provider.BuildSystemProvider
6+
import cc.unitmesh.devti.template.GENIUS_CICD
67
import cc.unitmesh.devti.template.TemplateRender
78
import cc.unitmesh.genius.actions.context.DevOpsContext
89
import com.intellij.openapi.actionSystem.AnAction
@@ -40,7 +41,7 @@ class GenerateGitHubActionsAction : AnAction(AutoDevBundle.message("action.new.g
4041

4142
// first, we need to guess language
4243
val githubActions = BuildSystemProvider.guess(project);
43-
val templateRender = TemplateRender("genius/cicd")
44+
val templateRender = TemplateRender(GENIUS_CICD)
4445
templateRender.context = DevOpsContext.from(githubActions)
4546
val template = templateRender.getTemplate("generate-github-action.vm")
4647

src/main/kotlin/com/intellij/temporary/error/ErrorPromptBuilder.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package com.intellij.temporary.error
44
import com.intellij.temporary.AutoPsiUtils
55
import cc.unitmesh.devti.llms.tokenizer.Tokenizer
66
import cc.unitmesh.devti.prompting.BasePromptText
7+
import cc.unitmesh.devti.template.GENIUS_ERROR
78
import cc.unitmesh.devti.template.TemplateRender
89
import com.intellij.openapi.application.ReadAction
910
import com.intellij.openapi.vfs.VirtualFile
@@ -47,7 +48,7 @@ class ErrorPromptBuilder(private val maxLength: Int, private val tokenizer: Toke
4748

4849
val errorTextTrimmed = trimTextByTokenizer(errorText, maxLengthForPiece)
4950

50-
val templateRender = TemplateRender("genius/error")
51+
val templateRender = TemplateRender(GENIUS_ERROR)
5152
templateRender.context = ErrorContext(errorTextTrimmed, sourceCode)
5253
val template = templateRender.getTemplate("fix-error.vm")
5354
val prompt = templateRender.renderTemplate(template)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Create build.yml YAML file for GitHub Action for build project and runs tests
2+
3+
- ${context.buildContext}
4+
- OS: latest ubuntu version

src/main/resources/genius/zh/code/code-complete.vm

Whitespace-only changes.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Write unit test for following ${context.lang} code.
2+
3+
${context.frameworkedContext}
4+
5+
#if( $context.relatedClasses.length() > 0 )
6+
${context.relatedClasses}
7+
#end
8+
#if( $context.currentClass.length() > 0 )
9+
Here is current class information:
10+
${context.currentClass}
11+
#end
12+
13+
Here is the source code to be tested:
14+
15+
```$context.lang
16+
${context.imports}
17+
${context.sourceCode}
18+
```
19+
20+
## if newFile
21+
#if( $context.isNewFile )
22+
Start method test code with Markdown code block here:
23+
#else
24+
Start ${context.testClassName} test code with Markdown code block here:
25+
#end
26+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
As a helpful assistant with expertise in code debugging, your objective is to identify the roots of runtime problems by analyzing console logs and providing general solutions to fix the issues. When assisting users, follow these rules:
2+
3+
1. Always be helpful and professional.
4+
2. Use your mastery in code debugging to determine the cause of runtime problems by looking at console logs.
5+
3. Provide fixes to the bugs causing the runtime problems when given the code.
6+
4. Ensure that your solutions are not temporary "duct tape" fixes, but instead, provide long-term solutions.
7+
5. If a user sends you a one-file program, append the fixed code in markdown format at the end of your response.
8+
This code will be extracted using re.findall(r"`{{3}}(\w*)\n([\S\s]+?)\n`{{3}}", model_response)
9+
so adhere to this formatting strictly.
10+
6. If you can fix the problem strictly by modifying the code, do so. For instance, if a library is missing, it is preferable to rewrite the code without the library rather than suggesting to install the library.
11+
7. Always follow these rules to ensure the best assistance possible for the user.
12+
13+
Now, consider this user request:
14+
15+
"Please help me understand what the problem is and try to fix the code. Here's the console output and the program text:
16+
17+
Console output:
18+
%s
19+
Texts of programs:
20+
%s
21+
Provide a helpful response that addresses the user's concerns, adheres to the rules, and offers a solution for the runtime problem.
22+
23+
```
24+
${context.errorText}
25+
```
26+
27+
```
28+
${context.soureCode}
29+
```
30+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
You are a professional Frontend developer.
2+
According to the user's requirements, you should choose the best components for the user in List.
3+
4+
- Framework: ${context.frameworks}
5+
- Language: ${context.language}
6+
- User component: ${context.componentNames}, ${context.pageNames}
7+
8+
For example:
9+
10+
- Question(requirements): Build a form for user to fill in their information.
11+
- You should anwser: [Input, Select, Radio, Checkbox, Button, Form]
12+
13+
----
14+
15+
Here are the User requirements:
16+
17+
```markdown
18+
${context.requirement}
19+
```
20+
21+
Please choose the best Components for the user, just return the components names in a list, no explain.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
You are a professional Frontend developer.
2+
According to the user's requirements, and Components info, write Component for the user.
3+
4+
- User Components Infos: ${context.components}
5+
6+
For example:
7+
8+
- Question(requirements): Build a form for user to fill in their information.
9+
// componentName: Form, props: { fields: [{name: 'name', type: 'text'}, {name: 'age', type: 'number'}] }
10+
// componentName: Input, props: { name: 'name', type: 'text' }
11+
// componentName: Input, props: { name: 'age', type: 'number' }
12+
- Answer:
13+
```react
14+
<Form>
15+
<Input name="name" type="text" />
16+
<Input name="age" type="number" />
17+
</Form>
18+
```
19+
20+
----
21+
22+
Here are the requirements:
23+
24+
```markdown
25+
${context.requirement}
26+
```
27+
28+
Please write your code with Markdown syntax, no explanation is needed:
29+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
You are a seasoned software developer, and I'm seeking your expertise to review the following code:
2+
3+
- Focus on critical algorithms, logical flow, and design decisions within the code. Discuss how these changes impact the core functionality and the overall structure of the code.
4+
- Identify and highlight any potential issues or risks introduced by these code changes. This will help reviewers pay special attention to areas that may require improvement or further analysis.
5+
- Emphasize the importance of compatibility and consistency with the existing codebase. Ensure that the code adheres to the established standards and practices for code uniformity and long-term maintainability.
6+
7+
${context.frameworkContext}
8+
9+
#if($context.stories.isNotEmpty())
10+
The following user stories are related to these changes:
11+
${context.stories.joinToString("\n")}
12+
#end
13+
14+
${context.diffContext}
15+
16+
As your Tech lead, I am only concerned with key code review issues. Please provide me with a critical summary.
17+
Submit your key insights under 5 sentences in here:

0 commit comments

Comments
 (0)