fruitbars / simple-one-api

OpenAI 接口接入适配,支持千帆大模型平台、讯飞星火大模型、腾讯混元以及MiniMax、Deep-Seek,等兼容OpenAI接口,仅单可执行文件,配置超级简单,一键部署,开箱即用. Seamlessly integrate with OpenAI and compatible APIs using a single executable for quick setup and deployment.
MIT License
1.24k stars 111 forks source link

Use `claude-3-5-sonnet-20240620` from different providers/channels. #74

Closed hongyi-zhao closed 2 weeks ago

hongyi-zhao commented 2 weeks ago

If I want to use claude-3-5-sonnet-20240620 from different providers/channels with the following "model_map" method based config.json:

{
  "api_key": "123456",
  "debug": false,
  "load_balancing": "random",
  "proxy": {
    "type": "http",
    "http_proxy": "http://127.0.0.1:8080",
    "strategy": "default"
  },
  "services": {
    "claude.ai": [
      {
        "models": [
          "claude.ai/claude-3-5-sonnet-20240620"
        ],
        "enabled": true,
        "credentials": {
          "api_key": "sk-ant-xxx"
        },
        "model_map": {
          "claude.ai/claude-3-5-sonnet-20240620": "claude-3-5-sonnet-20240620"
        },        
        "server_url": "https://api.anthropic.com/v1/messages",
        "use_proxy": true
      }
    ],
    "wildcard.com.cn": [
      {
        "models": [
          "wildcard.com.cn/claude-3-5-sonnet-20240620"
        ],
        "enabled": true,
        "credentials": {
          "api_key": "sk-xxx"
        },
        "model_map": {
          "wildcard.com.cn/claude-3-5-sonnet-20240620": "claude-3-5-sonnet-20240620"
        },        
        "server_url": "https://api.gptsapi.net/v1/chat/completions"
      }
    ] 
  }
}

But the access to these models failed:

$ curl http://127.0.0.1:9090/v1/chat/completions   -H "Content-Type: application/json"   -H "Authorization: Bearer 123456"   -d '{
  "model": "claude.ai/claude-3-5-sonnet-20240620",
  "messages": [{"role": "user", "content": "Hello, GPT-4!"}]
}'
{"error":"service handler not found"}

$ curl http://127.0.0.1:9090/v1/chat/completions   -H "Content-Type: application/json"   -H "Authorization: Bearer 123456"   -d '{
  "model": "wildcard.com.cn/claude-3-5-sonnet-20240620",
  "messages": [{"role": "user", "content": "Hello, GPT-4!"}]
}'
{"error":"service handler not found"}

image

On the other hand, how to do it with model_redirect?

hongyi-zhao commented 2 weeks ago

After trial and error, the following method work:

$ cat config_claude.json 
{
  "api_key": "123456",
  "debug": false,
  "load_balancing": "random",
  "proxy": {
    "type": "http",
    "http_proxy": "http://127.0.0.1:8080",
    "strategy": "default"
  },
  "services": {
    "claude": [
      {
        "models": [
          "claude/claude-3-5-sonnet-20240620"
        ],
        "enabled": true,
        "credentials": {
          "api_key": "sk-ant-xxx"
        },
        "model_redirect": {
          "claude.ai/claude-3-5-sonnet-20240620": "claude-3-5-sonnet-20240620"
        },        
        "server_url": "https://api.anthropic.com/v1/messages",
        "use_proxy": true
      }
    ],
    "openai": [
      {
        "models": [
          "my-claude-3-5-sonnet-20240620"
        ],
        "enabled": true,
        "credentials": {
          "api_key": "sk-xxx"
        },
        "model_redirect": {
          "my-claude-3-5-sonnet-20240620": "claude-3-5-sonnet-20240620"
        },        
        "server_url": "https://api.gptsapi.net/v1/chat/completions"
      }
    ] 
  }
}

In the above config file, model_redirect can also be replaced by model_map, and no other changes are needed.

The original failure was due to the following two reasons: