├── API-README.md ├── EN-README.md ├── LICENSE ├── README.md ├── api ├── client.py └── requirements.txt ├── api_testpilot_generate_case.py ├── data ├── 20250404111524_01.png ├── 20250404122210.png ├── 7ceda900fedcc4a23952add92960958f_origin.png └── data_01.PNG ├── download_api_testpilot_model.py └── requirements.txt /API-README.md: -------------------------------------------------------------------------------- 1 | ### 📌 API-TestPilot 实操教程 2 | 3 | 1、项目下载:请git clone https://github.com/walker0012025/API-TestPilot.git 。 4 | 5 | 2、进入项目:cd API-TestPilot/api。 6 | 7 | 3、安装依赖:pip install -r requirements.txt。 8 | 9 | 4、生成用例:执行client.py。 10 | -------------------------------------------------------------------------------- /EN-README.md: -------------------------------------------------------------------------------- 1 | # API-TestPilot 2 | API-TestPilot: An AI model collaboratively trained by JunGe (Test Development Expert) and his students to generate API test cases. 3 | 4 | ### 🌟 Overview of API-TestPilot 5 | 6 | API-TestPilot is an AI-powered model designed to generate API test cases automatically. It aims to empower software testing engineers to enhance API testing efficiency and align with AI-driven technological advancements. 7 | 8 | ### 🎉 API-TestPilot Version News 9 | - 🎁 2025.04.05 API-TestPilot 1.0 is officially open-sourced and released. 10 | - 🎁 2025.04.06 API-TestPilot Version 1.1 (pending release) fixes long-text generation repetition issues. Scheduled for release on April 7 (currently in internal testing). 11 | - 🎁 2025.04.07 API-TestPilot 1.1, released on 2025.04.07, fixes duplication issues in long text generation and is now live. Your feedback is crucial as we prepare for the development of version 1.2. Please share your questions and issues with us. 12 | 13 | ### 🚀 API-TestPilot Core Features 14 | 15 | By providing API documentation to the model, API-TestPilot generates comprehensive test cases tailored to your API specifications. 16 | 17 | Deployment Simplicity & Hardware Requirements 18 | Cost-Efficient Training: Total distillation and hardware costs amount to 380 RMB,Hardware Compatibility:Smooth operation on Tesla V100 (32GB VRAM) && Theoretically compatible with 24GB VRAM GPUs (untested). 19 | 20 | API-TestPilot evaluates and generates test cases across the following dimensions: 21 | 22 | ![Image](https://github.com/walker0012025/API-TestPilot/blob/main/data/20250404111524_01.png) 23 | 24 | ### 💡 API-TestPilot Key Notes 25 | 26 | Comprehensive Coverage: The model generates test cases exceeding conventional requirements but may lack domain-specific business logic. Solutions: 27 | 28 | 1.Retraining is necessary and comes at a relatively low cost. For instance, the retraining expense for the API-TestPilot model amounts to 380 RMB, encompassing both hardware utilization and knowledge distillation expenses. 29 | 30 | 2.Through the framework, the specific effects can be viewed in the video at the back of this document. Both training and the framework require test development engineers to have certain technical capabilities. Of course, the use of AI technology to enhance the work efficiency of testing will also bring an exponential increase. 31 | 32 | 3.The demo code in this project is intended exclusively for evaluating its functionality. For other requirements, you will need to find solutions on your own. 33 | 34 | 4.There are 1,000 Hamlets among 1,000 software test engineers. Therefore, we look forward to your hands-on operation and experience in evaluating the API-TestPilot model, and there will be a detailed practical deployment tutorial. 35 | 36 | ### 👥 API-TestPilot Contributors 37 | 38 | 1.API-TestPilot was completed jointly by Brother Jun and his partners. The API-TestPilot model was named by **Fu Jiaxing**.The English content of readme was completed by **Zhou Song**.Other students **participated in the entire process of model evaluation and data sets** . The training and hardware preparation and deployment process are completed by the test and development brother. 39 | 40 | 2.These little friends have distilled from **. cleaning. Test model training. Test model evaluation. Full-process technologies such as test model deployment** , especially the application of Ai technology in the testing industry, are leading the industry. In order to avoid impersonation when selecting small partners, if there is a need for authenticity verification, companies can contact the test and development brother through these small partners. The test and development brother will provide a certificate, which will include the operation records of the corresponding small partners. The following is a list of contributions (in no particular order). 41 | 42 | ![Image](https://github.com/walker0012025/API-TestPilot/blob/main/data/20250404122210.png) 43 | 44 | ### 📌 API-TestPilot Deployment Guide 45 | 46 | Environment Setup 47 | 48 | 1.Hardware: Single GPU (32GB VRAM recommended; 24GB VRAM untested). 49 | 50 | 2.Dependencies:Python 3.12.4, pip 23.3.1 (use virtual environments). 51 | 52 | 3.Clone Repository: 53 | git clone https://github.com/walker0012025/API-TestPilot.git 54 | 55 | 4.cd API-TestPilot 56 | 57 | 5.Install Dependencies:pip install -r requirements.txt。 58 | 59 | 6.Download Model: Execute `python download_api_testpilot_model.py` (downloading may take time). 60 | 61 | 7.Modify the path: Open the api_testpilot_generate_case.py source code and replace the path of model_path with your actual path (generally, you don't need to change it. If you report an error, switch to the root directory find -name api-testpilot-model and find a path similar to that in the source code to replace it). 62 | 63 | 8.Generate Test Cases:python api_testpilot_generate_case.py ,start generating interface test cases (interface information has been prepared in the source code, you can view the source code and modify it yourself). 64 | 65 | ### ⚡ API-TestPilot combined with Ai execution interface testing framework enables automatic testing with interface test cases 66 | ### ⚡ Framework development and related technologies can be learned from test developer Jun Ge. The following is the platform automatically executes interface testing based on the generated test cases. 67 | 68 | ![Image](https://github.com/walker0012025/API-TestPilot/blob/main/data/1743762862000.gif) 69 | 70 | ### 🙏 Citation 71 | ```bibtex 72 | @misc{glm2024chatglm, 73 | title={ChatGLM: A Family of Large Language Models from GLM-130B to GLM-4 All Tools}, 74 | author={Team GLM and Aohan Zeng and Bin Xu and Bowen Wang and Chenhui Zhang and Da Yin and Diego Rojas and Guanyu Feng and Hanlin Zhao and Hanyu Lai and Hao Yu and Hongning Wang and Jiadai Sun and Jiajie Zhang and Jiale Cheng and Jiayi Gui and Jie Tang and Jing Zhang and Juanzi Li and Lei Zhao and Lindong Wu and Lucen Zhong and Mingdao Liu and Minlie Huang and Peng Zhang and Qinkai Zheng and Rui Lu and Shuaiqi Duan and Shudan Zhang and Shulin Cao and Shuxun Yang and Weng Lam Tam and Wenyi Zhao and Xiao Liu and Xiao Xia and Xiaohan Zhang and Xiaotao Gu and Xin Lv and Xinghan Liu and Xinyi Liu and Xinyue Yang and Xixuan Song and Xunkai Zhang and Yifan An and Yifan Xu and Yilin Niu and Yuantao Yang and Yueyan Li and Yushi Bai and Yuxiao Dong and Zehan Qi and Zhaoyu Wang and Zhen Yang and Zhengxiao Du and Zhenyu Hou and Zihan Wang}, 75 | year={2024}, 76 | eprint={2406.12793}, 77 | archivePrefix={arXiv}, 78 | primaryClass={cs.CL} 79 | } 80 | ``` 81 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # API-TestPilot 中文 | [English](https://github.com/walker0012025/API-TestPilot/blob/main/EN-README.md) 2 | 3 | ### 🌟 API-TestPilot 模型简介 4 | 5 | API-TestPilot,中文名**API 试飞员**,由测试开发俊哥及其学员共同训练的**AI生成接口测试用例**模型。旨在利用Ai技术提升软件测试工程师接口测试工作效率和帮助测试工程师跟上Ai时代技术发展要求。 6 | 7 | ### 🍓 API-TestPilot 使用必读 8 | - 🔥 使用本项目,请注明出处。 9 | - 🔥 严禁IT培训机构未经授权使用本项目内容,自2023年起,多家培训机构存在以下侵权行为: 10 | - 1、未授权转载我的外网内容,用于他自己的公众号、小红书推广 11 | - 2、盗用我的外网视频封面,原封不动用于他自己B站等推广视频 12 | - 3、其他未经授权转发我带有个人肖像视频用于宣传的等让人觉得可恶的行径 13 | - 本项目从开源之日起,本项目禁止IT培训机构未经授权以任何形式使用,违规者将保留追究法律责任的权利, 14 | - 🔥 我的愿景:提升整个测试行业的技术水平。倘若您喜欢本项目,欢迎给予star支持。 15 | - 🔥 作者、贡献者及关联方不承担任何因使用本开源项目导致的直接或间接责任。 16 | - 🔥 禁止将本开源项目用于:违反法律法规或公序良俗的行为;侵害他人隐私、知识产权或其他合法权益;可能对人身、财产或环境造成危害的场景。 17 | 18 | ### 🎉 API-TestPilot 版本新闻 19 | - 🎁 2025.04.05 API-TestPilot 1.0 版本正式开源,正式上线。 20 | - 🎁 2025.04.06 API-TestPilot 1.1 版本修复长文本生成重复问题,待上线(预计4月7日上线,在脚本跑内测中) 21 | - 🎁 2025.04.07 API-TestPilot 1.1 修复了长文本生成中的重复问题,现已上线。 22 | - 🎁 2025.04.10 API-TestPilot 1.2 预计4月11日上线。解决生成的接口用例,覆盖度可能会出现掉点的问题。 23 | - 🎁 2025.04.11 API-TestPilot 1.2 4月11日上线计划先搁置,因其他事情耽搁,预计一周内上线。 24 | - 🎁 2025.04.13 API-TestPilot 1.2 版本已上线,修复覆盖度可能掉点的问题。 25 | - 🎁 2025.04.18 API-TestPilot 1.2 有同学在CPU上成功跑起来,但不建议尝试,推理很慢、很慢、很慢 26 | - 🎁 2025.04.20 API-TestPilot 1.2 API Server 上线,仅用于学习交流,只会在闲时开启,使用教程在下方(从部署到服务代码编写、开放仅用3个小时,不保证服务稳定性)。 27 | 28 | ### 🚀 API-TestPilot 核心特征 29 | 30 | 在使用 API-TestPilot 模型时,只需要将接口文档信息给到模型,API-TestPilot 就可以帮您生成对应的接口测试用例。 31 | 32 | 部署模型简单及需要的硬件成本不大,API-TestPilot 模型**蒸馏和硬件消耗成本380RMB**,经测试推理过程实际**消耗显存20G**左右,可在**Tesla V100 单卡32G显存**的设备流畅运行,**单卡24G显存**的设备理论可行(已有测试同学在22G的2080TI上成功运行)。 33 | 34 | API-TestPilot 将从以下几个维度思考和生成对应的接口测试用例: 35 | 36 | ![Image](https://github.com/walker0012025/API-TestPilot/blob/main/data/20250404111524_01.png) 37 | 38 | ### 💡 API-TestPilot 要点提醒 39 | 40 | 首先 API-TestPilot 模型生成接口测试用例时考虑的场景已经很全了,甚至超过常规接口测试的要求。但是我没有办法获取公司数据,无法知道您具体的业务流,如果对业务流有严格要求,**解决办法**有: 41 | 42 | 1、再次训练,训练代价不大。比如 API-TestPilot 模型训练成本380RMB,此费用包含硬件和蒸馏成本。 43 | 44 | 2、框架+训练,训练和框架这两者都需要测试开发工程师具备一定的技术能力。当然,一个成熟的AI测试开发能够显著提升功能测试的效率和测试质量,使其呈指数级增长。 45 | 46 | 3、项目中的调用代码demo仅用于效果评测,如有其他需求,需自行解决。 47 | 48 | 4、一千个软件测试工程师就有一千个哈姆雷特,所以API-TestPilot 模型的评测及各项评估指标,**_我更期待您自己亲手实操和体验,后面有详细的实操部署教程。_** 49 | 50 | ### 👥 API-TestPilot 贡献同学 51 | 52 | 1、API-TestPilot 是测试开发俊哥和其学员共同完成。API-TestPilot 模型命名由**付佳星**完成,readme英文内容由**周松**完成,模型评测及数据集等工作其他同学**全程参与**、训练及硬件准备部署过程由测试开发俊哥完成。 53 | 54 | 2、这些同学具备**全栈AI测试开发技术**全过程技术,从**AI生成功能测试用例**、**AI一键执行接口测试**、**AI一键执行WEB测试**、**AI一键执行APP测试**、**AI CheckIn**、**AI模型测试**、**AI产品测试**,当然,也包括**测试模型的训练**,他们的**AI测试开发技术**处于行业领先。企业在选择小伙伴时为了避免冒充,如果有验真需求,可通过这些小伙伴联系到测试开发俊哥,测试开发俊哥将提供证明,证明将包含对应小伙伴的操作记录。以下为贡献名单(排名不分先后)。 55 | 56 | 3、其他未能参与本次开源项目的同学,无需担心,后续的版本迭代会让您参与。 57 | 58 | ![Image](https://github.com/walker0012025/API-TestPilot/blob/main/data/20250404122210.png) 59 | 60 | ### 📌 API-TestPilot 实操教程 61 | 62 | 备注:以下教程为单卡环境,单机单卡、多机多卡、CUDA、CUDNN等需自行解决(大多数情况无需解决)。 63 | 64 | 1、硬件设备:准备一张卡,建议32G显存,24G显存理论可以(已有测试同学在22G的2080TI上成功运行)。 65 | 66 | 2、项目下载:请git clone https://github.com/walker0012025/API-TestPilot.git 。 67 | 68 | 3、进入项目:cd API-TestPilot。 69 | 70 | 4、安装依赖:pip install -r requirements.txt。 71 | 72 | 5、下载模型:执行download_api_testpilot_model.py。 73 | 74 | 6、生成用例:执行api_testpilot_generate_case.py,开始生成接口测试用例。 75 | 76 | ### 📝 API-TestPilot开源模型非Ai测试技术核心,仅提供了Ai生成接口测试用例的能力 77 | ### 📝 API-TestPilot模型覆盖的接口测试场景可能会比常规测试设计的更全。 78 | ### 🎯 如您想进阶Ai测试开发,您将掌握以下内容 79 | - 🎁 Ai测试平台开发(独立开发,前后端分离架构) 80 | - 🎁 Ai生成测试用例(注入企业测试思维,两分钟完成3~5天工作量) 81 | - 🎁 Ai执行接口测试(实现一键化的Ai执行接口测试平台,从接口文档到报告一键化) 82 | - 🎁 Ai执行web/app测试(实现一键化的Ai执行web/app测试平台,全方位提升测试效率) 83 | - 🎁 Ai Checkin 技术 (从源头、代码、单元等维度对项目进行全流程管控) 84 | - 🎁 Ai 模型测试技术 (从模型评测、压测等各种维度实现对模型进行测试) 85 | - 🎁 其他Ai测试技术等 86 | 87 | ### ⚡ Ai测试开发处于红利期,可扫描下方二维码领取AI测试开发教程资料 88 | ![Image](https://github.com/walker0012025/API-TestPilot/blob/main/data/7ceda900fedcc4a23952add92960958f_origin.png) 89 | 90 | ### ⚡ 当您看到类似下图的信息出现时,恭喜您成功了。 91 | 92 | ![Image](https://github.com/walker0012025/API-TestPilot/blob/main/data/data_01.PNG) 93 | 94 | ### 📌 API-TestPilot API 调用实操教程 95 | 96 | 1、项目下载:请git clone https://github.com/walker0012025/API-TestPilot.git 。 97 | 98 | 2、进入项目:cd API-TestPilot/api。 99 | 100 | 3、安装依赖:pip install -r requirements.txt。 101 | 102 | 4、生成用例:执行client.py。 103 | 104 | ### 🙏 引用 105 | ```bibtex 106 | @misc{glm2024chatglm, 107 | title={ChatGLM: A Family of Large Language Models from GLM-130B to GLM-4 All Tools}, 108 | author={Team GLM and Aohan Zeng and Bin Xu and Bowen Wang and Chenhui Zhang and Da Yin and Diego Rojas and Guanyu Feng and Hanlin Zhao and Hanyu Lai and Hao Yu and Hongning Wang and Jiadai Sun and Jiajie Zhang and Jiale Cheng and Jiayi Gui and Jie Tang and Jing Zhang and Juanzi Li and Lei Zhao and Lindong Wu and Lucen Zhong and Mingdao Liu and Minlie Huang and Peng Zhang and Qinkai Zheng and Rui Lu and Shuaiqi Duan and Shudan Zhang and Shulin Cao and Shuxun Yang and Weng Lam Tam and Wenyi Zhao and Xiao Liu and Xiao Xia and Xiaohan Zhang and Xiaotao Gu and Xin Lv and Xinghan Liu and Xinyi Liu and Xinyue Yang and Xixuan Song and Xunkai Zhang and Yifan An and Yifan Xu and Yilin Niu and Yuantao Yang and Yueyan Li and Yushi Bai and Yuxiao Dong and Zehan Qi and Zhaoyu Wang and Zhen Yang and Zhengxiao Du and Zhenyu Hou and Zihan Wang}, 109 | year={2024}, 110 | eprint={2406.12793}, 111 | archivePrefix={arXiv}, 112 | primaryClass={cs.CL} 113 | } 114 | ``` 115 | -------------------------------------------------------------------------------- /api/client.py: -------------------------------------------------------------------------------- 1 | # 此API服务只会利用闲置时间开放,俊哥炼丹过程中不开放API服务 2 | # 本服务为测试API,只为降低部分同学的使用门槛。 3 | # 本服务为临时开放,从部署到服务代码编写、开放仅用3个小时,未测试服务稳定性。 4 | 5 | import requests 6 | import json 7 | 8 | def call_api_stream(url, data=None, headers=None): 9 | 10 | try: 11 | response = requests.post( 12 | url, 13 | json=data, 14 | headers=headers, 15 | stream=True 16 | ) 17 | 18 | ad_shown = False 19 | 20 | for raw_line in response.iter_lines(): 21 | 22 | if not raw_line: 23 | continue 24 | line = raw_line.decode('utf-8').strip() 25 | 26 | try: 27 | chunk = json.loads(line) 28 | 29 | if 'advertisement' in chunk and not ad_shown: 30 | print(f"\n{chunk['advertisement']}\n") 31 | ad_shown = True 32 | 33 | if 'error' in chunk: 34 | print(f"[错误] {chunk['error']}") 35 | if 'detail' in chunk: 36 | print(f"详情: {chunk['detail']}") 37 | elif 'content' in chunk: 38 | print(chunk['content'], end='', flush=True) 39 | 40 | except json.JSONDecodeError: 41 | print(f"无效JSON数据: {line}") 42 | 43 | print("\n\n响应结束") 44 | 45 | except requests.exceptions.RequestException as e: 46 | print(f"请求异常: {str(e)}") 47 | except Exception as e: 48 | print(f"未处理错误: {str(e)}") 49 | 50 | if __name__ == "__main__": 51 | # 调用示例 52 | api_desc = """商品搜索 53 | 54 | 简要描述: 55 | 搜索建议查询 56 | 请求URL: 57 | https://api-hmugo-web.itheima.net/api/public/v1/goods/qsearch 58 | 请求方式: 59 | GET 60 | 参数: 61 | 返回示例 62 | { 63 | "message": [ 64 | { 65 | "goods_id": 57444, 66 | "goods_name": "创维(Skyworth)42X6 42英寸10核智能酷开网络平板液晶电视(黑色)" 67 | } 68 | ], 69 | "meta": { 70 | "msg": "获取成功", 71 | "status": 200 72 | } 73 | } 74 | 返回参数说明 75 | 备注 76 | 更多返回错误代码请看首页的错误代码描述 77 | 78 | 参数名 必选 类型 说明 79 | query 是 string 关键字 80 | 参数名 类型 说明 81 | goods_id number 商品id 82 | goods_name string 商品名称 83 | """ 84 | 85 | # 配置请求参数 86 | base_url = "http://36.213.71.118:32625/v1/apicase" 87 | payload = { 88 | "model_name": "api-testpilot-model-v1.2", 89 | "api_desc": api_desc 90 | } 91 | 92 | call_api_stream(base_url, data=payload) 93 | -------------------------------------------------------------------------------- /api/requirements.txt: -------------------------------------------------------------------------------- 1 | import requests 2 | -------------------------------------------------------------------------------- /api_testpilot_generate_case.py: -------------------------------------------------------------------------------- 1 | import os 2 | from typing import Generator 3 | from modelscope import AutoModelForCausalLM, AutoTokenizer 4 | import torch 5 | from transformers import TextIteratorStreamer 6 | from threading import Thread 7 | 8 | class ChatBotEngine: 9 | def __init__( 10 | self, 11 | model_path: str, 12 | max_tokens: int = 5120, 13 | temperature: float = 0.1, 14 | device: str = "cuda:0" 15 | ): 16 | os.environ["CUDA_VISIBLE_DEVICES"] = device.split(":")[-1] 17 | 18 | self.tokenizer = AutoTokenizer.from_pretrained( 19 | model_path, 20 | trust_remote_code=True 21 | ) 22 | self.model = AutoModelForCausalLM.from_pretrained( 23 | model_path, 24 | device_map="auto", 25 | torch_dtype=torch.float16, 26 | trust_remote_code=True 27 | ).eval() 28 | 29 | self.generation_config = { 30 | "max_new_tokens": max_tokens, 31 | "temperature": temperature, 32 | "pad_token_id": self.tokenizer.eos_token_id, 33 | "eos_token_id": [151329, 151336, 151338], 34 | } 35 | 36 | if temperature == 0: 37 | self.generation_config.update({ 38 | "num_beams": 5, 39 | "early_stopping": True, 40 | "no_repeat_ngram_size": 3 41 | }) 42 | else: 43 | self.generation_config.update({ 44 | "do_sample": True, 45 | "top_p": 0.9, 46 | "early_stopping": False 47 | }) 48 | 49 | def _build_prompt(self, messages: list) -> str: 50 | prompt = "" 51 | role_tags = { 52 | "system": "<|system|>", 53 | "user": "<|user|>", 54 | "assistant": "<|assistant|>" 55 | } 56 | for msg in messages: 57 | prompt += f"{role_tags[msg['role']]}\n{msg['content']}\n" 58 | return prompt + "<|assistant|>\n" 59 | 60 | def _identity_check(self) -> str: 61 | messages = [{"role": "user", "content": "你是谁?"}] 62 | return self._generate(messages) 63 | 64 | def _generate(self, messages: list) -> str: 65 | prompt = self._build_prompt(messages) 66 | inputs = self.tokenizer(prompt, return_tensors="pt").to(self.model.device) 67 | 68 | with torch.no_grad(): 69 | outputs = self.model.generate( 70 | **inputs, 71 | **self.generation_config 72 | ) 73 | return self.tokenizer.decode(outputs[0][len(inputs.input_ids[0]):], 74 | skip_special_tokens=True).strip() 75 | 76 | def stream_chat(self, messages: list) -> Generator[str, None, None]: 77 | identity_response = self._identity_check() 78 | yield f"\n{identity_response}\n\n" + "=" * 40 + "\n\n" 79 | 80 | prompt = self._build_prompt(messages) 81 | inputs = self.tokenizer(prompt, return_tensors="pt").to(self.model.device) 82 | 83 | streamer = TextIteratorStreamer( 84 | self.tokenizer, 85 | skip_prompt=True, 86 | skip_special_tokens=True 87 | ) 88 | 89 | thread = Thread(target=self.model.generate, kwargs={ 90 | **inputs, 91 | **self.generation_config, 92 | "streamer": streamer 93 | }) 94 | thread.start() 95 | 96 | yield from streamer 97 | 98 | class ChatClient: 99 | @staticmethod 100 | def run(engine: ChatBotEngine, api_desc: str): 101 | messages = [ 102 | {"role": "system", "content": "你是一名软件测试工程师。你的任务是根据接口文档内容生成接口测试用例。"}, 103 | {"role": "user", "content": api_desc} 104 | ] 105 | 106 | for chunk in engine.stream_chat(messages): 107 | print(chunk, end="", flush=True) 108 | print('\n') 109 | 110 | if __name__ == "__main__": 111 | bot_engine = ChatBotEngine( 112 | model_path="/root/.cache/modelscope/hub/models/walker001/api-testpilot-model-v1.2", 113 | max_tokens=5120, 114 | temperature=0.4 115 | ) 116 | 117 | api_desc = """ 118 | 商品搜索 119 | 120 | 简要描述: 121 | 搜索建议查询 122 | 请求URL: 123 | https://api-hmugo-web.itheima.net/api/public/v1/goods/qsearch 124 | 请求方式: 125 | GET 126 | 参数: 127 | 返回示例 128 | { 129 | "message": [ 130 | { 131 | "goods_id": 57444, 132 | "goods_name": "创维(Skyworth)42X6 42英寸10核智能酷开网络平板液晶电视(黑色)" 133 | } 134 | ], 135 | "meta": { 136 | "msg": "获取成功", 137 | "status": 200 138 | } 139 | } 140 | 返回参数说明 141 | 备注 142 | 更多返回错误代码请看首页的错误代码描述 143 | 144 | 参数名 必选 类型 说明 145 | query 是 string 关键字 146 | 参数名 类型 说明 147 | goods_id number 商品id 148 | goods_name string 商品名称 149 | """ 150 | 151 | ChatClient.run(bot_engine, api_desc) 152 | -------------------------------------------------------------------------------- /data/20250404111524_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/walker0012025/API-TestPilot/dc8142efe24cc711a3ec2b1b031990da18383103/data/20250404111524_01.png -------------------------------------------------------------------------------- /data/20250404122210.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/walker0012025/API-TestPilot/dc8142efe24cc711a3ec2b1b031990da18383103/data/20250404122210.png -------------------------------------------------------------------------------- /data/7ceda900fedcc4a23952add92960958f_origin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/walker0012025/API-TestPilot/dc8142efe24cc711a3ec2b1b031990da18383103/data/7ceda900fedcc4a23952add92960958f_origin.png -------------------------------------------------------------------------------- /data/data_01.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/walker0012025/API-TestPilot/dc8142efe24cc711a3ec2b1b031990da18383103/data/data_01.PNG -------------------------------------------------------------------------------- /download_api_testpilot_model.py: -------------------------------------------------------------------------------- 1 | from modelscope import snapshot_download 2 | 3 | # 请一定先按照操作步骤安装依赖之后再执行此脚本 4 | model_dir = snapshot_download('walker001/api-testpilot-model-v1.2') 5 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | absl-py==2.2.1 2 | accelerate==1.6.0 3 | addict==2.4.0 4 | aiofiles==23.2.1 5 | aiohappyeyeballs==2.6.1 6 | aiohttp==3.11.16 7 | aiosignal==1.3.2 8 | aliyun-python-sdk-core==2.16.0 9 | aliyun-python-sdk-kms==2.16.5 10 | altair==5.5.0 11 | annotated-types==0.7.0 12 | antlr4-python3-runtime==4.7.2 13 | anyio==4.9.0 14 | appdirs==1.4.4 15 | argon2-cffi==23.1.0 16 | argon2-cffi-bindings==21.2.0 17 | arrow==1.3.0 18 | arxiv==2.1.3 19 | asttokens==3.0.0 20 | async-lru==2.0.5 21 | attrdict==2.0.1 22 | attrs==25.3.0 23 | babel==2.17.0 24 | beautifulsoup4==4.13.3 25 | binpacking==1.5.2 26 | bitsandbytes==0.45.4 27 | bleach==6.2.0 28 | blinker==1.9.0 29 | boto3==1.37.25 30 | botocore==1.37.25 31 | braceexpand==0.1.7 32 | Brotli==1.1.0 33 | cachetools==5.5.2 34 | certifi==2025.1.31 35 | cffi==1.17.1 36 | charset-normalizer==3.4.1 37 | click==8.1.8 38 | colorama==0.4.6 39 | comm==0.2.2 40 | contourpy==1.3.1 41 | cpm-kernels==1.0.11 42 | crcmod==1.7 43 | cryptography==44.0.2 44 | cycler==0.12.1 45 | dacite==1.9.2 46 | dataclasses-json==0.6.7 47 | datasets==3.2.0 48 | debugpy==1.8.13 49 | decorator==5.2.1 50 | decord==0.6.0 51 | deepspeed==0.16.5 52 | defusedxml==0.7.1 53 | dill==0.3.8 54 | diskcache==5.6.3 55 | distro==1.9.0 56 | docstring_parser==0.16 57 | duckduckgo_search==5.3.1b1 58 | einops==0.8.1 59 | et_xmlfile==2.0.0 60 | eval_type_backport==0.2.2 61 | evalscope==0.13.2 62 | evaluate==0.4.3 63 | executing==2.2.0 64 | fastapi==0.115.12 65 | fastjsonschema==2.21.1 66 | feedparser==6.0.11 67 | ffmpy==0.5.0 68 | filelock==3.18.0 69 | fire==0.7.0 70 | fonttools==4.56.0 71 | fqdn==1.5.1 72 | frozenlist==1.5.0 73 | fsspec==2024.9.0 74 | func_timeout==4.3.5 75 | future==1.0.0 76 | fuzzywuzzy==0.18.0 77 | gitdb==4.0.12 78 | GitPython==3.1.44 79 | gradio==5.4.0 80 | gradio_client==1.4.2 81 | greenlet==3.1.1 82 | griffe==0.49.0 83 | grpcio==1.71.0 84 | h11==0.14.0 85 | h2==4.2.0 86 | h5py==3.13.0 87 | hjson==3.1.0 88 | hpack==4.1.0 89 | httpcore==1.0.7 90 | httpx==0.28.1 91 | huggingface-hub==0.30.1 92 | human-eval==1.0.3 93 | hyperframe==6.1.0 94 | idna==3.10 95 | imageio==2.37.0 96 | immutabledict==4.2.1 97 | importlib_metadata==8.6.1 98 | ipykernel==6.29.5 99 | ipython==9.0.2 100 | ipython_pygments_lexers==1.1.1 101 | ipywidgets==8.1.5 102 | isoduration==20.11.0 103 | jedi==0.19.2 104 | jieba==0.42.1 105 | Jinja2==3.1.6 106 | jiter==0.9.0 107 | jmespath==0.10.0 108 | joblib==1.4.2 109 | json5==0.11.0 110 | jsonlines==4.0.0 111 | jsonpatch==1.33 112 | jsonpointer==3.0.0 113 | jsonschema==4.23.0 114 | jsonschema-specifications==2024.10.1 115 | jupyter==1.1.1 116 | jupyter-console==6.6.3 117 | jupyter-events==0.12.0 118 | jupyter-lsp==2.2.5 119 | jupyter_client==8.6.3 120 | jupyter_core==5.7.2 121 | jupyter_server==2.15.0 122 | jupyter_server_terminals==0.5.3 123 | jupyterlab==4.3.6 124 | jupyterlab_pygments==0.3.0 125 | jupyterlab_server==2.27.3 126 | jupyterlab_widgets==3.0.13 127 | kiwisolver==1.4.8 128 | lagent==0.2.4 129 | langchain==0.2.17 130 | langchain-community==0.2.19 131 | langchain-core==0.2.43 132 | langchain-openai==0.1.25 133 | langchain-text-splitters==0.2.4 134 | langdetect==1.0.9 135 | langsmith==0.1.147 136 | latex2sympy2==1.9.1 137 | Levenshtein==0.27.1 138 | lxml==5.3.1 139 | Markdown==3.7 140 | markdown-it-py==3.0.0 141 | MarkupSafe==2.1.5 142 | marshmallow==3.26.1 143 | matplotlib==3.10.1 144 | matplotlib-inline==0.1.7 145 | mdurl==0.1.2 146 | mistune==3.1.3 147 | mmengine==0.10.7 148 | mmengine-lite==0.10.7 149 | modelscope==1.24.1 150 | mpmath==1.3.0 151 | ms-opencompass==0.1.6 152 | ms-vlmeval==0.0.16 153 | ms_swift==3.2.2 154 | msgpack==1.1.0 155 | mteb==1.19.4 156 | multidict==6.3.1 157 | multiprocess==0.70.16 158 | mypy-extensions==1.0.0 159 | narwhals==1.33.0 160 | nbclient==0.10.2 161 | nbconvert==7.16.6 162 | nbformat==5.10.4 163 | nest-asyncio==1.6.0 164 | networkx==3.4.2 165 | ninja==1.11.1.4 166 | nltk==3.9.1 167 | notebook==7.3.3 168 | notebook_shim==0.2.4 169 | numpy==1.26.4 170 | #nvidia-cublas-cu12==12.4.5.8 171 | #nvidia-cuda-cupti-cu12==12.4.127 172 | #nvidia-cuda-nvrtc-cu12==12.4.127 173 | #nvidia-cuda-runtime-cu12==12.4.127 174 | #nvidia-cudnn-cu12==9.1.0.70 175 | #nvidia-cufft-cu12==11.2.1.3 176 | #nvidia-curand-cu12==10.3.5.147 177 | #nvidia-cusolver-cu12==11.6.1.9 178 | #nvidia-cusparse-cu12==12.3.1.170 179 | #nvidia-cusparselt-cu12==0.6.2 180 | #nvidia-ml-py==12.570.86 181 | #nvidia-nccl-cu12==2.21.5 182 | #nvidia-nvjitlink-cu12==12.4.127 183 | #nvidia-nvtx-cu12==12.4.127 184 | omegaconf==2.0.6 185 | openai==1.70.0 186 | OpenCC==1.1.9 187 | opencv-python==4.11.0.86 188 | openpyxl==3.1.5 189 | orjson==3.10.16 190 | oss2==2.19.1 191 | overrides==7.7.0 192 | packaging==24.2 193 | pandas==2.2.3 194 | pandocfilters==1.5.1 195 | parso==0.8.4 196 | peft==0.14.0 197 | pexpect==4.9.0 198 | phx-class-registry==4.1.0 199 | pillow==11.1.0 200 | platformdirs==4.3.7 201 | plotly==5.24.1 202 | polars==1.26.0 203 | portalocker==3.1.1 204 | prettytable==3.16.0 205 | prometheus_client==0.21.1 206 | prompt_toolkit==3.0.50 207 | propcache==0.3.1 208 | protobuf==5.29.4 209 | psutil==7.0.0 210 | ptyprocess==0.7.0 211 | pure_eval==0.2.3 212 | py-cpuinfo==9.0.0 213 | pyarrow==19.0.1 214 | pycparser==2.22 215 | pycryptodome==3.22.0 216 | pydantic==2.11.1 217 | pydantic_core==2.33.0 218 | pydeck==0.9.1 219 | pydub==0.25.1 220 | Pygments==2.19.1 221 | pynvml==12.0.0 222 | pyparsing==3.2.3 223 | pypinyin==0.54.0 224 | pysbd==0.3.4 225 | python-dateutil==2.9.0.post0 226 | python-dotenv==1.1.0 227 | python-json-logger==3.3.0 228 | python-Levenshtein==0.27.1 229 | python-multipart==0.0.12 230 | pytrec-eval-terrier==0.5.6 231 | pytz==2025.2 232 | PyYAML==6.0.2 233 | pyzmq==26.3.0 234 | ragas==0.2.9 235 | rank-bm25==0.2.2 236 | RapidFuzz==3.12.2 237 | referencing==0.36.2 238 | regex==2024.11.6 239 | requests==2.32.3 240 | requests-toolbelt==1.0.0 241 | rfc3339-validator==0.1.4 242 | rfc3986-validator==0.1.1 243 | rich==14.0.0 244 | rouge==1.0.1 245 | rouge-chinese==1.0.3 246 | rouge_score==0.1.2 247 | rpds-py==0.24.0 248 | ruff==0.11.2 249 | s3transfer==0.11.4 250 | sacrebleu==2.5.1 251 | safehttpx==0.1.6 252 | safetensors==0.5.3 253 | scikit-learn==1.6.1 254 | scipy==1.15.2 255 | seaborn==0.13.2 256 | semantic-version==2.10.0 257 | Send2Trash==1.8.3 258 | sentence-transformers==4.0.1 259 | sentencepiece==0.2.0 260 | setuptools==69.5.1 261 | sgmllib3k==1.0.0 262 | shellingham==1.5.4 263 | shtab==1.7.1 264 | simplejson==3.20.1 265 | six==1.17.0 266 | smmap==5.0.2 267 | sniffio==1.3.1 268 | socksio==1.0.0 269 | sortedcontainers==2.4.0 270 | soupsieve==2.6 271 | SQLAlchemy==2.0.40 272 | sse-starlette==2.2.1 273 | stack-data==0.6.3 274 | starlette==0.46.1 275 | streamlit==1.44.1 276 | sty==1.0.6 277 | swankit==0.1.6 278 | swanlab==0.5.4 279 | sympy==1.13.1 280 | tabulate==0.9.0 281 | tenacity==8.5.0 282 | tensorboard==2.19.0 283 | tensorboard-data-server==0.7.2 284 | termcolor==3.0.1 285 | terminado==0.18.1 286 | threadpoolctl==3.6.0 287 | tiktoken==0.9.0 288 | timeout-decorator==0.5.0 289 | tinycss2==1.4.0 290 | tokenizers==0.21.1 291 | toml==0.10.2 292 | tomlkit==0.12.0 293 | torch==2.6.0 294 | torchvision==0.21.0 295 | tornado==6.4.2 296 | tqdm==4.67.1 297 | traitlets==5.14.3 298 | transformers==4.47.1 299 | transformers-stream-generator==0.0.5 300 | triton==3.2.0 301 | trl==0.16.0 302 | typeguard==4.4.2 303 | typer==0.15.2 304 | types-python-dateutil==2.9.0.20241206 305 | typing-inspect==0.9.0 306 | typing-inspection==0.4.0 307 | typing_extensions==4.13.0 308 | tyro==0.9.18 309 | tzdata==2025.2 310 | unicorn==2.1.3 311 | uri-template==1.3.0 312 | urllib3==2.3.0 313 | uvicorn==0.34.0 314 | validators==0.34.0 315 | watchdog==6.0.0 316 | wcwidth==0.2.13 317 | webcolors==24.11.1 318 | webdataset==0.2.111 319 | webencodings==0.5.1 320 | websocket-client==1.8.0 321 | websockets==12.0 322 | Werkzeug==3.1.3 323 | widgetsnbextension==4.0.13 324 | word2number==1.1 325 | XlsxWriter==3.2.2 326 | xtuner==0.1.11 327 | xxhash==3.5.0 328 | yapf==0.43.0 329 | yarl==1.18.3 330 | zipp==3.21.0 331 | zstandard==0.23.0 332 | --------------------------------------------------------------------------------