![JAR search and dependency download from the Maven repository](/logo.png)
cc.unitmesh.prompt.template.TemplateDataCompile.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of prompt-script Show documentation
Show all versions of prompt-script Show documentation
Chocolate Factory is a cutting-edge LLM toolkit designed to empower you in creating your very own AI assistant.
package cc.unitmesh.prompt.template
import cc.unitmesh.prompt.model.TemplateDatasource
import cc.unitmesh.template.PromptCompiler
import cc.unitmesh.template.TemplateEngineType
import cc.unitmesh.template.VelocityCompiler
import com.google.gson.JsonElement
import java.nio.file.Path
class TemplateDataCompile(private val type: TemplateEngineType = TemplateEngineType.VELOCITY) {
companion object {
val logger: org.slf4j.Logger = org.slf4j.LoggerFactory.getLogger(TemplateDataCompile::class.java)
}
private val compiler: PromptCompiler = when (type) {
TemplateEngineType.VELOCITY -> VelocityCompiler()
}
fun compile(templatePath: String, dataPath: String): String {
return compiler.compile(templatePath, dataPath)
}
fun compile(template: String, templateDatasource: List, basePath: Path): String {
templateDatasource.forEach {
when (it) {
is TemplateDatasource.File -> {
val dataPath = basePath.resolve(it.value).toString()
return compiler.compile(template, dataPath)
}
}
}
logger.error("unsupported template datasource: $templateDatasource")
return ""
}
fun compile(templatePath: String, element: JsonElement): String {
return compiler.compile(templatePath, element)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy