Skip to content

Commit 8ea5d35

Browse files
committed
fix(prompting): improve language block handling in PromptOptimizer #317
Enhanced the handling of language blocks in `PromptOptimizer` to correctly format text for `txt`, `md`, and `markdown` languages. Added a test case to verify the handling of `devin` language blocks.
1 parent e477111 commit 8ea5d35

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

core/src/main/kotlin/cc/unitmesh/devti/prompting/optimizer/PromptOptimizer.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ object PromptOptimizer {
88
return fences.joinToString("\n") {
99
if (it.originLanguage == "python") {
1010
"```${it.originLanguage}\n${it.text}\n```"
11-
} else {
11+
} else if (it.originLanguage == "txt" || it.originLanguage == "md" || it.originLanguage == "markdown") {
1212
trim(it.text)
13+
} else {
14+
"```${it.originLanguage}\n${trim(it.text)}\n```"
1315
}
1416
}
1517
}

core/src/test/kotlin/cc/unitmesh/devti/prompting/optimizer/PromptOptimizerTest.kt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,38 @@ def foo():
201201

202202
assertThat(result).isEqualTo(expected)
203203
}
204+
205+
@Test
206+
fun should_handle_with_devin_block() {
207+
val content = """
208+
|```devin
209+
|/write:HelloWorld.java
210+
|```java
211+
|public class HelloWorld {
212+
| public static void main(String[] args) {
213+
| System.out.println("Hello, World");
214+
| }
215+
|}
216+
|```
217+
|```
218+
|
219+
""".trimMargin()
220+
221+
// when
222+
val result = PromptOptimizer.trimCodeSpace(content)
223+
224+
// then
225+
val expected = """```DevIn
226+
/write:HelloWorld.java
227+
```java
228+
public class HelloWorld {
229+
public static void main(String[] args) {
230+
System.out.println("Hello, World");
231+
}
232+
}
233+
```
234+
```"""
235+
236+
assertThat(result).isEqualTo(expected)
237+
}
204238
}

0 commit comments

Comments
 (0)