-
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.
Allow
@Schema
on Tool requests and read description
from annotati…
…on when available. (#771)
- Loading branch information
Showing
3 changed files
with
90 additions
and
7 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
core/src/commonMain/kotlin/com/xebia/functional/xef/conversation/Schema.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,11 @@ | ||
package com.xebia.functional.xef.conversation | ||
|
||
import kotlinx.serialization.ExperimentalSerializationApi | ||
import kotlinx.serialization.SerialInfo | ||
|
||
/** Schema for a tool request */ | ||
@OptIn(ExperimentalSerializationApi::class) | ||
@SerialInfo | ||
@Retention(AnnotationRetention.RUNTIME) | ||
@Target(AnnotationTarget.CLASS) | ||
annotation class Schema(val value: String) |
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
55 changes: 55 additions & 0 deletions
55
core/src/commonTest/kotlin/com/xebia/functional/xef/functions/FunctionSchemaTests.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,55 @@ | ||
package com.xebia.functional.xef.functions | ||
|
||
import com.xebia.functional.xef.conversation.Description | ||
import com.xebia.functional.xef.conversation.Schema | ||
import com.xebia.functional.xef.llm.chatFunction | ||
import com.xebia.functional.xef.llm.defaultFunctionDescription | ||
import com.xebia.functional.xef.llm.functionName | ||
import com.xebia.functional.xef.llm.models.functions.buildJsonSchema | ||
import io.kotest.core.spec.style.StringSpec | ||
import io.kotest.matchers.shouldBe | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.json.JsonObject | ||
|
||
class FunctionSchemaTests : | ||
StringSpec({ | ||
"Request has default description" { | ||
val descriptor = Request.serializer().descriptor | ||
val function = chatFunction(descriptor) | ||
val fnName = functionName(descriptor) | ||
function.description shouldBe defaultFunctionDescription(fnName) | ||
} | ||
|
||
"Description can be set on request" { | ||
val descriptor = RequestWithDescription.serializer().descriptor | ||
val function = chatFunction(descriptor) | ||
function.description shouldBe "Request With Description" | ||
} | ||
|
||
"Schema can be generated on request" { | ||
val descriptor = Request.serializer().descriptor | ||
val function = chatFunction(descriptor) | ||
function.parameters shouldBe buildJsonSchema(descriptor) | ||
} | ||
|
||
"Schema can be set on request" { | ||
val descriptor = RequestWithSchema.serializer().descriptor | ||
val function = chatFunction(descriptor) | ||
function.parameters shouldBe JsonObject(emptyMap()) | ||
} | ||
}) { | ||
|
||
@Serializable data class Request(val input: String) | ||
|
||
@Serializable | ||
@Description("Request With Description") | ||
data class RequestWithDescription(val input: String) | ||
|
||
@Serializable | ||
@Description("Request with schema") | ||
@Schema(""" | ||
{ | ||
} | ||
""") | ||
data class RequestWithSchema(val input: String) | ||
} |