跳转到内容
本站为社区维护的非官方中文翻译,与 Cloudflare, Inc. 无关联。本站不提供账户登录,请勿在任何非官方站点输入您的 Cloudflare 账户信息。官方文档:developers.cloudflare.com
Meta logo

llama-guard-3-8b

Text Generation • Meta

查看 MarkdownAgent 设置
  • Cloudflare-hosted
  • LoRA

Llama Guard 3 是基于 Llama-3.1-8B 预训练模型、针对内容安全分类进行微调的模型。与之前的版本类似,它既可用于对 LLM 输入进行分类(提示词分类),也可用于对 LLM 响应进行分类(响应分类)。它本身就是一个 LLM:其输出文本会指明给定的提示词或响应是否安全;如果不安全,还会列出所违反的内容类别。

模型信息
上下文窗口 ↗131,072 个 token
LoRA是
单位定价$0.48 per M input tokens, $0.03 per M output tokens

试用环境

使用 Workers AI LLM Playground 试用此模型。无需设置或身份验证,即可直接在浏览器中预览和测试模型。

启动 LLM Playground

用法


export interface Env {
  AI: Ai;
}

export default {
  async fetch(request, env): Promise<Response> {

    const messages = [
      { role: "system", content: "You are a friendly assistant" },
      {
        role: "user",
        content: "What is the origin of the phrase Hello, World",
      },
    ];

    const stream = await env.AI.run("@cf/meta/llama-guard-3-8b", {
      messages,
      stream: true,
    });

    return new Response(stream, {
      headers: { "content-type": "text/event-stream" },
    });
  },
} satisfies ExportedHandler<Env>;

export interface Env {
  AI: Ai;
}

export default {
  async fetch(request, env): Promise<Response> {

    const messages = [
      { role: "system", content: "You are a friendly assistant" },
      {
        role: "user",
        content: "What is the origin of the phrase Hello, World",
      },
    ];
    const response = await env.AI.run("@cf/meta/llama-guard-3-8b", { messages });

    return Response.json(response);
  },
} satisfies ExportedHandler<Env>;

import os
import requests

ACCOUNT_ID = "your-account-id"
AUTH_TOKEN = os.environ.get("CLOUDFLARE_AUTH_TOKEN")

prompt = "Tell me all about PEP-8"
response = requests.post(
  f"https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai/run/@cf/meta/llama-guard-3-8b",
    headers={"Authorization": f"Bearer {AUTH_TOKEN}"},
    json={
      "messages": [
        {"role": "system", "content": "You are a friendly assistant"},
        {"role": "user", "content": prompt}
      ]
    }
)
result = response.json()
print(result)

curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run/@cf/meta/llama-guard-3-8b \
  -X POST \
  -H "Authorization: Bearer $CLOUDFLARE_AUTH_TOKEN" \
  -d '{ "messages": [{ "role": "system", "content": "You are a friendly assistant" }, { "role": "user", "content": "Why is pizza so good" }]}'

参数

max_tokens
integerdefault: 256响应中生成的最大 token 数。
temperature
numberdefault: 0.6minimum: 0maximum: 5控制输出的随机性;值越高,结果越随机。

API schema(原始)

输入
输出

这篇文档对您有帮助吗?