Skip to content

Commit

Permalink
fix: the old @SerializableTool remaining renamed to @AnthropicTool in…
Browse files Browse the repository at this point in the history
… exception messages nad unit tests
  • Loading branch information
morisil committed Oct 15, 2024
1 parent 7ea1c6f commit baf3d1c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/commonMain/kotlin/tool/Tools.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ inline fun <reified T : UsableTool> toolOf(

val serializer = try {
serializer<T>()
} catch (e :SerializationException) {
} catch (e: SerializationException) {
throw SerializationException(
"The class ${T::class.qualifiedName} must be annotated with @SerializableTool", e
nonAnnotatedToolMessage<T>(), e
)
}

Expand All @@ -72,7 +72,7 @@ inline fun <reified T : UsableTool> toolOf(
.annotations
.filterIsInstance<AnthropicTool>()
.firstOrNull() ?: throw SerializationException(
"The class ${T::class.qualifiedName} must be annotated with @SerializableTool",
nonAnnotatedToolMessage<T>()
)

return Tool(
Expand All @@ -82,3 +82,7 @@ inline fun <reified T : UsableTool> toolOf(
cacheControl = cacheControl
)
}

@PublishedApi
internal inline fun <reified T> nonAnnotatedToolMessage() =
"The class ${T::class.qualifiedName} must be annotated with @AnthropicTool"
4 changes: 2 additions & 2 deletions src/commonTest/kotlin/tool/UsableToolTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class UsableToolTest {
@Test
fun shouldFailToCreateToolWithoutAnthropicToolAnnotation() {
shouldThrowWithMessage<SerializationException>(
"The class com.xemantic.anthropic.tool.UsableToolTest.NoAnnotationTool must be annotated with @SerializableTool"
"The class com.xemantic.anthropic.tool.UsableToolTest.NoAnnotationTool must be annotated with @AnthropicTool"
) {
toolOf<NoAnnotationTool>()
}
Expand All @@ -84,7 +84,7 @@ class UsableToolTest {
@Test
fun shouldFailToCreateToolWithOnlySerializableAnnotation() {
shouldThrowWithMessage<SerializationException>(
"The class com.xemantic.anthropic.tool.UsableToolTest.OnlySerializableAnnotationTool must be annotated with @SerializableTool"
"The class com.xemantic.anthropic.tool.UsableToolTest.OnlySerializableAnnotationTool must be annotated with @AnthropicTool"
) {
toolOf<OnlySerializableAnnotationTool>()
}
Expand Down

0 comments on commit baf3d1c

Please sign in to comment.