大模型服务启动后的接口测试方案

以下是几个可直接执行的 curl 测试命令,覆盖健康检查、普通对话、推理模式和工具调用:

1. 基础连通性 & 模型列表

curl -s http://localhost:8000/v1/models \
  -H "Authorization: Bearer <API_KEY>" | jq

2. 普通对话(非推理模式)

curl -s http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <API_KEY>" \
  -d '{
    "model": "Qwen3.5-397B-A17B",
    "messages": [{"role": "user", "content": "你好,请简要介绍自己"}],
    "max_tokens": 256,
    "temperature": 0.7
  }' | jq '.choices[0].message.content'

3. 推理模式测试(启用 thinking / reasoning)

curl -s http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <API_KEY>" \
  -d '{
    "model": "Qwen3.5-397B-A17B",
    "messages": [{"role": "user", "content": "9.11 和 9.9 哪个更大?请逐步推理"}],
    "max_tokens": 1024,
    "temperature": 0.6,
    "reasoning": true
  }' | jq

返回中会有 message.reasoning_content 和 message.content 两个字段,前者是思考过程,后者是最终答案。

4. 工具调用测试(Tool Call)

curl -s http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <API_KEY>" \
  -d '{
    "model": "Qwen3.5-397B-A17B",
    "messages": [{"role": "user", "content": "北京现在天气怎么样?"}],
    "tools": [{
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "获取指定城市的当前天气",
        "parameters": {
          "type": "object",
          "properties": {
            "city": {"type": "string", "description": "城市名称"}
          },
          "required": ["city"]
        }
      }
    }],
    "tool_choice": "auto",
    "max_tokens": 512
  }' | jq '.choices[0].message.tool_calls'

5. 流式输出测试(SSE)

curl -N http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <API_KEY>" \
  -d '{
    "model": "Qwen3.5-397B-A17B",
    "messages": [{"role": "user", "content": "写一首关于AI的短诗"}],
    "max_tokens": 256,
    "stream": true
  }'

快速验证脚本(一键全测)

#!/bin/bash
API_KEY="<API_KEY>"
URL="http://localhost:8000/v1/chat/completions"
MODEL="Qwen3.5-397B-A17B"

echo "=== 测试1: 普通对话 ===" curl -s $URL -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \ -d "{\"model\":\"$MODEL\",\"messages\":[{\"role\":\"user\",\"content\":\"你好\"}],\"max_tokens\":64}" | jq -r '.choices[0].message.content'
echo -e "\n=== 测试2: 推理模式 ===" curl -s $URL -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \ -d "{\"model\":\"$MODEL\",\"messages\":[{\"role\":\"user\",\"content\":\"1+1等于几?请思考\"}],\"max_tokens\":128,\"reasoning\":true}" | jq '.choices[0].message | {reasoning_content, content}'

如果还没装 jq,用 apt-get install jq 或把 | jq 改成 | cat 即可。


转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 365433079@qq.com