d68e759873
1、修复agent run的结果文字显示、保存DB✓ 2、区分文字输入和语音输入✓ 3、修复Speech.close bug✓ 4、增加个人信息存入向量库✓ 5、修复处理时间计算不准确✓ 6、修复gpt key出错✓
33 lines
830 B
Python
33 lines
830 B
Python
import abc
|
||
import math
|
||
from typing import Any
|
||
|
||
from langchain.tools import BaseTool
|
||
|
||
|
||
class Calculator(BaseTool, abc.ABC):
|
||
name = "Calculator"
|
||
description = "Useful for when you need to answer questions about math(不能用于时间计划)"
|
||
|
||
def __init__(self):
|
||
super().__init__()
|
||
|
||
async def _arun(self, *args: Any, **kwargs: Any) -> Any:
|
||
# 用例中没有用到 arun 不予具体实现
|
||
pass
|
||
|
||
|
||
def _run(self, para: str) -> str:
|
||
para = para.replace("^", "**")
|
||
if "sqrt" in para:
|
||
para = para.replace("sqrt", "math.sqrt")
|
||
elif "log" in para:
|
||
para = para.replace("log", "math.log")
|
||
return eval(para)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
calculator_tool = Calculator()
|
||
result = calculator_tool.run("sqrt(2) + 3")
|
||
print(result)
|