Skip to content

Commit db369d2

Browse files
committed
feat: make code comments works
1 parent 74fb4de commit db369d2

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

src/main/kotlin/cc/unitmesh/devti/prompt/Markdown.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ fun parseCodeFromString(markdown: String): String {
1111
val node: Node = parser.parse(markdown)
1212
val visitor = CodeVisitor()
1313
node.accept(visitor)
14+
15+
if (visitor.code.isEmpty()) {
16+
// is still a code block
17+
if (markdown.contains("public") || markdown.contains("private")) {
18+
return markdown
19+
}
20+
21+
return markdown
22+
}
23+
1424
return visitor.code
1525
}
1626

src/main/kotlin/cc/unitmesh/devti/prompt/openai/OpenAIExecutor.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ class OpenAIExecutor(val openAIKey: String, val version: String) : AiExecutor, D
3232

3333

3434
val completion = service.createChatCompletion(completionRequest)
35-
return completion
35+
val output = completion
3636
.choices[0].message.content
37+
38+
logger.warn("output: $output")
39+
40+
return output
3741
}
3842

3943
override fun fillStoryDetail(project: SimpleProjectInfo, story: String): String {

src/main/resources/prompts/code_comments.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
Add code comments for follow code. Here are your requirements:
1+
Add comments inside follow function. Here are your requirements:
22

3-
1. should only return code, not explanation.
3+
1. comments should be clear and easy to understand.
4+
2. comments should inside the code, not in the end of the code, not in the beginning of the code.
5+
3. should only return with origin code, not explanation.
46

57
###
68
{code}

src/test/kotlin/cc/unitmesh/devti/DevtiFlowTest.kt

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,6 @@ package cc.unitmesh.devti
33
import org.junit.Test
44

55
class DevtiFlowTest {
6-
//
7-
// @Test
8-
// @Ignore
9-
// fun testShould_fetch_github_story() {
10-
// val dotenv = dotenv()
11-
// val githubToken = dotenv["GITHUB_TOKEN"]
12-
// val openAIKey = dotenv["OPENAI_KEY"]
13-
//
14-
// val gitHubIssue = GitHubIssue("unit-mesh/untitled", githubToken!!)
15-
// val openAIAction = OpenAIAction(openAIKey!!, "gpt-3.5-turbo")
16-
// val devtiFlow = DevtiFlow(gitHubIssue, openAIAction)
17-
// devtiFlow.processAll("1")
18-
// }
19-
20-
// input: """返回最合适的 Controller 名字:BlogController""", output: BlogController
21-
// input: """BlogController""", output: BlogController
226
@Test
237
fun testShould_extract_controller_name() {
248
val controllerName = DevtiFlow.matchControllerName("返回最合适的 Controller 名字:BlogController")

0 commit comments

Comments
 (0)