-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
71c7239
commit 2283155
Showing
50 changed files
with
945 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
# LLM Agent Builder Toolkit - File | ||
# LLM Agent Builder Tools | ||
|
||
Tools in this toolkit: | ||
Tools: | ||
|
||
* `readLocalFile` | ||
* `writeLocalFile` | ||
* `writeLocalFile` | ||
* `runSqlQuery` | ||
|
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,30 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.github.llmagentbuilder</groupId> | ||
<artifactId>tools</artifactId> | ||
<version>0.2.0</version> | ||
</parent> | ||
|
||
<artifactId>tool-baidu-hot-search</artifactId> | ||
<name>LLM Agent Builder :: Tool :: Baidu Hot Search</name> | ||
<description>LLM Agent Builder :: Tool :: Baidu Hot Search</description> | ||
|
||
<properties> | ||
<maven.compiler.source>${java.version}</maven.compiler.source> | ||
<maven.compiler.target>${java.version}</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.github.llmagentbuilder</groupId> | ||
<artifactId>web-scraper</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
7 changes: 7 additions & 0 deletions
7
...rch/src/main/kotlin/io/github/llmagentbuilder/tool/baiduhotsearch/BaiduHotSearchConfig.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,7 @@ | ||
package io.github.llmagentbuilder.tool.baiduhotsearch | ||
|
||
data class BaiduHotSearchConfig(val numberOfItems: Int? = null) | ||
|
||
data class BaiduHotSearchRequest(val numberOfItems: Int? = null) | ||
|
||
data class BaiduHotSearchResponse(val results: List<String>? = null) |
38 changes: 38 additions & 0 deletions
38
...earch/src/main/kotlin/io/github/llmagentbuilder/tool/baiduhotsearch/BaiduHotSearchTool.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,38 @@ | ||
package io.github.llmagentbuilder.tool.baiduhotsearch | ||
|
||
import io.github.llmagentbuilder.core.tool.ConfigurableAgentTool | ||
import io.github.llmagentbuilder.webscraper.WebScraper | ||
import org.slf4j.LoggerFactory | ||
|
||
const val toolId = "baiduHotSearch" | ||
|
||
class BaiduHotSearchTool(private val config: BaiduHotSearchConfig?) : | ||
ConfigurableAgentTool<BaiduHotSearchRequest, BaiduHotSearchResponse, BaiduHotSearchConfig> { | ||
|
||
private val logger = LoggerFactory.getLogger(javaClass) | ||
|
||
init { | ||
logger.info("Created with config: $config") | ||
} | ||
|
||
override fun apply(request: BaiduHotSearchRequest): BaiduHotSearchResponse { | ||
return BaiduHotSearchResponse( | ||
WebScraper.textList( | ||
"https://top.baidu.com/board?tab=realtime", | ||
".c-single-text-ellipsis" | ||
).take((config?.numberOfItems ?: 10).coerceAtLeast(1)) | ||
) | ||
} | ||
|
||
override fun description(): String { | ||
return "find hot search keywords in Baidu" | ||
} | ||
|
||
override fun id(): String { | ||
return toolId | ||
} | ||
|
||
override fun name(): String { | ||
return toolId | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...rc/main/kotlin/io/github/llmagentbuilder/tool/baiduhotsearch/BaiduHotSearchToolFactory.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,15 @@ | ||
package io.github.llmagentbuilder.tool.baiduhotsearch | ||
|
||
import io.github.llmagentbuilder.core.tool.ConfigurableAgentToolFactory | ||
|
||
class BaiduHotSearchToolFactory : | ||
ConfigurableAgentToolFactory<BaiduHotSearchConfig, BaiduHotSearchTool> { | ||
override fun toolId(): String { | ||
return toolId | ||
} | ||
|
||
override fun create(config: BaiduHotSearchConfig?): BaiduHotSearchTool { | ||
return BaiduHotSearchTool(config) | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
...src/main/resources/META-INF/services/io.github.llmagentbuilder.core.tool.AgentToolFactory
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 @@ | ||
io.github.llmagentbuilder.tool.baiduhotsearch.BaiduHotSearchToolFactory |
17 changes: 17 additions & 0 deletions
17
...h/src/test/kotlin/io/github/llmagentbuilder/tool/baiduhotsearch/BaiduHotSearchToolTest.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,17 @@ | ||
package io.github.llmagentbuilder.tool.baiduhotsearch | ||
|
||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Assertions.assertNotNull | ||
import org.junit.jupiter.api.Test | ||
|
||
class BaiduHotSearchToolTest { | ||
@Test | ||
fun find() { | ||
val results = BaiduHotSearchTool(BaiduHotSearchConfig()).apply( | ||
BaiduHotSearchRequest(10) | ||
) | ||
.results | ||
assertNotNull(results) | ||
assertEquals(10, results?.size) | ||
} | ||
} |
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,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.github.llmagentbuilder</groupId> | ||
<artifactId>tools</artifactId> | ||
<version>0.2.0</version> | ||
</parent> | ||
|
||
<artifactId>tool-baidu-search</artifactId> | ||
<name>LLM Agent Builder :: Tool :: Baidu Search</name> | ||
<description>LLM Agent Builder :: Tool :: Baidu Search</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.github.llmagentbuilder</groupId> | ||
<artifactId>web-scraper</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
12 changes: 12 additions & 0 deletions
12
baidu-search/src/main/kotlin/io/github/llmagentbuilder/tool/baidusearch/BaiduSearchConfig.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,12 @@ | ||
package io.github.llmagentbuilder.tool.baidusearch | ||
|
||
data class BaiduSearchConfig(val numberOfItems: Int? = null) | ||
|
||
data class BaiduSearchRequest(val keyword: String? = null) | ||
|
||
data class BaiduSearchResultItem( | ||
val title: String? = null, | ||
val url: String? = null | ||
) | ||
|
||
data class BaiduSearchResponse(val items: List<BaiduSearchResultItem>? = null) |
40 changes: 40 additions & 0 deletions
40
baidu-search/src/main/kotlin/io/github/llmagentbuilder/tool/baidusearch/BaiduSearchTool.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,40 @@ | ||
package io.github.llmagentbuilder.tool.baidusearch | ||
|
||
import io.github.llmagentbuilder.core.tool.ConfigurableAgentTool | ||
import io.github.llmagentbuilder.webscraper.WebScraper | ||
import org.slf4j.LoggerFactory | ||
|
||
const val toolId = "baiduSearch" | ||
|
||
class BaiduSearchTool(private val config: BaiduSearchConfig?) : | ||
ConfigurableAgentTool<BaiduSearchRequest, BaiduSearchResponse, BaiduSearchConfig> { | ||
|
||
private val logger = LoggerFactory.getLogger(javaClass) | ||
|
||
init { | ||
logger.info("Created with config: $config") | ||
} | ||
|
||
override fun apply(request: BaiduSearchRequest): BaiduSearchResponse { | ||
return BaiduSearchResponse( | ||
WebScraper.links( | ||
"https://www.baidu.com/s?wd=${request.keyword}", | ||
".c-container h3 a" | ||
).map { | ||
BaiduSearchResultItem(it.title, it.href) | ||
}.take((config?.numberOfItems ?: 10).coerceAtLeast(1)) | ||
) | ||
} | ||
|
||
override fun description(): String { | ||
return "Search web content using Baidu" | ||
} | ||
|
||
override fun id(): String { | ||
return toolId | ||
} | ||
|
||
override fun name(): String { | ||
return toolId | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...arch/src/main/kotlin/io/github/llmagentbuilder/tool/baidusearch/BaiduSearchToolFactory.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,14 @@ | ||
package io.github.llmagentbuilder.tool.baidusearch | ||
|
||
import io.github.llmagentbuilder.core.tool.ConfigurableAgentToolFactory | ||
|
||
class BaiduSearchToolFactory : | ||
ConfigurableAgentToolFactory<BaiduSearchConfig, BaiduSearchTool> { | ||
override fun create(config: BaiduSearchConfig?): BaiduSearchTool { | ||
return BaiduSearchTool(config) | ||
} | ||
|
||
override fun toolId(): String { | ||
return toolId | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...src/main/resources/META-INF/services/io.github.llmagentbuilder.core.tool.AgentToolFactory
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 @@ | ||
io.github.llmagentbuilder.tool.baidusearch.BaiduSearchToolFactory |
13 changes: 13 additions & 0 deletions
13
...-search/src/test/kotlin/io/github/llmagentbuilder/tool/baidusearch/BaiduSearchToolTest.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,13 @@ | ||
package io.github.llmagentbuilder.tool.baidusearch | ||
|
||
import org.junit.jupiter.api.Test | ||
import kotlin.test.assertNotNull | ||
|
||
class BaiduSearchToolTest { | ||
@Test | ||
fun testSearch() { | ||
val tool = BaiduSearchTool(BaiduSearchConfig()) | ||
val items = tool.apply(BaiduSearchRequest("AI大模型")).items | ||
assertNotNull(items) | ||
} | ||
} |
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,24 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.github.llmagentbuilder</groupId> | ||
<artifactId>tools</artifactId> | ||
<version>0.2.0</version> | ||
</parent> | ||
|
||
<artifactId>code-execution</artifactId> | ||
<name>LLM Agent Builder :: Code Execution</name> | ||
<description>LLM Agent Builder :: Code Execution</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.buildobjects</groupId> | ||
<artifactId>jproc</artifactId> | ||
<version>2.8.2</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
1 change: 1 addition & 0 deletions
1
code-execution/src/main/java/io/github/llmagentbuilder/codeexecution/package-info.java
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 @@ | ||
package io.github.llmagentbuilder.codeexecution; |
19 changes: 19 additions & 0 deletions
19
code-execution/src/main/kotlin/io/github/llmagentbuilder/codeexecution/CodeExecutor.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,19 @@ | ||
package io.github.llmagentbuilder.codeexecution | ||
|
||
import java.nio.file.Files | ||
import kotlin.io.path.writeText | ||
|
||
/** | ||
* Code executor | ||
*/ | ||
interface CodeExecutor { | ||
fun execute(input: String): String | ||
} | ||
|
||
object CodeExecutionHelper { | ||
fun inputToFile(input: String, suffix: String): String { | ||
val file = Files.createTempFile("code-execution-", suffix) | ||
file.writeText(input) | ||
return file.toAbsolutePath().toString() | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...n/kotlin/io/github/llmagentbuilder/codeexecution/nonsandboxed/NonSandboxedCodeExecutor.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,23 @@ | ||
package io.github.llmagentbuilder.codeexecution.nonsandboxed | ||
|
||
import io.github.llmagentbuilder.codeexecution.CodeExecutor | ||
import org.buildobjects.process.ProcBuilder | ||
import java.nio.file.Paths | ||
|
||
abstract class NonSandboxedCodeExecutor : CodeExecutor { | ||
override fun execute(input: String): String { | ||
val result = ProcBuilder(executable()) | ||
.withArgs(*args(input).toTypedArray()) | ||
.withWorkingDirectory( | ||
(workingDirectory() ?: ".") | ||
.run { Paths.get(this).toAbsolutePath().normalize() } | ||
.toFile()) | ||
.ignoreExitStatus() | ||
.run() | ||
return result.outputString.trim() | ||
} | ||
|
||
abstract fun executable(): String | ||
abstract fun workingDirectory(): String? | ||
abstract fun args(input: String): List<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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.github.llmagentbuilder</groupId> | ||
<artifactId>tools</artifactId> | ||
<version>0.2.0</version> | ||
</parent> | ||
|
||
<artifactId>tool-java-code-execution</artifactId> | ||
<name>LLM Agent Builder :: Tool :: Java Code Execution</name> | ||
<description>LLM Agent Builder :: Tool :: Java Code Execution</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.github.llmagentbuilder</groupId> | ||
<artifactId>code-execution</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
32 changes: 32 additions & 0 deletions
32
...c/main/java/io/github/llmagentbuilder/tool/javacodeexecution/JavaCodeExecutionConfig.java
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,32 @@ | ||
package io.github.llmagentbuilder.tool.javacodeexecution; | ||
|
||
public class JavaCodeExecutionConfig { | ||
|
||
private String executable; | ||
|
||
private String workingDirectory; | ||
|
||
public String getExecutable() { | ||
return executable; | ||
} | ||
|
||
public void setExecutable(String executable) { | ||
this.executable = executable; | ||
} | ||
|
||
public String getWorkingDirectory() { | ||
return workingDirectory; | ||
} | ||
|
||
public void setWorkingDirectory(String workingDirectory) { | ||
this.workingDirectory = workingDirectory; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "JavaCodeExecutionConfig{" + | ||
"executable='" + executable + '\'' + | ||
", workingDirectory='" + workingDirectory + '\'' + | ||
'}'; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
.../main/java/io/github/llmagentbuilder/tool/javacodeexecution/JavaCodeExecutionRequest.java
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,5 @@ | ||
package io.github.llmagentbuilder.tool.javacodeexecution; | ||
|
||
public record JavaCodeExecutionRequest(String code) { | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
...main/java/io/github/llmagentbuilder/tool/javacodeexecution/JavaCodeExecutionResponse.java
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,5 @@ | ||
package io.github.llmagentbuilder.tool.javacodeexecution; | ||
|
||
public record JavaCodeExecutionResponse(String result) { | ||
|
||
} |
Oops, something went wrong.