Skip to content

Commit

Permalink
Remove Java code and use Kotlin instead
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcheng1982 committed Oct 1, 2024
1 parent ebf8370 commit eccb17f
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 83 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ko_fi: alexcheng1982
github: alexcheng1982

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.github.llmagentbuilder.tool.readlocalfile

data class ReadLocalFileConfig(
val basePath: String,
val charset: String?
)

data class ReadLocalFileRequest(val filePath: String)

data class ReadLocalFileResponse(val content: String)

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.github.llmagentbuilder.tool.writelocalfile

data class WriteLocalFileConfig(val basePath: String)

data class WriteLocalFileRequest(
val filename: String,
val url: String,
val content: String,
val append: Boolean,
)

data class WriteLocalFileResponse(
val path: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import java.net.URI
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.StandardOpenOption
import java.util.*

Expand All @@ -30,13 +29,13 @@ class WriteLocalFileTool(private val config: WriteLocalFileConfig) :
val savePath = calculateSavePath(request)
if (StringUtils.isNotEmpty(request.content)) {
Files.writeString(
savePath, request.content(), StandardCharsets.UTF_8,
savePath, request.content, StandardCharsets.UTF_8,
StandardOpenOption.CREATE,
if (request.append) StandardOpenOption.APPEND else StandardOpenOption.TRUNCATE_EXISTING
)
} else if (StringUtils.isNotEmpty(request.url)) {
FileUtils.copyURLToFile(
URI(request.url()).toURL(),
URI(request.url).toURL(),
savePath.toFile()
)
}
Expand All @@ -61,10 +60,8 @@ class WriteLocalFileTool(private val config: WriteLocalFileConfig) :
private fun calculateSavePath(request: WriteLocalFileRequest): Path {
val basePath = StringUtils.trimToNull(config.basePath)
val saveFileDir = basePath?.run {
Paths.get(this)
} ?: Files.createTempDirectory(
"${toolName}_"
)
Path.of(this)
} ?: Path.of(".")
val filename = StringUtils.trimToNull(request.filename)
return saveFileDir.resolve(filename ?: UUID.randomUUID().toString())
.toAbsolutePath()
Expand Down

0 comments on commit eccb17f

Please sign in to comment.