Skip to content

About

No description, website, or topics provided.

Resources

Stars

16 stars

Watchers

1 watching

Forks

Repository files navigation

An Open-Source DeepSeek API Router

English 中文

An open-source router for public DeepSeek API services with custom policies (e.g., lowest price, highest output token rate).

Currently, it supports DeepSeek R1 and the following providers:

The following table explains the metrics that this tool can evaluate:

Abbreviation Full Form Description Supported Statistics
ttft Time to first token Latency between input submission and generation of the first output token average, median, p90, p99
prefill Prefill tokens per second # of input tokens / ttft average, median, p90, p99
decode Decode tokens per second # of output tokens / (total time - ttft) average, median, p90, p99
otps Output tokens per second # of output tokens / total time average, median, p90, p99
otpr Output tokens per request Total output tokens (including reasoning tokens) generated to answer one user request average, median, p90, p99
success Request success rate Percentage of requests completed without errors/timeouts (regardless of correctness)
gpqa Graduate-Level Google-Proof Q&A Benchmark testing expert-level knowledge across STEM/humanities
aime2024 American Invitational Mathematics Examination 2024 Math problem-solving benchmark based on real competition questions
livecodebench Live Coding Benchmark Code generation evaluation with execution testing
mmlu Massive Multitask Language Understanding 57-subject multiple-choice test spanning STEM/humanities
ceval Chinese Evaluation Chinese-language benchmark
output_price Output token price CNY per million output tokens
input_price Input token price CNY per million input tokens

Install

conda create -n deepseek_router python=3.10
conda activate deepseek_router
git clone --recurse-submodules [email protected]:llm-router/DeepSeekRouter.git
cd DeepSeekRouter
pip install -e .

Configuration

  1. Change the log field in config/cron.json to where you want to store the logs.
  2. Set the default field of each provider to your own API key in config/keys.json. Ignore those providers of which you do not have a key and those that you do not plan to evaluate.
{
  "volcengine": {
    "default": "your-key-for-volcengine"
  },
  "together": {
    "default": "your-key-for-together.ai"
  },
  ...
  1. You do not need to configure the endpoints of the inference providers except for Azure AI Foundry. You need to change the base_url field to your own endpoint.

[Optional] If you want to use a SQL database to store the results and deploy the dashboard

  1. Change the connection string in config/db.json to yours. If you use MySQL, it should look like:
{
  "conn_str": "mysql+mysqlconnector://user:12345678@localhost:3306/deepseek_router"
}
  1. Run the following command to create tables:
python deepseek_router/model/model.py
  1. Run the following command to start the web app:
python deepseek_router/app/app.py
  1. The dashboard is available at http://localhost:5000. You need to run the evaluation to see the results. Check out deepseek_router/app/templates/home.html and make your changes to the dashboard.

Evaluate intelligence

You should use deepseek_router/cron/benchmark_test_all.py to evaluate intelligence. It can take one day or more to run a dataset.

  1. Download the datasets:
./scripts/download_datasets.sh # Download dataset for opencompass evaluate
  1. Use llmqos/cron/benchmark_test_all.py to evaluate intelligence. It can take one day or more to run a dataset. Use --output flag to specify the output format.

Available datasets are under data/datasets.json. Note that only gpqa, aime2024 and ceval have been tested.

python deepseek_router/cron/benchmark_test_all.py --dataset <dataset> --output <db OR csv OR both> # run dataset for all providers

Evaluate performance

You should use deepseek_router/cron/service_perf_test_all.py to evaluate performance. It can take a few minute for one run. You should run it for enough time in order to get an accurate result.

python deepseek_router/cron/service_perf_test_all.py --output <db OR csv OR both>

By default, we use ShareGPT and L-Eval datasets for performance testing. You can write your own prompt generator and use that for performance testing.

Choose the best providers for you

After you have done evaluation, you can provide your requirement and find out the right providers for you. A requirement file looks like:

{
  "filters": [
    {
      "metric": "success",
      "min": 0.95
    },
    {
      "metric": "otps",
      "stat": "p90",
      "min": 30
    },
    {
      "metric": "gpqa",
      "min": 60
    }
  ],
  "order": [
    {
      "metric": "output_price"
    }
  ]
}

Run the router program:

python deepseek_router/router/router.py --requirement <PATH_TO_YOUR_REQUIREMENT_FILE>

Acknowledgments

We have referred to the design of the following projects/websites:

We reused OpenCompass for running benchmarks.

About

No description, website, or topics provided.

Resources

Stars

16 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages