You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you want to map the role of a message for the presentation layer, for example, this is not possible with an exact mapping using the value class. Because a role could also theoretically be Role("Tom"). But the only accepted values of OpenAi are all contained in the class. You always need an unnecessary else branch, which then throws an exception or you introduce an unknown role in the presentantion layer for mapping in else branch.
@JvmInline
@Serializable
public value class Role(public val role: String) {
public companion object {
public val System: Role = Role("system")
public val User: Role = Role("user")
public val Assistant: Role = Role("assistant")
public val Function: Role = Role("function")
public val Tool: Role = Role("tool")
}
}
sealed class Role(val role: String) {
data object System: Role("system")
data object Assistant: Role("assistant")
data object User: Role("user")
data object Tool: Role("tool")
data object Function: Role("function")
}
Additional Context
If anyone has a better solution on how to solve the problem, I would be very grateful.
The text was updated successfully, but these errors were encountered:
wolfscowl
changed the title
Value class roll no suitable for mapping, Why not a sealed class with data objects?
Value class roll not best solution for mapping, Why not a sealed class with data objects?
Jun 22, 2024
wolfscowl
changed the title
Value class roll not best solution for mapping, Why not a sealed class with data objects?
Value class Roll not best solution for mapping. Why not a sealed class with data objects?
Jun 22, 2024
Feature Description
If you want to map the role of a message for the presentation layer, for example, this is not possible with an exact mapping using the value class. Because a role could also theoretically be Role("Tom"). But the only accepted values of OpenAi are all contained in the class. You always need an unnecessary else branch, which then throws an exception or you introduce an unknown role in the presentantion layer for mapping in else branch.
Problem it Solves
Proposed Solution
Additional Context
If anyone has a better solution on how to solve the problem, I would be very grateful.
The text was updated successfully, but these errors were encountered: