yym68686 commited on
Commit
d2ba74a
·
1 Parent(s): 9bf0345

📖 Docs: Update documentation

Browse files
Files changed (3) hide show
  1. README.md +3 -4
  2. README_CN.md +1 -2
  3. main.py +7 -12
README.md CHANGED
@@ -49,11 +49,10 @@ providers:
49
  - provider: provider_name # Service provider name, such as openai, anthropic, gemini, openrouter, deepbricks, can be any name, required
50
  base_url: https://api.your.com/v1/chat/completions # Backend service API address, required
51
  api: sk-YgS6GTi0b4bEabc4C # Provider's API Key, required, automatically uses base_url and api to get all available models through the /v1/models endpoint.
52
- # Multiple providers can be configured here, each provider can have multiple API Keys, and each API Key can have multiple models configured.
53
  api_keys:
54
- - api: sk-Pkj60Yf8JFWxfgRmXQFWyGtWUddGZnmi3KlvowmRWpWpQxx # API Key, required for user requests to uni-api
55
- model: # Models that can be used by this API Key, required. Channel-level round-robin load balancing is enabled by default, and each request to the model follows the order configured in model. It is independent of the original channel order in providers. Therefore, you can set a different request order for each API key.
56
- - all # Can use all models from all channels set under providers, no need to add available channels one by one. If you don't want to set available channels for each api in api_keys, uni-api supports setting the api key to use all models from all channels under providers.
57
  ```
58
 
59
  Detailed advanced configuration of `api.yaml`:
 
49
  - provider: provider_name # Service provider name, such as openai, anthropic, gemini, openrouter, deepbricks, can be any name, required
50
  base_url: https://api.your.com/v1/chat/completions # Backend service API address, required
51
  api: sk-YgS6GTi0b4bEabc4C # Provider's API Key, required, automatically uses base_url and api to get all available models through the /v1/models endpoint.
52
+ # Multiple providers can be configured here, each provider can configure multiple API Keys, and each API Key can configure multiple models.
53
  api_keys:
54
+ - api: sk-Pkj60Yf8JFWxfgRmXQFWyGtWUddGZnmi3KlvowmRWpWpQxx # API Key, user request uni-api requires API key, required
55
+ # This API Key can use all models, that is, it can use all models in all channels set under providers, without needing to add available channels one by one.
 
56
  ```
57
 
58
  Detailed advanced configuration of `api.yaml`:
README_CN.md CHANGED
@@ -52,8 +52,7 @@ providers:
52
  # 这里可以配置多个提供商,每个提供商可以配置多个 API Key,每个 API Key 可以配置多个模型。
53
  api_keys:
54
  - api: sk-Pkj60Yf8JFWxfgRmXQFWyGtWUddGZnmi3KlvowmRWpWpQxx # API Key,用户请求 uni-api 需要 API key,必填
55
- model: # 该 API Key 可以使用的模型,必填。默认开启渠道级轮询负载均衡,每次请求模型按照 model 配置的顺序依次请求。与 providers 里面原始的渠道顺序无关。因此你可以设置每个 API key 请求顺序不一样。
56
- - all # 可以使用 providers 下面设置的所有渠道里面的所有模型,不需要一个个添加可用渠道。如果你不想在 `api_keys` 里面给每个 `api` 一个个设置可用渠道,`uni-api` 支持将 `api key` 设置为可以使用 providers 下面所有渠道的所有模型。
57
  ```
58
 
59
  `api.yaml` 详细的高级配置:
 
52
  # 这里可以配置多个提供商,每个提供商可以配置多个 API Key,每个 API Key 可以配置多个模型。
53
  api_keys:
54
  - api: sk-Pkj60Yf8JFWxfgRmXQFWyGtWUddGZnmi3KlvowmRWpWpQxx # API Key,用户请求 uni-api 需要 API key,必填
55
+ # 该 API Key 可以使用所有模型,即可以使用 providers 下面设置的所有渠道里面的所有模型,不需要一个个添加可用渠道。
 
56
  ```
57
 
58
  `api.yaml` 详细的高级配置:
main.py CHANGED
@@ -631,7 +631,7 @@ class ModelRequestHandler:
631
 
632
  for model in config['api_keys'][api_index]['model']:
633
  if model == "all":
634
- # 如果模型名为 *,则返回所有模型
635
  for provider in config["providers"]:
636
  model_dict = get_model_dict(provider)
637
  for model in model_dict.keys():
@@ -661,7 +661,7 @@ class ModelRequestHandler:
661
  # api_keys 中 model 为 provider_name/* 时,表示所有模型都匹配
662
  if model_name_split == "*":
663
  if model_name in models_list:
664
- provider_rules.append(provider_name)
665
 
666
  # 如果请求模型名: gpt-4* ,则匹配所有以模型名开头且不以 * 结尾的模型
667
  for models_list_model in models_list:
@@ -684,21 +684,16 @@ class ModelRequestHandler:
684
  # print("provider_rules", provider_rules)
685
  for item in provider_rules:
686
  for provider in config['providers']:
687
- # print("provider", provider, provider['provider'] == item, item)
688
- if provider['provider'] == item.split("/")[0]:
689
  new_provider = copy.deepcopy(provider)
690
  model_dict = get_model_dict(provider)
691
- # print("model_dict", model_dict)
692
  model_name_split = "/".join(item.split("/")[1:])
693
- if model_name in model_dict.keys():
694
- if "/" in item and model_name_split == model_name:
695
- new_provider["model"] = [{model_dict[model_name]: model_name}]
696
- # 如果 item 不包含 /,则直接匹配 provider,说明整个渠道所有模型都能用
697
  provider_list.append(new_provider)
698
 
699
- elif model_name.endswith("*") and "/" in item and model_name_split.startswith(model_name.rstrip("*")):
700
- # old: new
701
- new_provider["model"] = [{model_dict[model_name_split]: model_name}]
702
  provider_list.append(new_provider)
703
 
704
  # print("provider_list", provider_list)
 
631
 
632
  for model in config['api_keys'][api_index]['model']:
633
  if model == "all":
634
+ # 如果模型名为 all,则返回所有模型
635
  for provider in config["providers"]:
636
  model_dict = get_model_dict(provider)
637
  for model in model_dict.keys():
 
661
  # api_keys 中 model 为 provider_name/* 时,表示所有模型都匹配
662
  if model_name_split == "*":
663
  if model_name in models_list:
664
+ provider_rules.append(provider_name + "/" + model_name)
665
 
666
  # 如果请求模型名: gpt-4* ,则匹配所有以模型名开头且不以 * 结尾的模型
667
  for models_list_model in models_list:
 
684
  # print("provider_rules", provider_rules)
685
  for item in provider_rules:
686
  for provider in config['providers']:
687
+ if "/" in item and provider['provider'] == item.split("/")[0]:
 
688
  new_provider = copy.deepcopy(provider)
689
  model_dict = get_model_dict(provider)
 
690
  model_name_split = "/".join(item.split("/")[1:])
691
+ # old: new
692
+ new_provider["model"] = [{model_dict[model_name_split]: model_name}]
693
+ if model_name in model_dict.keys() and model_name_split == model_name:
 
694
  provider_list.append(new_provider)
695
 
696
+ elif model_name.endswith("*") and model_name_split.startswith(model_name.rstrip("*")):
 
 
697
  provider_list.append(new_provider)
698
 
699
  # print("provider_list", provider_list)