-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support enum descriptions * added example --------- Co-authored-by: José Carlos Montañez <jc@MacBook-Pro.local> Co-authored-by: Raúl Raja Martínez <raulraja@gmail.com>
- Loading branch information
1 parent
e1b6807
commit 6a3fa58
Showing
2 changed files
with
54 additions
and
17 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
36 changes: 36 additions & 0 deletions
36
examples/src/main/kotlin/com/xebia/functional/xef/assistants/ToolsWithDescriptions.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,36 @@ | ||
package com.xebia.functional.xef.assistants | ||
|
||
import com.xebia.functional.xef.conversation.Description | ||
import com.xebia.functional.xef.llm.assistants.Assistant | ||
import com.xebia.functional.xef.llm.assistants.AssistantThread | ||
import com.xebia.functional.xef.llm.assistants.RunDelta | ||
import com.xebia.functional.xef.llm.assistants.Tool | ||
import kotlinx.serialization.Serializable | ||
|
||
@Description("Natural numbers") | ||
enum class NaturalWithDescriptions { | ||
@Description("If the number is positive.") POSITIVE, | ||
@Description("If the number is negative.") NEGATIVE | ||
} | ||
|
||
@Serializable | ||
data class SumInputWithDescription( | ||
@Description("Left operand") val left: Int, | ||
@Description("Right operand") val right: Int, | ||
val natural: NaturalWithDescriptions | ||
) | ||
|
||
class SumToolWithDescription : Tool<SumInputWithDescription, Int> { | ||
override suspend fun invoke(input: SumInputWithDescription): Int { | ||
return input.left + input.right | ||
} | ||
} | ||
|
||
suspend fun main() { | ||
val toolConfig = Tool.toolOf(SumToolWithDescription()).functionObject | ||
println(toolConfig.parameters) | ||
} | ||
|
||
private suspend fun runAssistantAndDisplayResults(thread: AssistantThread, assistant: Assistant) { | ||
thread.run(assistant).collect(RunDelta::printEvent) | ||
} |