-
Notifications
You must be signed in to change notification settings - Fork 1
/
CreateFile.kt
42 lines (38 loc) · 1.13 KB
/
CreateFile.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.xemantic.claudine.tool
import com.xemantic.anthropic.schema.Description
import com.xemantic.anthropic.tool.AnthropicTool
import com.xemantic.anthropic.tool.ToolInput
import kotlinx.io.buffered
import kotlinx.io.files.Path
import kotlinx.io.files.SystemFileSystem
import kotlinx.io.writeString
import kotlin.io.encoding.Base64
import kotlin.io.encoding.ExperimentalEncodingApi
@OptIn(ExperimentalEncodingApi::class)
@AnthropicTool("CreateFile")
@Description("Creates a file on human's machine")
data class CreateFile(
@Description("The absolute file path")
val path: String,
@Description("The content to write")
val fileContent: String,
@Description(
"If the file content is binary, it will be transferred as Base64 encoded string." +
"Defaults to false if omitted."
)
val base64: Boolean? = null
) : ToolInput() {
init {
use {
val file = Path(path = path)
SystemFileSystem.sink(file).buffered().use { sink ->
if (base64 == true) {
sink.write(Base64.decode(fileContent))
} else {
sink.writeString(fileContent)
}
}
"File created"
}
}
}