mirror of
https://github.com/jie65535/JChatGPT.git
synced 2025-06-02 17:39:10 +08:00
Add IP Address query
This commit is contained in:
parent
12df62d7fe
commit
ef25b06aab
@ -279,7 +279,8 @@ object JChatGPT : KotlinPlugin(
|
||||
private val myTools = listOf(
|
||||
WebSearch(),
|
||||
WeatherService(),
|
||||
CrazyKfc()
|
||||
CrazyKfc(),
|
||||
IpAddressQuery(),
|
||||
)
|
||||
|
||||
|
||||
|
33
src/main/kotlin/tools/IpAddressQuery.kt
Normal file
33
src/main/kotlin/tools/IpAddressQuery.kt
Normal file
@ -0,0 +1,33 @@
|
||||
package top.jie65535.mirai.tools
|
||||
|
||||
import com.aallam.openai.api.chat.Tool
|
||||
import com.aallam.openai.api.core.Parameters
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.statement.*
|
||||
import kotlinx.serialization.json.*
|
||||
|
||||
class IpAddressQuery : BaseAgent(
|
||||
tool = Tool.function(
|
||||
name = "ipAddressQuery",
|
||||
description = "可查询IP地址归属地",
|
||||
parameters = Parameters.buildJsonObject {
|
||||
put("type", "object")
|
||||
putJsonObject("properties") {
|
||||
putJsonObject("ip") {
|
||||
put("type", "string")
|
||||
put("description", "IPv4地址")
|
||||
}
|
||||
}
|
||||
putJsonArray("required") {
|
||||
add("ip")
|
||||
}
|
||||
}
|
||||
)
|
||||
) {
|
||||
override suspend fun execute(args: JsonObject?): String {
|
||||
requireNotNull(args)
|
||||
val ip = args.getValue("ip").jsonPrimitive.content
|
||||
val response = httpClient.get("https://api.52vmy.cn/api/query/itad?ip=$ip")
|
||||
return response.bodyAsText()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user