del_substr_tool.py 536 B

12345678910111213141516171819202122
  1. from langchain.agents.tools import BaseTool
  2. from pydantic import BaseModel, Field
  3. from typing import Type
  4. class DelSubstrToolInput(BaseModel):
  5. text: str = Field(description="原字符串")
  6. content: str = Field(description="去除的内容")
  7. class DelSubstrTool(BaseTool):
  8. name: str = "remove_str"
  9. description: str = (
  10. "去除字符串的指定的内容"
  11. )
  12. args_schema: Type[BaseModel] = DelSubstrToolInput
  13. def _run(self, text: str, content: str):
  14. return text.replace(r"{content}","")