本文为您介绍大模型应用防火墙 Python SDK 的下载地址、安装方式以及代码示例,帮助您快速了解如何使用 SDK 调用 OpenAPI。
python --version
可以检查当前 Python 的版本信息。Win+R
,输入regedit
打开注册表编辑器。\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
路径下的变量LongPathsEnabled
为1
即可。前往volcengine-python-sdk下载大模型应用防火墙 Python SDK 安装包。
您可以使用以下任意一种方式安装 SDK。
使用 pip 命令安装 SDK。
pip install volcengine-python-sdk
python setup.py install --user
命令,为指定 user 安装 SDK。sudo python setup.py install
命令,为全部 user 安装 SDK。配置全局默认参数:
configuration = volcenginesdkcore.Configuration() configuration.client_side_validation = True # 客户端是否进行参数校验 configuration.schema = "http" # https or http configuration.debug = False # 是否开启调试 configuration.logger_file = "sdk.log" volcenginesdkcore.Configuration.set_default(configuration)
以下提供调用CheckLLMPrompt
判别大模型提示词是否合规的示例代码,实际使用时,您可以替换成 SDK 中已经支持的任意接口。CheckLLMPrompt
相关参数的详细说明,可参考CheckLLMPrompt - 判别大模型提示词是否合规。
from __future__ import print_function import volcenginesdkcore import volcenginesdkwaf from volcenginesdkcore.rest import ApiException if __name__ == '__main__': configuration = volcenginesdkcore.Configuration() configuration.ak = "YOUR AK" configuration.sk = "YOUR SK" configuration.region = "cn-beijing" # set default configuration volcenginesdkcore.Configuration.set_default(configuration) # use global default configuration api_instance = volcenginesdkwaf.WAFApi() check_llm_prompt_request = volcenginesdkwaf.CheckLLMPromptRequest( content="需要判别的提示词", content_type=1, host="example.com", msg_class=0, region="cn-beijing", ) try: # 复制代码运行示例,请自行打印API返回值。 data = api_instance.check_llm_prompt(check_llm_prompt_request) print("response:" , data ) except ApiException as e: # 复制代码运行示例,请自行打印API错误信息。 print("Exception when calling api: %s\n" % e) pass