📖 Docs: Update documentation
Browse files- README.md +3 -4
- README_CN.md +1 -2
- 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
|
53 |
api_keys:
|
54 |
-
- api: sk-Pkj60Yf8JFWxfgRmXQFWyGtWUddGZnmi3KlvowmRWpWpQxx # API Key,
|
55 |
-
|
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 |
-
|
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 |
-
|
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 |
-
|
694 |
-
|
695 |
-
|
696 |
-
# 如果 item 不包含 /,则直接匹配 provider,说明整个渠道所有模型都能用
|
697 |
provider_list.append(new_provider)
|
698 |
|
699 |
-
elif model_name.endswith("*") and
|
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)
|