You need to enable JavaScript to run this app.
导航
PHP 使用示例
最近更新时间:2025.04.23 16:51:49首次发布时间:2025.04.09 15:17:28
我的收藏
有用
有用
无用
无用

本文为您提供调用CheckLLMPrompt判别大模型提示词是否合规的示例代码。实际使用时,您可以替换成 SDK 中已经支持的任意接口。

前提条件

调用前,请确保已经完成PHP 安装和初始化

调用接口

CheckLLMPrompt相关参数的详细说明,可参考CheckLLMPrompt - 判别大模型提示词是否合规

<?php
// Example Code generated by Beijing Volcanoengine Technology.
error_reporting(E_ALL & ~E_DEPRECATED);
require_once(__DIR__ . '/vendor/autoload.php');

$config = \Volcengine\Common\Configuration::getDefaultConfiguration()
        // 注意示例代码安全,代码泄漏会导致AK/SK泄漏,有极大的安全风险。
    ->setAk("Your AK")   // Access Key,用于身份验证
    ->setSk("Your SK")  // Secret Key,用于签名
    ->setRegion("cn-beijing");  // 大模型应用防火墙所属地域对应的 ID

$apiInstance = new \Volcengine\Waf\API\WAFApi(
// If you want use custom http client, pass your client which implements GuzzleHttp\ClientInterface.
// This is optional, GuzzleHttp\Client will be used as default.
    new GuzzleHttp\Client(),
    $config
);

$checkLLMPromptRequest = new \Volcengine\Waf\Model\CheckLLMPromptRequest();
$checkLLMPromptRequest->setContent("请输入您想要校验的内容,文本内容或资源URL");  // 需要检测的内容
$checkLLMPromptRequest->setContentType(1); // 内容类型: 1-文本, 2-音频, 3-图片
$checkLLMPromptRequest->setHost("fd****.access.omni-shield.volces.com"); // 大模型应用防火墙生成的接入点域名
$checkLLMPromptRequest->setMsgClass(0); // 场景类型,当前默认为标准类型,填入 0 即可
$checkLLMPromptRequest->setRegion("cn-beijing"); // 大模型应用防火墙所属地域对应的 ID

try {
    // 复制代码运行示例,请自行打印API返回值。
    $checkLLMPromptResponse = $apiInstance->checkLLMPrompt($checkLLMPromptRequest);
    var_dump($checkLLMPromptResponse);
} catch (Exception $e) {
    // 复制代码运行示例,请自行打印API错误信息。
    // echo 'Exception when calling Api: ', $e->getMessage(), PHP_EOL;
    var_dump($e->getResponseBody());
}