OpenBMB / BMTools

Tool Learning for Big Models, Open-Source Solutions of ChatGPT-Plugins
Apache License 2.0
2.91k stars 273 forks source link

KeyError: 'type'的问题 #28

Closed Lihengwannafly closed 1 year ago

Lihengwannafly commented 1 year ago

当使用map tool的时候,会产生KeyError: 'type'的报错,这是由于bmtools/tools/map/api.py里每个方法的参数没有指定类型,例如:

    @tool.get("/get_coordinates")
    def get_coordinates(location):
        """Get the coordinates of a location"""
        url = BASE_URL + "Locations"
        params = {
            "query": location,
            "key": KEY
        }
        response = requests.get(url, params=params)
        json_data = response.json()
        coordinates = json_data["resourceSets"][0]["resources"][0]["point"]["coordinates"]
        return coordinates,

需要给location添加str的类型,修改后的代码是:

    @tool.get("/get_coordinates")
    def get_coordinates(location: str):
        """Get the coordinates of a location"""
        url = BASE_URL + "Locations"
        params = {
            "query": location,
            "key": KEY
        }
        response = requests.get(url, params=params)
        json_data = response.json()
        coordinates = json_data["resourceSets"][0]["resources"][0]["point"]["coordinates"]
        return coordinates
thuqinyj16 commented 1 year ago

感谢指出!麻烦 @Kunlun-Zhu 改一下吧,map和stock里都需要改一下