-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New PromptBuilder returning list of messages (#326)
* New PromptBuilder returning list of messages * Comments addressed --------- Co-authored-by: Raúl Raja Martínez <[email protected]>
- Loading branch information
1 parent
07a86c9
commit d46e052
Showing
23 changed files
with
425 additions
and
349 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 4 additions & 8 deletions
12
core/src/commonMain/kotlin/com/xebia/functional/xef/llm/models/chat/Message.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,10 @@ | ||
package com.xebia.functional.xef.llm.models.chat | ||
|
||
import kotlin.jvm.JvmStatic | ||
|
||
data class Message(val role: Role, val content: String, val name: String) { | ||
companion object { | ||
suspend fun systemMessage(message: suspend () -> String) = | ||
Message(role = Role.SYSTEM, content = message(), name = Role.SYSTEM.name) | ||
|
||
suspend fun userMessage(message: suspend () -> String) = | ||
Message(role = Role.USER, content = message(), name = Role.USER.name) | ||
|
||
suspend fun assistantMessage(message: suspend () -> String) = | ||
Message(role = Role.ASSISTANT, content = message(), name = Role.ASSISTANT.name) | ||
@JvmStatic | ||
fun apply(role: Role, content: String, name: String): Message = Message(role, content, name) | ||
} | ||
} |
22 changes: 0 additions & 22 deletions
22
core/src/commonMain/kotlin/com/xebia/functional/xef/prompt/Builder.kt
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
core/src/commonMain/kotlin/com/xebia/functional/xef/prompt/PromptBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.xebia.functional.xef.prompt | ||
|
||
import com.xebia.functional.xef.llm.models.chat.Message | ||
import com.xebia.functional.xef.llm.models.chat.Role | ||
|
||
open class PromptBuilder { | ||
private val items = mutableListOf<Message>() | ||
|
||
operator fun Message.unaryPlus() { | ||
items.add(this) | ||
} | ||
|
||
operator fun List<Message>.unaryPlus() { | ||
items.addAll(this) | ||
} | ||
|
||
protected open fun preprocess(elements: List<Message>): List<Message> = elements | ||
|
||
fun build(): List<Message> = preprocess(items) | ||
} | ||
|
||
fun String.message(role: Role): Message = Message(role, this, role.name) | ||
|
||
fun buildPrompt(block: PromptBuilder.() -> Unit): List<Message> = | ||
PromptBuilder().apply { block() }.build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
core/src/commonMain/kotlin/com/xebia/functional/xef/prompt/experts/ExpertSystem.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 0 additions & 45 deletions
45
core/src/commonMain/kotlin/com/xebia/functional/xef/prompt/models.kt
This file was deleted.
Oops, something went wrong.
57 changes: 32 additions & 25 deletions
57
core/src/commonMain/kotlin/com/xebia/functional/xef/prompt/templates/templates.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.