跳到正文
原文
OpenRouter:Announcements(RSS)·· 2025-01-24精选AI 评分64

OpenRouter 推出 Reasoning Tokens 功能,可查看思考型模型的推理过程

Reasoning Tokens for Thinking Models

AI 导读

OpenRouter 发布 Reasoning Tokens 功能,在 Chatroom 和 API 中可观察模型的推理步骤,API 请求中添加 include_reasoning: true 即可在消息的 reasoning 字段返回推理内容。

推荐理由

官方公告给出 API 参数和示例代码,读者可以直接了解如何获取并复用模型的推理过程。

正文 · AI 翻译

我们很高兴地宣布推出 Reasoning Tokens,这是一项新功能,让你可以在聊天室和通过 API 观察模型的推理过程。

推理 token 让你可以透明地查看模型所采取的推理步骤。

要使用,请在 API 请求中添加 include_reasoning: true。启用后,推理 token 将出现在每条消息的 reasoning 字段中:

import requests
import json

url = "https://openrouter.ai/api/v1/chat/completions"
headers = {
    "Authorization": f"Bearer {OPENROUTER_API_KEY}",
    "Content-Type": "application/json"
}
payload = {
    "model": "deepseek/deepseek-r1",
    "messages": [
        {"role": "user", "content": "How would you build the world's tallest skyscraper?"}
    ],
    "include_reasoning": True
}

response = requests.post(url, headers=headers, data=json.dumps(payload))
print(response.json()['choices'][0]['message']['reasoning'])

推理 token 最初适用于 DeepSeek R1 模型(及其衍生模型),后续将支持 Gemini Thinking 模型。

你当然可以查看推理过程,但这也可以潜在地用于更复杂的工作流。下面是一个玩具示例(灵感来自 X 上的 @skirano),将 R1 的推理注入到一个能力弱得多的模型中,使其更聪明。这个示例本身实用性存疑,但我们很期待看到推理 token 用例的演进!

import requests
import json

question = "Which is bigger: 9.11 or 9.9?"

url = "https://openrouter.ai/api/v1/chat/completions"
headers = {
    "Authorization": f"Bearer {TOKEN}",
    "Content-Type": "application/json"
}

def do_req(model, content, include_reasoning=False):
    payload = {
        "model": model,
        "messages": [
            {"role": "user", "content": content}
        ],
        "include_reasoning": include_reasoning
    }
    return requests.post(url, headers=headers, data=json.dumps(payload))

# R1 will reliably return "done" for the content portion of the response
content = f"{question} Please think this through, but don't output an answer -- only think about the problem, and output 'done'."
reasoning_response = do_req("deepseek/deepseek-r1", content, True)
reasoning = reasoning_response.json()['choices'][0]['message']['reasoning']

# Let's test!
simple_response = do_req("openai/gpt-3.5-turbo-instruct", question)
print(simple_response.json()['choices'][0]['message']['content'])

content = f"{question}. Here is some context to help you: {reasoning}"
smart_response = do_req("openai/gpt-3.5-turbo-instruct", content)
print(smart_response.json()['choices'][0]['message']['content'])

来源:OpenRouter:Announcements(RSS) · openrouter.ai