/ AIG-PromptSecurity / deepteam / plugin_system / tool_decorators.py
tool_decorators.py
 1  # Copyright (c) 2024-2026 Tencent Zhuque Lab. All rights reserved.
 2  #
 3  # Licensed under the Apache License, Version 2.0 (the "License");
 4  # you may not use this file except in compliance with the License.
 5  # You may obtain a copy of the License at
 6  #
 7  #     http://www.apache.org/licenses/LICENSE-2.0
 8  #
 9  # Unless required by applicable law or agreed to in writing, software
10  # distributed under the License is distributed on an "AS IS" BASIS,
11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  # See the License for the specific language governing permissions and
13  # limitations under the License.
14  #
15  # Requirement: Any integration or derivative work must explicitly attribute
16  # Tencent Zhuque Lab (https://github.com/Tencent/AI-Infra-Guard) in its
17  # documentation or user interface, as detailed in the NOTICE file.
18  
19  """
20  工具参数装饰器模块
21  用于为工具类添加参数说明,支持扫描器自动提取参数信息
22  """
23  
24  def tool_parameters(**param_descriptions):
25      """
26      装饰器:为工具类添加参数说明
27      
28      Args:
29          **param_descriptions: 参数名 -> 参数描述的映射
30          
31      Example:
32          @tool_parameters(
33              role="要扮演的角色名称,如:doctor, teacher, hacker",
34              context="角色背景上下文,可选,默认为空",
35              temperature="生成文本的随机性,0-1之间,默认0.7"
36          )
37          class RoleplayAttack(BaseAttack):
38              def __init__(self, role: str, context: str = "", temperature: float = 0.7):
39                  pass
40      """
41      def decorator(cls):
42          cls._parameter_descriptions = param_descriptions
43          return cls
44      return decorator