{"id":13545799,"url":"https://github.com/OpenBMB/BMTools","last_synced_at":"2025-04-02T17:31:48.244Z","repository":{"id":153535718,"uuid":"621705019","full_name":"OpenBMB/BMTools","owner":"OpenBMB","description":"Tool Learning for Big Models, Open-Source Solutions of ChatGPT-Plugins","archived":false,"fork":false,"pushed_at":"2023-12-05T05:25:27.000Z","size":23666,"stargazers_count":2776,"open_issues_count":12,"forks_count":258,"subscribers_count":35,"default_branch":"main","last_synced_at":"2025-03-30T19:03:57.657Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OpenBMB.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-03-31T08:00:43.000Z","updated_at":"2025-03-25T06:40:16.000Z","dependencies_parsed_at":"2023-12-05T06:38:44.553Z","dependency_job_id":null,"html_url":"https://github.com/OpenBMB/BMTools","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenBMB%2FBMTools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenBMB%2FBMTools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenBMB%2FBMTools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenBMB%2FBMTools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OpenBMB","download_url":"https://codeload.github.com/OpenBMB/BMTools/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246860095,"owners_count":20845598,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T12:00:18.304Z","updated_at":"2025-04-02T17:31:47.130Z","avatar_url":"https://github.com/OpenBMB.png","language":"Python","funding_links":[],"categories":["Frameworks \u0026 Libraries","Python","Related Projects","A01_文本生成_文本对话","Projects","Other","Evaluation"],"sub_categories":["Lightweight \u0026 Specialized Agents","🎨Application","大语言对话模型及数据","Developer tools","Other sdk/libraries","Industry Products"],"readme":"\r\n\u003cdiv align= \"center\"\u003e\r\n    \u003ch1\u003e\u003cimg src=\"assets/logo.png\" height=\"28px\" /\u003e BMTools\u003c/h1\u003e\r\n\u003c/div\u003e\r\n\r\n\r\n\r\n\u003cp align=\"center\"\u003e\r\n  \u003ca href=\"#whats-new\"\u003eNews\u003c/a\u003e •\r\n  \u003ca href=\"#1-setup\"\u003eSetup\u003c/a\u003e •\r\n  \u003ca href=\"#2-use-existing-tools\"\u003eHow To Use\u003c/a\u003e •\r\n  \u003ca href=\"https://arxiv.org/abs/2304.08354\"\u003ePaper\u003c/a\u003e •\r\n  \u003ca href=\"https://bmtools.readthedocs.io/en/main/\"\u003eDocs\u003c/a\u003e •\r\n  \u003ca href=\"https://github.com/thunlp/ToolLearningPapers\"\u003ePaper List\u003c/a\u003e •\r\n  \u003ca href=\"https://huggingface.co/spaces/congxin95/BMTools-demo\"\u003eDemo\u003c/a\u003e •\r\n  \u003ca href=\"#citation\"\u003eCitation\u003c/a\u003e •\r\n\u003c/p\u003e\r\n\r\n\r\n\r\n*Read this in [Chinese](README_zh.md).*\r\n\r\n\r\n\u003cbr\u003e\r\n\r\n\u003cdiv align=\"center\"\u003e\r\n\u003cimg src=\"assets/overview.png\" width=\"700px\"\u003e\r\n\u003c/div\u003e\r\n\u003cbr\u003e\r\n\r\nBMTools is an open-source repository that extends language models using tools and serves as a platform for the community to build and share tools. In this repository, you can (1) easily build a plugin by writing python functions (2) use external ChatGPT-Plugins. \r\n\r\n\r\nThis project is inspired by the open-source project [LangChain](https://github.com/hwchase17/langchain/) and optimized for the usage of open-sourced tools like [ChatGPT-Plugins](https://openai.com/blog/chatgpt-plugins), striving to achieve the open-source academic version of ChatGPT-Plugins.\r\n\r\n- **For new features and further developments, please go to [XAgent](https://github.com/OpenBMB/XAgent).**\r\n\r\n\r\n- **A demo of using BMTools to manipulate tools for meta analysis.**\r\n\r\n\r\n\u003cdiv align=\"center\"\u003e\r\n\r\n\u003cimg src=\"assets/meta0423.gif\" width=\"700px\"\u003e\r\n\r\n\u003c/div\u003e\r\n\r\n\r\n## What's New\r\n\r\n- **[2023/5/28]** We release [ToolBench](https://github.com/OpenBMB/ToolBench), a large-scale tool learning benchmark together with a capable model.\r\n\r\n- **[2023/5/25]** The evaluation data used in the paper is partially released at [data-test](https://cloud.tsinghua.edu.cn/d/2dab79f7b66841329f45/), we have also created large-scale SFT (100k+) high-quality tool-use training data at [data-sft](https://drive.google.com/drive/folders/1OaB-hM7eRiWi3TeqHij24VT9MAqgvC0H?usp=drive_link).\r\n\r\n- **[2023/5/19]** Three new Tools are supported: Baidu Map, Google Scholar Search, and Zillow\r\n\r\n- **[2023/5/18]** [WebCPM](https://github.com/thunlp/WebCPM) is accepted by ACL 2023, a Chinese version of WebGPT.\r\n\r\n- **[older]** [Auto-GPT](https://github.com/Significant-Gravitas/Auto-GPT) and [BabyAGI](https://github.com/yoheinakajima/babyagi) are supported in BMTools.\r\n\r\n\r\n## 1. Setup\r\n\r\n```bash\r\ngit clone git@github.com:OpenBMB/BMTools.git\r\ncd BMTools\r\npip install --upgrade pip\r\npip install -r requirements.txt\r\npython setup.py develop\r\n```\r\nTo support CPM-Bee:\r\n\r\n```bash\r\ngit clone -b main --single-branch https://github.com/OpenBMB/CPM-Bee.git\r\ncp -rf CPM-Bee/src/cpm_live bmtools/models/\r\n```\r\n\r\n\r\n## 2. Use existing tools\r\n\r\n### 2.1 Set up tools\r\n\r\n#### 2.1.1 Local tools\r\nAdd your api keys to secret_keys.sh, then start the local tools\r\n```bash\r\nsource secret_keys.sh\r\npython host_local_tools.py\r\n```\r\nThen set the url of the plugin to `http://127.0.0.1:8079/tools/{tool_name}/` (Remember the tailing `/`).\r\n\r\n#### 2.1.2 Use online ChatGPT-Plugins\r\n\r\nJust load it with the URL pointed to the `.well-known/ai-plugin.json`\r\nFor example, set the url to `https://www.klarna.com/`, where `https://www.klarna.com/.well-known/ai-plugin.json` is a valid configuration. \r\n\r\n### 2.2 Use a single tool \r\n\r\n```python\r\nfrom bmtools.agent.singletool import load_single_tools, STQuestionAnswerer\r\n\r\ntool_name, tool_url = 'klarna',  'https://www.klarna.com/'\r\ntool_name, tool_config = load_single_tools(tool_name, tool_url)\r\nprint(tool_name, tool_config)\r\nstqa =  STQuestionAnswerer()\r\n\r\nagent = stqa.load_tools(tool_name, tool_config)\r\nagent(\"{Your Question}\")\r\n```\r\n\r\n### 2.3 Use multiple tools\r\nWe can use multiple tools at the same time. Basically, the language model will do it recursively. It will treat the whole tool as an API, send questions to it, and the tool calls its sub-APIs to solve the question and send it back to parent tools.\r\n\r\nTry this functionality using scripts like:\r\n\r\n```python\r\nfrom bmtools.agent.tools_controller import load_valid_tools, MTQuestionAnswerer\r\ntools_mappings = {\r\n    \"klarna\": \"https://www.klarna.com/\",\r\n    \"chemical-prop\": \"http://127.0.0.1:8079/tools/chemical-prop/\",\r\n    \"wolframalpha\": \"http://127.0.0.1:8079/tools/wolframalpha/\",\r\n}\r\n\r\ntools = load_valid_tools(tools_mappings)\r\n\r\nqa =  MTQuestionAnswerer(openai_api_key='', all_tools=tools)\r\n\r\nagent = qa.build_runner()\r\n\r\nagent(\"How many benzene rings are there in 9H-Carbazole-3-carboxaldehyde? and what is sin(x)*exp(x)'s plot, what is it integrated from 0 to 1? \")\r\n```\r\n\r\n### 2.4 Use the web demo\r\n1. Add your plugin to the mappings at beginning of web_demo.py\r\n\r\n2. Start the webdemo\r\n```bash\r\npython web_demo.py\r\n```\r\n\r\n\r\n## 3. Use customized tools\r\n\r\n### 3.1 Develop a tool locally\r\n\r\nTo develop a tool locally, you need to write a python function to build the tool and register it to the registry.\r\n\r\nFor example, you can write a tool that can execute python code and return the result. The following is a sample code:\r\n\r\n```python\r\nfrom bmtools.tools import Tool\r\nfrom pydantic import BaseModel\r\n\r\nclass ExecutionQuery(BaseModel):\r\n    code: str\r\n\r\nclass ExecutionResult(BaseModel):\r\n    result: str\r\n\r\ndef build_python_tool(config) -\u003e Tool:\r\n    tool = Tool(\r\n        \"PythonTool\",\r\n        \"A plugin that can execute python code\",\r\n        name_for_model=\"python\", \r\n        description_for_model=\"A plugin that can execute python code\",\r\n        contact_email=\"your@email\",\r\n    )\r\n\r\n    @tool.post(\"/execute\")\r\n    def execute_python_code(query : ExecutionQuery) -\u003e ExecutionResult:\r\n        return ExecutionResult(\r\n            result=eval(query.code)\r\n        )\r\n    \r\n    return tool\r\n```\r\n\r\nThen you need to register the tool to the registry using the following code:\r\n\r\n```python\r\nfrom bmtools.tools import register\r\n\r\n@register(\"python\")\r\ndef register_python_tool():\r\n    return build_python_tool\r\n```\r\n\r\nHere we register the tool with the name `python`. \r\n\r\n\r\n### 3.2 Contributing to BMTools\r\n\r\nAfter you have developed a tool, you can contribute it to BMTools by following the steps below:\r\n1. Fork this repository\r\n2. Create a folder in `bmtools/tools/{tool_name}`\r\n3. Add an `api.py` to the folder: `bmtools/tools/{tool_name}/api.py` and a `__init__.py` to the folder: `bmtools/tools/{tool_name}/__init__.py`\r\n4. Register the tool in the `__init__.py` file you created in step 3 using the code in section 3.1\r\n5. Import your tool in the `__init__.py` file under bmtools/tools\r\n6. Add a `test.py` to test your tool automatically\r\n7. Add a `readme.md` in your folder containing a brief introduction, contributor information, or anything you want to let others know. \r\n\r\n## 4. Optimize your tool's prompt\r\nThe functions you wrote will be converted into an interface compatible with the OpenAI plugin. The AI models will read the name, description of the tools, as well as the name and descriptions of the tools' APIs. You can adjust the following aspect to make your API better understood by AI models.\r\n\r\n- (1) `name_for_model` (tell the model what the tool is) \r\n- (2) `description_for_model` (this will be displayed to the model before the tool is called, and you can include information on how to use the APIs) \r\n- (3) The function name for each API function, as well as the name in `@tool.get()`. It's best if these two names match, as the name plays an important role in the model's API selection. \r\n- (4) The function's doc string (can suggest to the model whether to use this API or not) \r\n- (5) The function's return value, which can provide the model with error messages to guide its next steps, such as retrying or indicating a preferred next step \r\n- (6) Reduce the errors in your API function.\r\n\r\nA simple example to refer to is the [Wolfram Alpha API](./bmtools/tools/wolframalpha/).\r\n\r\n## Citation\r\n\r\nIf you use BMTools in your research, please cite:\r\n\r\n```bibtex\r\n@misc{qin2023tool,\r\n      title={Tool Learning with Foundation Models}, \r\n      author={Yujia Qin and Shengding Hu and Yankai Lin and Weize Chen and Ning Ding and Ganqu Cui and Zheni Zeng and Yufei Huang and Chaojun Xiao and Chi Han and Yi Ren Fung and Yusheng Su and Huadong Wang and Cheng Qian and Runchu Tian and Kunlun Zhu and Shihao Liang and Xingyu Shen and Bokai Xu and Zhen Zhang and Yining Ye and Bowen Li and Ziwei Tang and Jing Yi and Yuzhang Zhu and Zhenning Dai and Lan Yan and Xin Cong and Yaxi Lu and Weilin Zhao and Yuxiang Huang and Junxi Yan and Xu Han and Xian Sun and Dahai Li and Jason Phang and Cheng Yang and Tongshuang Wu and Heng Ji and Zhiyuan Liu and Maosong Sun},\r\n      year={2023},\r\n      eprint={2304.08354},\r\n      archivePrefix={arXiv},\r\n      primaryClass={cs.CL}\r\n}\r\n```\r\n\r\n\r\n\r\n## Star History\r\n\r\n\u003cbr\u003e\r\n\u003cdiv align=\"center\"\u003e\r\n\r\n\u003cimg src=\"https://api.star-history.com/svg?repos=OpenBMB/BMTools\u0026type=Date\" width=\"600px\"\u003e\r\n\r\n\u003c/div\u003e\r\n\u003cbr\u003e\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOpenBMB%2FBMTools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FOpenBMB%2FBMTools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOpenBMB%2FBMTools/lists"}