跳转到正文
文档导航: 开放模型 / 其他推理客户端

其他推理客户端

RightNow AI开放模型其他推理客户端 更新于

本页内容

模型中心有两个推理客户端,Python 用 huggingface_hub,JavaScript 用 @huggingface/inference,两者都接受兼容 chat 的基础 URL,所以今天都能调用开放模型 API。

hub clients
Text
Illustration of the address each model hub client takes.

Both clients take an address. The Python client takes base_url, with the base URL that ends in /v1. The JavaScript client takes endpointUrl, with the host: the client adds /v1/chat/completions itself. Naming the open models as a provider does not resolve: they are not a registered inference provider in the model hub.

Python

Shell
pip install "huggingface_hub>=1.0"
export RIGHTNOW_API_KEY="rp_your_key_here"
Python
import os
from huggingface_hub import InferenceClient

client = InferenceClient(
    base_url="https://api.rightnowai.co/v1",
    api_key=os.environ["RIGHTNOW_API_KEY"],
)

prompt = "Write a TypeScript retry helper."
completion = client.chat.completions.create(
    model="MODEL_ID",
    messages=[{"role": "user", "content": prompt}],
    max_tokens=16384,
)

print(completion.choices[0].message.content)

把 MODEL_ID 换成实时列表中的 ID。这些客户端通常接收模型中心的仓库 ID;在本页的基础 URL 形式下,你传入的是开放模型的 ID,因为你直接与开放模型 API 通信。

流式传输就是加上 stream=True 的同一次调用,读取 chunk.choices[0].delta.content,并跳过没有 choices 的用量帧。

JavaScript

把密钥作为 token 传入,并在客户端选项中传入 endpointUrl。主机带不带 /v1 都可以工作。

Shell
npm install @huggingface/inference
export RIGHTNOW_API_KEY="rp_your_key_here"
Text
import { InferenceClient } from "@huggingface/inference";

const token = process.env.RIGHTNOW_API_KEY;
const client = new InferenceClient(token, {
  endpointUrl: "https://api.rightnowai.co",
});

const prompt = "Write a TypeScript retry helper.";
const completion = await client.chatCompletion({
  model: "MODEL_ID",
  messages: [{ role: "user", content: prompt }],
  max_tokens: 16384,
});

console.log(completion.choices[0].message.content);

chatCompletionStream 接受相同的参数并返回增量。

Warning

不要把 endpointUrl 与显式指定的第三方 provider 组合使用。客户端会用 Cannot use endpointUrl with a third-party provider 拒绝这种组合。只传 endpointUrl。

模型能力

可用的 JSON 片段在结构化输出中。当模型为 JSON 输出需要特定的 reasoning_effort 时,如果你省略该字段,网关会应用它。当网关选择了一个请求没有指定的强度时,其响应标头 X-RunInfra-Reasoning-Effort-Applied 会带上所应用的值。

暂时暂停的模型会在模型列表中以及它的开放模型页面上显示。

模型的推理在哪里出现

对于各自页面上介绍的推理模型,模型会先思考再回答。这段文本通过 delta.reasoning 流式传输并出现在 message.reasoning 上,绝不会出现在 content 上。

response.json
JSON
{
  "id": "chatcmpl-example",
  "object": "chat.completion",
  "model": "glm-5-3",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "reasoning": "The user wants a retry helper. I should use exponential backoff...",
        "content": "export async function retry<T>(fn: () => Promise<T>, attempts = 3) { ... }"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": { "prompt_tokens": 14, "completion_tokens": 892, "total_tokens": 906 }
}

本示例中的 id、文本和令牌数仅作说明。

应该用哪个客户端

如果你已经生活在模型中心的生态中,本页的客户端可以工作,这里以后也不会改变。否则请使用 chat API 客户端,它是最短的路径,这些文档的其余部分也以此为前提。请参阅兼容客户端。

无论哪种方式,这些调用都像对开放模型 API 的任何其他调用一样计费。请参阅价格与额度和速率限制。