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

gemma-2b-it-lora

Beta

Text Generation • Google

查看 MarkdownAgent 设置
  • Cloudflare-hosted
  • LoRA

这是 Cloudflare 专用于搭配 LoRA 适配器进行推理的 Gemma-2B 基础模型。Gemma 是 Google 推出的轻量级、最先进的开放模型系列,采用了与 Gemini 模型相同的研究成果和技术构建。

模型信息
上下文窗口 ↗8,192 个 token
LoRA是
Beta是

试用环境

使用 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/google/gemma-2b-it-lora", {
      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/google/gemma-2b-it-lora", { 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/google/gemma-2b-it-lora",
    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/google/gemma-2b-it-lora \
  -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" }]}'

参数

输入

prompt
stringrequiredminLength: 1供模型生成响应的输入文本提示词。
lora
string用于微调基础模型的 LoRA(低秩适配,Low-Rank Adaptation)模型名称。
raw
booleandefault: false如果为 true,则不应用聊天模板,您必须遵循特定模型所要求的格式。
stream
booleandefault: false如果为 true,响应将通过 SSE(Server Sent Events,服务器发送事件)以增量方式流式返回。
max_tokens
integerdefault: 256响应中生成的最大 token 数。
temperature
numberdefault: 0.6minimum: 0maximum: 5控制输出的随机性;值越高,结果越随机。
top_p
numberminimum: 0.001maximum: 1通过控制模型考虑的候选词数量来调整 AI 响应的创造性。较低的值使输出更可预测;较高的值使响应更加多样、更具创意。
top_k
integerminimum: 1maximum: 50限制 AI 仅从概率最高的前 k 个词中进行选择。较低的值使响应更聚焦;较高的值会带来更多变化和意外结果。
seed
integerminimum: 1maximum: 9999999999用于使生成结果可复现的随机种子。
repetition_penalty
numberminimum: 0maximum: 2对重复 token 的惩罚;值越高,越能抑制重复。
frequency_penalty
numberminimum: -2maximum: 2降低模型逐字重复相同内容的可能性。
presence_penalty
numberminimum: -2maximum: 2提高模型引入新话题的可能性。

输出

Synchronous — Send a request and receive a complete response
response
string模型生成的文本响应
Streaming — Send a request with `stream: true` and receive server-sent events
type
string
format
binary

API schema(原始)

Synchronous输入
Synchronous输出
Streaming输入
Streaming输出

这篇文档对您有帮助吗?