mirror of
https://github.com/jie65535/JChatGPT.git
synced 2026-06-23 00:49:31 +08:00
Optimize search results
Add Weather Service Agent Add Crazy Thursday Agent
This commit is contained in:
56
src/main/kotlin/tools/WeatherService.kt
Normal file
56
src/main/kotlin/tools/WeatherService.kt
Normal file
@@ -0,0 +1,56 @@
|
||||
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 WeatherService : BaseAgent(
|
||||
tool = Tool.function(
|
||||
name = "queryWeather",
|
||||
description = "可用于查询某城市地区天气.",
|
||||
parameters = Parameters.buildJsonObject {
|
||||
put("type", "object")
|
||||
putJsonObject("properties") {
|
||||
putJsonObject("city") {
|
||||
put("type", "string")
|
||||
put("description", "城市地区,如\"深圳市\"")
|
||||
}
|
||||
putJsonObject("time_range") {
|
||||
put("type", "string")
|
||||
putJsonArray("enum") {
|
||||
add("day")
|
||||
add("three")
|
||||
add("many")
|
||||
}
|
||||
put("description", "时间范围,仅当天天气可获得最详细信息,三天和更多只能获得简单信息。")
|
||||
}
|
||||
}
|
||||
putJsonArray("required") {
|
||||
add("city")
|
||||
}
|
||||
}
|
||||
)
|
||||
) {
|
||||
override val loadingMessage: String
|
||||
get() = "查询天气中..."
|
||||
|
||||
override suspend fun execute(args: JsonObject?): String {
|
||||
requireNotNull(args)
|
||||
val city = args.getValue("city").jsonPrimitive.content
|
||||
val timeRange = args["time_range"]?.jsonPrimitive?.contentOrNull
|
||||
val response = httpClient.get(
|
||||
buildString {
|
||||
append(when (timeRange) {
|
||||
"many" -> "https://api.52vmy.cn/api/query/tian/many"
|
||||
"three" -> "https://api.52vmy.cn/api/query/tian/three"
|
||||
else -> "https://api.52vmy.cn/api/query/tian"
|
||||
})
|
||||
append("?city=")
|
||||
append(city)
|
||||
}
|
||||
)
|
||||
return response.bodyAsText()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user