|
1 | 1 | package cc.unitmesh.devti.template
|
2 | 2 |
|
3 | 3 | import cc.unitmesh.cf.core.llms.LlmMsg
|
| 4 | +import cc.unitmesh.devti.custom.team.TeamPromptsBuilder |
4 | 5 | import cc.unitmesh.template.TemplateRoleSplitter
|
| 6 | +import com.intellij.openapi.project.ProjectManager |
5 | 7 | import org.apache.velocity.VelocityContext
|
6 | 8 | import org.apache.velocity.app.Velocity
|
7 | 9 | import java.io.StringWriter
|
8 | 10 | import java.nio.charset.Charset
|
9 | 11 |
|
10 |
| -class TemplateRender(pathPrefix: String) { |
| 12 | +class TemplateRender(val pathPrefix: String) { |
11 | 13 | private val defaultPrefix: String = pathPrefix.trimEnd('/')
|
12 | 14 | private val velocityContext = VelocityContext()
|
13 | 15 | private val splitter = TemplateRoleSplitter()
|
14 | 16 | var context: Any = ""
|
15 | 17 |
|
| 18 | + |
| 19 | + /** |
| 20 | + * Retrieves the template for a given filename. |
| 21 | + * |
| 22 | + * @param filename the name of the file for which the template is requested |
| 23 | + * @return the template string for the specified filename, or the default template if no override is found |
| 24 | + */ |
| 25 | + fun getTemplate(filename: String): String { |
| 26 | + val overrideTemplate = ProjectManager.getInstance().openProjects.firstOrNull().let { |
| 27 | + TeamPromptsBuilder(it!!).overrideTemplate(pathPrefix, filename) |
| 28 | + } |
| 29 | + |
| 30 | + return overrideTemplate ?: getDefaultTemplate(filename) |
| 31 | + } |
| 32 | + |
16 | 33 | /**
|
17 | 34 | * Retrieves the template content from the specified file.
|
18 | 35 | *
|
19 | 36 | * @param filename the name of the file containing the template
|
20 | 37 | * @return the content of the template as a string
|
21 | 38 | * @throws TemplateNotFoundError if the specified file cannot be found
|
22 | 39 | */
|
23 |
| - fun getTemplate(filename: String): String { |
| 40 | + private fun getDefaultTemplate(filename: String): String { |
24 | 41 | val path = "$defaultPrefix/$filename"
|
25 | 42 | val resourceUrl = javaClass.classLoader.getResource(path) ?: throw TemplateNotFoundError(path)
|
26 | 43 | val bytes = resourceUrl.readBytes()
|
|
0 commit comments