跳转至

深度思考

深度思考模型是一种具备复杂推理能力的AI系统,通过多步骤逻辑分析、自我反思和链式思维,解决需要深层认知处理的难题。本文介绍如何调用 GLM、Deepseek、Minimax 等支持深度思考的模型。

混合思考模式,默认开启思考模式:GLM-5.1、GLM-5、GLM-4.7
仅思考模式:MiniMax-M2.5、MiniMax-M2.1

1. 在 curl 中使用深度思考

curl --request POST \
  --url https://api.magikcloud.cn/v1/chat/completions \
  --header 'Authorization: Bearer ${API_KEY}' \ # 替换为你的 API Key
  --header 'Content-Type: application/json' \
  --data '{
    "model": "${ENDPOINT}",  # 替换为你的接入点ID
    "messages": [{
        "role": "user",
        "content": "你是谁"
    }],
    "stream": true,
    "stream_options":{"include_usage": true},
    "chat_template_kwargs": {"thinking": true} # 开启深度思考
  }'

2. 在 python 中使用深度思考

import requests

url = "https://api.magikcloud.cn/v1/chat/completions"

payload = {
    "model": "${ENDPOINT}", # 替换为你的接入点ID
    "messages": [
        {
            "role": "user",
            "content": "Please give a travel plan"
        }
    ],
    "stream": True,
    "stream_options":{"include_usage": True},
    "chat_template_kwargs": {"thinking": True} # 开启深度思考
}
headers = {
    "Authorization": "Bearer ${API_KEY}", # 替换为你的 API Key
    "Content-Type": "application/json"
}

response = requests.request("POST", url, json=payload, headers=headers)

print(response.text)

3. 在 javascript 中使用深度思考

var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer ${API_KEY}"); // 替换为你的 API Key
myHeaders.append("Content-Type", "application/json");

var raw = JSON.stringify({
    "messages": [
        {
            "role": "user",
            "content": "Please give a travel plan"
        }
    ],
    "model": "${ENDPOINT}", // 替换为你的接入点ID
    "stream": true,
    "chat_template_kwargs": {"thinking": true} // 开启深度思考
});

var requestOptions = {
    method: 'POST',
    headers: myHeaders,
    body: raw,
    redirect: 'follow'
};

fetch("https://api.magikcloud.cn/v1/chat/completions", requestOptions)
    .then(response => response.text())
    .then(result => console.log(result))
    .catch(error => console.log('error', error));

4. 在 Golang 中使用深度思考

package main

import (
    "bytes"
    "encoding/json"
    "net/http"
)

func main() {
    url := "https://api.magikcloud.cn/v1/chat/completions"
    payload := map[string]interface{} {
        "model": "${ENDPOINT}", // 替换为你的接入点ID
        "messages": []map[string]string{
            {"role": "user", "content": "Please give a travel plan"},
        },
        "stream": true,
        "chat_template_kwargs": {"thinking": true} // 开启深度思考
    }
    body, _ := json.Marshal(payload)
    req, _ := http.NewRequest("POST", url, bytes.NewBuffer(body))
    req.Header.Set("Authorization", "Bearer ${API_KEY}") // 替换为你的 API Key
    req.Header.Set("Content-Type", "application/json")
    client := &http.Client{}
    resp, _ := client.Do(req)
    defer resp.Body.Close()
}