mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-18 14:27:10 +00:00
fix: 加个天气小工具
This commit is contained in:
parent
39478d2928
commit
e192e51ef2
7 changed files with 104 additions and 30 deletions
32
utils/tools/WeatherTool.js
Normal file
32
utils/tools/WeatherTool.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import { AbstractTool } from './AbstractTool.js'
|
||||
import {Config} from "../config.js";
|
||||
|
||||
export class WeatherTool extends AbstractTool {
|
||||
name = 'weather'
|
||||
|
||||
parameters = {
|
||||
properties: {
|
||||
city: {
|
||||
type: 'string',
|
||||
description: '要查询的地点,细化到县/区级'
|
||||
}
|
||||
},
|
||||
required: ['city']
|
||||
}
|
||||
|
||||
func = async function (opts) {
|
||||
let { city } = opts
|
||||
let key = Config.amapKey
|
||||
|
||||
let adcodeRes = await fetch(`https://restapi.amap.com/v3/config/district?keywords=${city}&subdistrict=1&key=${key}`)
|
||||
adcodeRes = await adcodeRes.json()
|
||||
let adcode = adcodeRes.districts[0].adcode
|
||||
let cityName = adcodeRes.districts[0].name
|
||||
let res = await fetch(`https://restapi.amap.com/v3/weather/weatherInfo?city=${adcode}&key=${key}`)
|
||||
res = await res.json()
|
||||
let result = res.lives[0]
|
||||
return `the weather information of area ${cityName} in json format is:\n${JSON.stringify(result)}`
|
||||
}
|
||||
|
||||
description = 'Useful when you want to query weather '
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue