commonMain.com.xebia.functional.xef.PromptMultipleClassifier.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xef-core Show documentation
Show all versions of xef-core Show documentation
Building applications with LLMs through composability in Kotlin
package com.xebia.functional.xef
import com.xebia.functional.xef.conversation.Description
import kotlin.reflect.KType
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.KSerializer
import kotlinx.serialization.descriptors.SerialKind
import kotlinx.serialization.serializer
interface PromptMultipleClassifier {
fun getItems(): List
fun template(input: String): String {
val items = getItems()
return """
|Based on the , identify whether the user is asking about one or more of the following items
|
|${
items.joinToString("\n") { item -> "<${item.name}>${item.description}${item.name}>" }
}
|
|
|${
items.mapIndexed { index, item -> "\t- ${item.name}
" }
.joinToString("\n")
}
|
|
|$input
|
"""
}
@OptIn(ExperimentalSerializationApi::class)
fun KType.enumValuesName(serializer: KSerializer = serializer(this)): List {
return if (serializer.descriptor.kind != SerialKind.ENUM) {
emptyList()
} else {
(0 until serializer.descriptor.elementsCount).map { index ->
val name =
serializer.descriptor.getElementName(index).removePrefix(serializer.descriptor.serialName)
val description =
(serializer.descriptor.getElementAnnotations(index).first { it is Description }
as Description)
.value
Classification(name, description)
}
}
}
}