Skip to content

Latest commit

 

History

History
56 lines (42 loc) · 1.24 KB

File metadata and controls

56 lines (42 loc) · 1.24 KB

LLMSpeed - LLM Token 速度测试工具

测试 OpenAI Chat 和 Anthropic 格式模型的速度,测量首次响应延迟和每秒 Token 数。

功能

  • 支持 OpenAI Chat 和 Anthropic 流式 API
  • 测量首次响应延迟(ms)和每秒 Token 数
  • 通过 content-type 检查提前检测无效模型
  • 支持推理模型的 reasoning_content 字段
  • 结果导出为 CSV

配置文件格式 (config.yaml)

test_prompt: "你好,请介绍一下你自己"

models:
  - base_url: "https://api.openai.com/v1"
    type: "openai-chat"
    models:
      - "gpt-4o"
      - "gpt-4o-mini"
    api_key: "sk-xxx"

  - base_url: "https://api.anthropic.com"
    type: "anthropic"
    models:
      - "claude-3-5-sonnet-20241022"
    api_key: "sk-ant-xxx"

运行

pip install openai anthropic pyyaml
python llmspeed.py

使用自定义配置文件:

python llmspeed.py my_config.yaml

输出

结果保存到 results.csv,包含以下列:

列名 说明
base_url API 端点
type API 类型(openai-chatanthropic
model 模型名称
first_token_latency 首次响应延迟(ms),失败为 -1
tokens_per_second 每秒 Token 数,失败为 -1