olivebot/agent/tools/Weather.py

28 lines
659 B
Python
Raw Normal View History

2023-12-12 00:03:36 +08:00
import os
from typing import Any
import requests
from langchain.tools import BaseTool
class Weather(BaseTool):
name = "weather"
description = "Use for searching weather at a specific location"
def __init__(self):
super().__init__()
async def _arun(self, *args: Any, **kwargs: Any) -> Any:
# 用例中没有用到 arun 不予具体实现
pass
def _run(self, para: str) -> str:
return "今天天气晴朗风和日丽气温25度空气十分清新心情美美哒"
if __name__ == "__main__":
weather_tool = Weather()
weather_info = weather_tool.run("成都")
print(weather_info)