yym68686 commited on
Commit
c9427f3
·
1 Parent(s): d088195

🪞 Frontend: Added sidebar support to the front end, removed the menu bar.

Browse files
Files changed (3) hide show
  1. README.md +33 -32
  2. README_CN.md +6 -5
  3. main.py +53 -46
README.md CHANGED
@@ -25,7 +25,7 @@ For personal use, one/new-api is too complex with many commercial features that
25
  - Support four types of load balancing.
26
  1. Supports channel-level weighted load balancing, allowing requests to be distributed according to different channel weights. It is not enabled by default and requires configuring channel weights.
27
  2. Support Vertex regional load balancing and high concurrency, which can increase Gemini and Claude concurrency by up to (number of APIs * number of regions) times. Automatically enabled without additional configuration.
28
- 3. Except for Vertex region-level load balancing, all APIs support channel-level sequential load balancing, enhancing the immersive translation experience. Automatically enabled without additional configuration.
29
  4. Support automatic API key-level round-robin load balancing for multiple API Keys in a single channel.
30
  - Support automatic retry, when an API channel response fails, automatically retry the next API channel.
31
  - Support fine-grained permission control. Support using wildcards to set specific models available for API key channels.
@@ -59,36 +59,36 @@ Detailed advanced configuration of `api.yaml`:
59
 
60
  ```yaml
61
  providers:
62
- - provider: provider_name # Service provider name, such as openai, anthropic, gemini, openrouter, deepbricks, any name, required
63
- base_url: https://api.your.com/v1/chat/completions # Backend service API address, required
64
  api: sk-YgS6GTi0b4bEabc4C # Provider's API Key, required
65
- model: # Optional, if model is not configured, all available models will be automatically retrieved through base_url and api via the /v1/models endpoint.
66
- - gpt-4o # Usable model name, required
67
- - claude-3-5-sonnet-20240620: claude-3-5-sonnet # Rename model, claude-3-5-sonnet-20240620 is the provider's model name, claude-3-5-sonnet is the renamed name, you can use a simpler name instead of the original complex name, optional
68
  - dall-e-3
69
 
70
  - provider: anthropic
71
  base_url: https://api.anthropic.com/v1/messages
72
- api: # Supports multiple API Keys, multiple keys automatically enable round-robin load balancing, at least one key, required
73
  - sk-ant-api03-bNnAOJyA-xQw_twAA
74
  - sk-ant-api02-bNnxxxx
75
  model:
76
- - claude-3-5-sonnet-20240620: claude-3-5-sonnet # Rename model, claude-3-5-sonnet-20240620 is the provider's model name, claude-3-5-sonnet is the renamed name, you can use a simpler name instead of the original complex name, optional
77
- tools: true # Whether to support tools, such as code generation, document generation, etc., default is true, optional
78
 
79
  - provider: gemini
80
  base_url: https://generativelanguage.googleapis.com/v1beta # base_url supports v1beta/v1, only for Gemini models, required
81
  api: AIzaSyAN2k6IRdgw
82
  model:
83
  - gemini-1.5-pro
84
- - gemini-1.5-flash-exp-0827: gemini-1.5-flash # After renaming, the original model name gemini-1.5-flash-exp-0827 cannot be used, if you want to use the original name, you can add the original name in the model, just add the following line to use the original name
85
  - gemini-1.5-flash-exp-0827 # Add this line, both gemini-1.5-flash-exp-0827 and gemini-1.5-flash can be requested
86
  tools: true
87
 
88
  - provider: vertex
89
- project_id: gen-lang-client-xxxxxxxxxxxxxx # Description: Your Google Cloud project ID. Format: String, usually composed of lowercase letters, numbers, and hyphens. How to obtain: You can find your project ID in the project selector of the Google Cloud Console.
90
- private_key: "-----BEGIN PRIVATE KEY-----\nxxxxx\n-----END PRIVATE" # Description: The private key of the Google Cloud Vertex AI service account. Format: A JSON-formatted string containing the private key information of the service account. How to obtain: Create a service account in the Google Cloud Console, generate a JSON-formatted key file, and then set its content as the value of this environment variable.
91
- client_email: xxxxxxxxxx@xxxxxxx.gserviceaccount.com # Description: The email address of the Google Cloud Vertex AI service account. Format: Usually a string like "service-account-name@project-id.iam.gserviceaccount.com". How to obtain: Generated when creating a service account, or can be obtained by viewing service account details in the "IAM & Admin" section of the Google Cloud Console.
92
  model:
93
  - gemini-1.5-pro
94
  - gemini-1.5-flash
@@ -97,14 +97,14 @@ providers:
97
  - claude-3-sonnet@20240229: claude-3-sonnet
98
  - claude-3-haiku@20240307: claude-3-haiku
99
  tools: true
100
- notes: https://xxxxx.com/ # Can include the provider's website, notes, official documentation, optional
101
 
102
  - provider: cloudflare
103
  api: f42b3xxxxxxxxxxq4aoGAh # Cloudflare API Key, required
104
  cf_account_id: 8ec0xxxxxxxxxxxxe721 # Cloudflare Account ID, required
105
  model:
106
- - '@cf/meta/llama-3.1-8b-instruct': llama-3.1-8b # Rename model, @cf/meta/llama-3.1-8b-instruct is the provider's original model name, must be enclosed in quotes to avoid YAML syntax error, llama-3.1-8b is the renamed name, you can use a simpler name instead of the original complex name, optional
107
- - '@cf/meta/llama-3.1-8b-instruct' # Must be enclosed in quotes to avoid YAML syntax error
108
 
109
  - provider: other-provider
110
  base_url: https://api.xxx.com/v1/messages
@@ -113,37 +113,38 @@ providers:
113
  - causallm-35b-beta2ep-q6k: causallm-35b
114
  - anthropic/claude-3-5-sonnet
115
  tools: false
116
- engine: openrouter # Force use of a specific message format, currently supports gpt, claude, gemini, openrouter native format, optional
117
 
118
  api_keys:
119
- - api: sk-KjjI60Yf0JFWxfgRmXqFWyGtWUd9GZnmi3KlvowmRWpWpQRo # API Key, required for users to use this service
120
- model: # The models that this API Key can use, required. Channel-level round-robin load balancing is enabled by default, and each request model is requested in the order configured in the model. It is unrelated to the original channel order in providers. Therefore, you can set different request orders for each API key.
121
- - gpt-4o # Usable model name, can use all gpt-4o models provided by providers
122
- - claude-3-5-sonnet # Usable model name, can use all claude-3-5-sonnet models provided by providers
123
- - gemini/* # Usable model name, can only use all models provided by the provider named gemini, where gemini is the provider name, * represents all models
124
  role: admin
125
 
126
  - api: sk-pkhf60Yf0JGyJxgRmXqFQyTgWUd9GZnmi3KlvowmRWpWqrhy
127
  model:
128
- - anthropic/claude-3-5-sonnet # Usable model name, can only use the claude-3-5-sonnet model provided by the provider named anthropic. Models named claude-3-5-sonnet from other providers cannot be used. This notation will not match the model named anthropic/claude-3-5-sonnet provided by other-provider.
129
- - <anthropic/claude-3-5-sonnet> # By adding angle brackets around the model name, it will not look for the claude-3-5-sonnet model under the channel named anthropic, but instead treat the entire anthropic/claude-3-5-sonnet as the model name. This notation can match the model named anthropic/claude-3-5-sonnet provided by other-provider. But it will not match the claude-3-5-sonnet model under anthropic.
130
- - openai-test/text-moderation-latest # When message moderation is enabled, the text-moderation-latest model under the channel named openai-test can be used for message moderation.
131
  preferences:
132
- SCHEDULING_ALGORITHM: fixed_priority # When SCHEDULING_ALGORITHM is fixed_priority, fixed priority scheduling is used, always executing the channel of the first model with a request. Modify the default channel round-robin load balancing. SCHEDULING_ALGORITHM options are: fixed_priority, weighted_round_robin, lottery, random.
133
- # When SCHEDULING_ALGORITHM is random, random round-robin load balancing is used, randomly requesting the channel of the model with a request.
 
134
  AUTO_RETRY: true # Whether to automatically retry, automatically retry the next provider, true for automatic retry, false for no automatic retry, default is true
135
- RATE_LIMIT: 2/min # Supports rate limiting, the maximum number of requests per minute, can be set as an integer, such as 2/min, 2 times per minute, 5/hour, 5 times per hour, 10/day, 10 times per day, 10/month, 10 times per month, 10/year, 10 times per year. Default is 60/min, optional
136
- ENABLE_MODERATION: true # Whether to enable message moderation, true to enable, false to disable, default is false, when enabled, user messages will be moderated, and if inappropriate messages are found, an error message will be returned.
137
 
138
  # Channel-level weighted load balancing configuration example
139
  - api: sk-KjjI60Yd0JFWtxxxxxxxxxxxxxxwmRWpWpQRo
140
  model:
141
  - gcp1/*: 5 # The number after the colon is the weight, weight only supports positive integers.
142
- - gcp2/*: 3 # The larger the number, the greater the probability of the request.
143
- - gcp3/*: 2 # In this example, there are a total of 10 weights across all channels, and out of 10 requests, 5 requests will request the gcp1/* model, 2 requests will request the gcp2/* model, and 3 requests will request the gcp3/* model.
144
 
145
  preferences:
146
- SCHEDULING_ALGORITHM: weighted_round_robin # Only when SCHEDULING_ALGORITHM is weighted_round_robin and if the above channels have weights, requests will be made according to the weighted order. Use weighted round-robin load balancing, request the channel of the model with a request according to the weight order. When SCHEDULING_ALGORITHM is lottery, use lottery round-robin load balancing, request the channel of the model with a request according to the weight randomly.
147
  AUTO_RETRY: true
148
  ```
149
 
 
25
  - Support four types of load balancing.
26
  1. Supports channel-level weighted load balancing, allowing requests to be distributed according to different channel weights. It is not enabled by default and requires configuring channel weights.
27
  2. Support Vertex regional load balancing and high concurrency, which can increase Gemini and Claude concurrency by up to (number of APIs * number of regions) times. Automatically enabled without additional configuration.
28
+ 3. Except for Vertex region-level load balancing, all APIs support channel-level sequential load balancing, enhancing the immersive translation experience. It is not enabled by default and requires configuring `SCHEDULING_ALGORITHM` as `round_robin`.
29
  4. Support automatic API key-level round-robin load balancing for multiple API Keys in a single channel.
30
  - Support automatic retry, when an API channel response fails, automatically retry the next API channel.
31
  - Support fine-grained permission control. Support using wildcards to set specific models available for API key channels.
 
59
 
60
  ```yaml
61
  providers:
62
+ - provider: provider_name # Service provider name, such as openai, anthropic, gemini, openrouter, deepbricks, any name can be given, required
63
+ base_url: https://api.your.com/v1/chat/completions # API address of the backend service, required
64
  api: sk-YgS6GTi0b4bEabc4C # Provider's API Key, required
65
+ model: # Optional, if model is not configured, all available models will be automatically obtained via base_url and api through the /v1/models endpoint.
66
+ - gpt-4o # Model name that can be used, required
67
+ - claude-3-5-sonnet-20240620: claude-3-5-sonnet # Renamed model, claude-3-5-sonnet-20240620 is the provider's model name, claude-3-5-sonnet is the renamed name, you can use a simple name to replace the original complex name, optional
68
  - dall-e-3
69
 
70
  - provider: anthropic
71
  base_url: https://api.anthropic.com/v1/messages
72
+ api: # Supports multiple API Keys, multiple keys automatically enable polling load balancing, at least one key, required
73
  - sk-ant-api03-bNnAOJyA-xQw_twAA
74
  - sk-ant-api02-bNnxxxx
75
  model:
76
+ - claude-3-5-sonnet-20240620: claude-3-5-sonnet # Renamed model, claude-3-5-sonnet-20240620 is the provider's model name, claude-3-5-sonnet is the renamed name, you can use a simple name to replace the original complex name, optional
77
+ tools: true # Whether to support tools, such as generating code, generating documents, etc., default is true, optional
78
 
79
  - provider: gemini
80
  base_url: https://generativelanguage.googleapis.com/v1beta # base_url supports v1beta/v1, only for Gemini models, required
81
  api: AIzaSyAN2k6IRdgw
82
  model:
83
  - gemini-1.5-pro
84
+ - gemini-1.5-flash-exp-0827: gemini-1.5-flash # After renaming, the original model name gemini-1.5-flash-exp-0827 cannot be used, if you want to use the original name, you can add the original name in the model, just add the line below to use the original name
85
  - gemini-1.5-flash-exp-0827 # Add this line, both gemini-1.5-flash-exp-0827 and gemini-1.5-flash can be requested
86
  tools: true
87
 
88
  - provider: vertex
89
+ project_id: gen-lang-client-xxxxxxxxxxxxxx # Description: Your Google Cloud project ID. Format: String, usually composed of lowercase letters, numbers, and hyphens. How to obtain: You can find your project ID in the project selector in Google Cloud Console.
90
+ private_key: "-----BEGIN PRIVATE KEY-----\nxxxxx\n-----END PRIVATE" # Description: Private key of Google Cloud Vertex AI service account. Format: A JSON formatted string containing the private key information of the service account. How to obtain: Create a service account in Google Cloud Console, generate a JSON format key file, and then set its content as the value of this environment variable.
91
+ client_email: xxxxxxxxxx@xxxxxxx.gserviceaccount.com # Description: Email address of Google Cloud Vertex AI service account. Format: Usually a string like "service-account-name@project-id.iam.gserviceaccount.com". How to obtain: Generated when creating a service account, can also be obtained by viewing the service account details in the "IAM and Admin" section of Google Cloud Console.
92
  model:
93
  - gemini-1.5-pro
94
  - gemini-1.5-flash
 
97
  - claude-3-sonnet@20240229: claude-3-sonnet
98
  - claude-3-haiku@20240307: claude-3-haiku
99
  tools: true
100
+ notes: https://xxxxx.com/ # You can put the provider's website, notes, official documentation, optional
101
 
102
  - provider: cloudflare
103
  api: f42b3xxxxxxxxxxq4aoGAh # Cloudflare API Key, required
104
  cf_account_id: 8ec0xxxxxxxxxxxxe721 # Cloudflare Account ID, required
105
  model:
106
+ - '@cf/meta/llama-3.1-8b-instruct': llama-3.1-8b # Renamed model, @cf/meta/llama-3.1-8b-instruct is the provider's original model name, the model name must be enclosed in quotes, otherwise yaml syntax error, llama-3.1-8b is the renamed name, you can use a simple name to replace the original complex name, optional
107
+ - '@cf/meta/llama-3.1-8b-instruct' # The model name must be enclosed in quotes, otherwise yaml syntax error
108
 
109
  - provider: other-provider
110
  base_url: https://api.xxx.com/v1/messages
 
113
  - causallm-35b-beta2ep-q6k: causallm-35b
114
  - anthropic/claude-3-5-sonnet
115
  tools: false
116
+ engine: openrouter # Force to use a specific message format, currently supports gpt, claude, gemini, openrouter native format, optional
117
 
118
  api_keys:
119
+ - api: sk-KjjI60Yf0JFWxfgRmXqFWyGtWUd9GZnmi3KlvowmRWpWpQRo # API Key, users need an API key to use this service, required
120
+ model: # The model that this API Key can use, required. Channel-level polling load balancing is enabled by default, each request model is requested in the order configured in the model. It is unrelated to the original channel order in providers. Therefore, you can set different request orders for each API key.
121
+ - gpt-4o # Model name that can be used, can use the gpt-4o model provided by all providers
122
+ - claude-3-5-sonnet # Model name that can be used, can use the claude-3-5-sonnet model provided by all providers
123
+ - gemini/* # Model name that can be used, can only use all models provided by the provider named gemini, where gemini is the provider name, * represents all models
124
  role: admin
125
 
126
  - api: sk-pkhf60Yf0JGyJxgRmXqFQyTgWUd9GZnmi3KlvowmRWpWqrhy
127
  model:
128
+ - anthropic/claude-3-5-sonnet # Model name that can be used, can only use the claude-3-5-sonnet model provided by the provider named anthropic. The claude-3-5-sonnet model from other providers cannot be used. This way of writing will not match the model named anthropic/claude-3-5-sonnet provided by other-provider.
129
+ - <anthropic/claude-3-5-sonnet> # By adding angle brackets on both sides of the model name, it will not look for the claude-3-5-sonnet model under the channel named anthropic, but will use the entire anthropic/claude-3-5-sonnet as the model name. This way of writing can match the model named anthropic/claude-3-5-sonnet provided by other-provider. But it will not match the claude-3-5-sonnet model under anthropic.
130
+ - openai-test/text-moderation-latest # When message moderation is enabled, the text-moderation-latest model under the channel named openai-test can be used for moral review.
131
  preferences:
132
+ SCHEDULING_ALGORITHM: fixed_priority # When SCHEDULING_ALGORITHM is fixed_priority, use fixed priority scheduling, always execute the first channel with a request. Enabled by default, the default value of SCHEDULING_ALGORITHM is fixed_priority. Optional values for SCHEDULING_ALGORITHM are: fixed_priority, round_robin, weighted_round_robin, lottery, random.
133
+ # When SCHEDULING_ALGORITHM is random, use random polling load balancing, randomly request the channel with the requested model.
134
+ # When SCHEDULING_ALGORITHM is round_robin, use polling load balancing, request the channel of the user's model in order.
135
  AUTO_RETRY: true # Whether to automatically retry, automatically retry the next provider, true for automatic retry, false for no automatic retry, default is true
136
+ RATE_LIMIT: 2/min # Supports rate limiting, maximum number of requests per minute, can be set to an integer, such as 2/min, 2 times per minute, 5/hour, 5 times per hour, 10/day, 10 times per day, 10/month, 10 times per month, 10/year, 10 times per year. Default is 60/min, optional
137
+ ENABLE_MODERATION: true # Whether to enable message moderation, true for enable, false for disable, default is false, when enabled, messages will be morally reviewed, if inappropriate messages are found, an error message will be returned.
138
 
139
  # Channel-level weighted load balancing configuration example
140
  - api: sk-KjjI60Yd0JFWtxxxxxxxxxxxxxxwmRWpWpQRo
141
  model:
142
  - gcp1/*: 5 # The number after the colon is the weight, weight only supports positive integers.
143
+ - gcp2/*: 3 # The size of the number represents the weight, the larger the number, the greater the probability of the request.
144
+ - gcp3/*: 2 # In this example, there are a total of 10 weights across all channels, and 5 out of 10 requests will request the gcp1/* model, 2 requests will request the gcp2/* model, and 3 requests will request the gcp3/* model.
145
 
146
  preferences:
147
+ SCHEDULING_ALGORITHM: weighted_round_robin # Only when SCHEDULING_ALGORITHM is weighted_round_robin and the channels above have weights, requests will be made in the weighted order. Use weighted polling load balancing, request the channel of the model with the request in weight order. When SCHEDULING_ALGORITHM is lottery, use lottery polling load balancing, randomly request the channel of the model with the request according to weight. Channels without weights automatically fall back to round_robin polling load balancing.
148
  AUTO_RETRY: true
149
  ```
150
 
README_CN.md CHANGED
@@ -25,7 +25,7 @@
25
  - 支持四种负载均衡。
26
  1. 支持渠道级加权负载均衡,可以根据不同的渠道权重分配请求。默认不开启,需要配置渠道权重。
27
  2. 支持 Vertex 区域级负载均衡,支持 Vertex 高并发,最高可将 Gemini,Claude 并发提高 (API数量 * 区域数量) 倍。自动开启不需要额外配置。
28
- 3. 除了 Vertex 区域级负载均衡,所有 API 均支持渠道级顺序负载均衡,提高沉浸式翻译体验。自动开启不需要额外配置。
29
  4. 支持单个渠道多个 API Key 自动开启 API key 级别的轮训负载均衡。
30
  - 支持自动重试,当一个 API 渠道响应失败时,自动重试下一个 API 渠道。
31
  - 支持细粒度的权限控制。支持使用通配符设置 API key 可用渠道的特定模型。
@@ -87,8 +87,8 @@ providers:
87
 
88
  - provider: vertex
89
  project_id: gen-lang-client-xxxxxxxxxxxxxx # 描述: 您的Google Cloud项目ID。格式: 字符串,通常由小写字母、数字和连字符组成。获取方式: 在Google Cloud Console的项目选择器中可以找到您的项目ID。
90
- private_key: "-----BEGIN PRIVATE KEY-----\nxxxxx\n-----END PRIVATE" # 描述: Google Cloud Vertex AI服务账号的私钥。格式: 一个JSON格式的字符串,包含服务账号的私钥信息。获取方式: 在Google Cloud Console中创建服务账号,生成JSON格式的密钥文件,然后将其内容设置为此环境变量的值。
91
- client_email: xxxxxxxxxx@xxxxxxx.gserviceaccount.com # 描述: Google Cloud Vertex AI服务账号的电子邮件地址。格式: 通常是形如 "service-account-name@project-id.iam.gserviceaccount.com" 的字符串。获取方式: 在创建服务账号时生成,也可以在Google Cloud Console的"IAM与管理"部分查看服务账号详情获得。
92
  model:
93
  - gemini-1.5-pro
94
  - gemini-1.5-flash
@@ -129,8 +129,9 @@ api_keys:
129
  - <anthropic/claude-3-5-sonnet> # 通过在模型名两侧加上尖括号,这样就不会去名为anthropic的渠道下去寻找claude-3-5-sonnet模型,而是将整个 anthropic/claude-3-5-sonnet 作为模型名称。这种写法可以匹配到other-provider提供的名为 anthropic/claude-3-5-sonnet 的模型。但不会匹配到anthropic下面的claude-3-5-sonnet模型。
130
  - openai-test/text-moderation-latest # 当开启消息道德审查后,可以使用名为 openai-test 渠道下的 text-moderation-latest 模型进行道德审查。
131
  preferences:
132
- SCHEDULING_ALGORITHM: fixed_priority # 当 SCHEDULING_ALGORITHM 为 fixed_priority 时,使用固定优先级调度,永远执行第一个拥有请求的模型的渠道。修改默认开启的渠道轮询负载均衡。SCHEDULING_ALGORITHM 可选值为:fixed_priority,weighted_round_robin, lottery, random。
133
  # 当 SCHEDULING_ALGORITHM 为 random 时,使用随机轮训负载均衡,随机请求拥有请求的模型的渠道。
 
134
  AUTO_RETRY: true # 是否自动重试,自动重试下一个提供商,true 为自动重试,false 为不自动重试,默认为 true
135
  RATE_LIMIT: 2/min # 支持限流,每分钟最多请求次数,可以设置为整数,如 2/min,2 次每分钟、5/hour,5 次每小时、10/day,10 次每天,10/month,10 次每月,10/year,10 次每年。默认60/min,选填
136
  ENABLE_MODERATION: true # 是否开启消息道德审查,true 为开启,false 为不开启,默认为 false,当开启后,会对用户的消息进行道德审查,如果发现不当的消息,会返回错误信息。
@@ -143,7 +144,7 @@ api_keys:
143
  - gcp3/*: 2 # 在该示例中,所有渠道加起来一共�� 10 个权重,及 10 个请求里面有 5 个请求会请求 gcp1/* 模型,2 个请求会请求 gcp2/* 模型,3 个请求会请求 gcp3/* 模型。
144
 
145
  preferences:
146
- SCHEDULING_ALGORITHM: weighted_round_robin # 仅当 SCHEDULING_ALGORITHM 为 weighted_round_robin 并且上面的渠道如果有权重,会按照加权后的顺序请求。使用加权轮训负载均衡,按照权重顺序请求拥有请求的模型的渠道。当 SCHEDULING_ALGORITHM 为 lottery 时,使用抽奖轮训负载均衡,按照权重随机请求拥有请求的模型的渠道。
147
  AUTO_RETRY: true
148
  ```
149
 
 
25
  - 支持四种负载均衡。
26
  1. 支持渠道级加权负载均衡,可以根据不同的渠道权重分配请求。默认不开启,需要配置渠道权重。
27
  2. 支持 Vertex 区域级负载均衡,支持 Vertex 高并发,最高可将 Gemini,Claude 并发提高 (API数量 * 区域数量) 倍。自动开启不需要额外配置。
28
+ 3. 除了 Vertex 区域级负载均衡,所有 API 均支持渠道级顺序负载均衡,提高沉浸式翻译体验。默认不开启,需要配置 `SCHEDULING_ALGORITHM` 为 `round_robin`。
29
  4. 支持单个渠道多个 API Key 自动开启 API key 级别的轮训负载均衡。
30
  - 支持自动重试,当一个 API 渠道响应失败时,自动重试下一个 API 渠道。
31
  - 支持细粒度的权限控制。支持使用通配符设置 API key 可用渠道的特定模型。
 
87
 
88
  - provider: vertex
89
  project_id: gen-lang-client-xxxxxxxxxxxxxx # 描述: 您的Google Cloud项目ID。格式: 字符串,通常由小写字母、数字和连字符组成。获取方式: 在Google Cloud Console的项目选择器中可以找到您的项目ID。
90
+ private_key: "-----BEGIN PRIVATE KEY-----\nxxxxx\n-----END PRIVATE" # 描述: Google Cloud Vertex AI服务账号的私钥。格式: 一个 JSON 格式的字符串,包含服务账号的私钥信息。获取方式: 在 Google Cloud Console 中创建服务账号,生成JSON格式的密钥文件,然后将其内容设置为此环境变量的值。
91
+ client_email: xxxxxxxxxx@xxxxxxx.gserviceaccount.com # 描述: Google Cloud Vertex AI 服务账号的电子邮件地址。格式: 通常是形如 "service-account-name@project-id.iam.gserviceaccount.com" 的字符串。获取方式: 在创建服务账号时生成,也可以在 Google Cloud Console 的"IAM与管理"部分查看服务账号详情获得。
92
  model:
93
  - gemini-1.5-pro
94
  - gemini-1.5-flash
 
129
  - <anthropic/claude-3-5-sonnet> # 通过在模型名两侧加上尖括号,这样就不会去名为anthropic的渠道下去寻找claude-3-5-sonnet模型,而是将整个 anthropic/claude-3-5-sonnet 作为模型名称。这种写法可以匹配到other-provider提供的名为 anthropic/claude-3-5-sonnet 的模型。但不会匹配到anthropic下面的claude-3-5-sonnet模型。
130
  - openai-test/text-moderation-latest # 当开启消息道德审查后,可以使用名为 openai-test 渠道下的 text-moderation-latest 模型进行道德审查。
131
  preferences:
132
+ SCHEDULING_ALGORITHM: fixed_priority # 当 SCHEDULING_ALGORITHM 为 fixed_priority 时,使用固定优先级调度,永远执行第一个拥有请求的模型的渠道。默认开启,SCHEDULING_ALGORITHM 缺省值为 fixed_priority。SCHEDULING_ALGORITHM 可选值有:fixed_priorityround_robin,weighted_round_robin, lottery, random。
133
  # 当 SCHEDULING_ALGORITHM 为 random 时,使用随机轮训负载均衡,随机请求拥有请求的模型的渠道。
134
+ # 当 SCHEDULING_ALGORITHM 为 round_robin 时,使用轮训负载均衡,按照顺序请求用户使用的模型的渠道。
135
  AUTO_RETRY: true # 是否自动重试,自动重试下一个提供商,true 为自动重试,false 为不自动重试,默认为 true
136
  RATE_LIMIT: 2/min # 支持限流,每分钟最多请求次数,可以设置为整数,如 2/min,2 次每分钟、5/hour,5 次每小时、10/day,10 次每天,10/month,10 次每月,10/year,10 次每年。默认60/min,选填
137
  ENABLE_MODERATION: true # 是否开启消息道德审查,true 为开启,false 为不开启,默认为 false,当开启后,会对用户的消息进行道德审查,如果发现不当的消息,会返回错误信息。
 
144
  - gcp3/*: 2 # 在该示例中,所有渠道加起来一共�� 10 个权重,及 10 个请求里面有 5 个请求会请求 gcp1/* 模型,2 个请求会请求 gcp2/* 模型,3 个请求会请求 gcp3/* 模型。
145
 
146
  preferences:
147
+ SCHEDULING_ALGORITHM: weighted_round_robin # 仅当 SCHEDULING_ALGORITHM 为 weighted_round_robin 并且上面的渠道如果有权重,会按照加权后的顺序请求。使用加权轮训负载均衡,按照权重顺序请求拥有请求的模型的渠道。当 SCHEDULING_ALGORITHM 为 lottery 时,使用抽奖轮训负载均衡,按照权重随机请求拥有请求的模型的渠道。没设置权重的渠道自动回退到 round_robin 轮训负载均衡。
148
  AUTO_RETRY: true
149
  ```
150
 
main.py CHANGED
@@ -1077,8 +1077,7 @@ from xue.components.menubar import (
1077
  Menubar, MenubarMenu, MenubarTrigger, MenubarContent,
1078
  MenubarItem, MenubarSeparator
1079
  )
1080
- from xue.components import input
1081
- from xue.components import dropdown, sheet, form, button, checkbox
1082
  from xue.components.model_config_row import model_config_row
1083
  # import sys
1084
  # import os
@@ -1184,6 +1183,38 @@ async def verify_api_key(x_api_key: str = FastapiForm(...)):
1184
  else:
1185
  return Div("无效的API密钥", class_="text-red-500").render()
1186
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1187
  @frontend_router.get("/", response_class=HTMLResponse, dependencies=[Depends(frontend_rate_limit_dependency)])
1188
  async def root(x_api_key: str = Depends(get_api_key)):
1189
  if not x_api_key:
@@ -1200,56 +1231,22 @@ async def root(x_api_key: str = Depends(get_api_key)):
1200
  });
1201
  });
1202
  """),
1203
- title="Menubar Example"
1204
  ),
1205
  Body(
1206
  Div(
1207
- Menubar(
1208
- MenubarMenu(
1209
- MenubarTrigger("File", "file-menu"),
1210
- MenubarContent(
1211
- MenubarItem("New Tab", shortcut="⌘T"),
1212
- MenubarItem("New Window", shortcut="⌘N"),
1213
- MenubarItem("New Incognito Window", disabled=True),
1214
- MenubarSeparator(),
1215
- MenubarItem("Print...", shortcut="⌘P"),
1216
- ),
1217
- id="file-menu"
1218
- ),
1219
- MenubarMenu(
1220
- MenubarTrigger("Edit", "edit-menu"),
1221
- MenubarContent(
1222
- MenubarItem("Undo", shortcut="⌘Z"),
1223
- MenubarItem("Redo", shortcut="⇧⌘Z"),
1224
- MenubarSeparator(),
1225
- MenubarItem("Cut"),
1226
- MenubarItem("Copy"),
1227
- MenubarItem("Paste"),
1228
- ),
1229
- id="edit-menu"
1230
- ),
1231
- MenubarMenu(
1232
- MenubarTrigger("View", "view-menu"),
1233
- MenubarContent(
1234
- MenubarItem("Always Show Bookmarks Bar"),
1235
- MenubarItem("Always Show Full URLs"),
1236
- MenubarSeparator(),
1237
- MenubarItem("Reload", shortcut="⌘R"),
1238
- MenubarItem("Force Reload", shortcut="⇧⌘R", disabled=True),
1239
- MenubarSeparator(),
1240
- MenubarItem("Toggle Fullscreen"),
1241
- MenubarItem("Hide Sidebar"),
1242
- ),
1243
- id="view-menu"
1244
  ),
 
 
 
1245
  ),
1246
- class_="p-4"
1247
- ),
1248
- Div(
1249
- data_table(data_table_columns, app.state.config["providers"], "users-table"),
1250
- class_="p-4"
1251
  ),
1252
- Div(id="sheet-container"), # 这里是 sheet 将被加载的地方
1253
  class_="container mx-auto",
1254
  id="body"
1255
  )
@@ -1257,6 +1254,16 @@ async def root(x_api_key: str = Depends(get_api_key)):
1257
  # print(result)
1258
  return result
1259
 
 
 
 
 
 
 
 
 
 
 
1260
  @frontend_router.get("/dropdown-menu/{menu_id}/{row_id}", response_class=HTMLResponse, dependencies=[Depends(frontend_rate_limit_dependency)])
1261
  async def get_columns_menu(menu_id: str, row_id: str):
1262
  columns = [
 
1077
  Menubar, MenubarMenu, MenubarTrigger, MenubarContent,
1078
  MenubarItem, MenubarSeparator
1079
  )
1080
+ from xue.components import input, dropdown, sheet, form, button, checkbox, sidebar
 
1081
  from xue.components.model_config_row import model_config_row
1082
  # import sys
1083
  # import os
 
1183
  else:
1184
  return Div("无效的API密钥", class_="text-red-500").render()
1185
 
1186
+ # 添加侧边栏配置
1187
+ sidebar_items = [
1188
+ {
1189
+ "icon": "layout-dashboard",
1190
+ # "label": "仪表盘",
1191
+ "label": "Dashboard",
1192
+ "value": "dashboard",
1193
+ "hx": {"get": "/dashboard", "target": "#main-content"}
1194
+ },
1195
+ # {
1196
+ # "icon": "settings",
1197
+ # # "label": "设置",
1198
+ # "label": "Settings",
1199
+ # "value": "settings",
1200
+ # "hx": {"get": "/settings", "target": "#main-content"}
1201
+ # },
1202
+ # {
1203
+ # "icon": "database",
1204
+ # # "label": "数据",
1205
+ # "label": "Data",
1206
+ # "value": "data",
1207
+ # "hx": {"get": "/data", "target": "#main-content"}
1208
+ # },
1209
+ # {
1210
+ # "icon": "scroll-text",
1211
+ # # "label": "日志",
1212
+ # "label": "Logs",
1213
+ # "value": "logs",
1214
+ # "hx": {"get": "/logs", "target": "#main-content"}
1215
+ # }
1216
+ ]
1217
+
1218
  @frontend_router.get("/", response_class=HTMLResponse, dependencies=[Depends(frontend_rate_limit_dependency)])
1219
  async def root(x_api_key: str = Depends(get_api_key)):
1220
  if not x_api_key:
 
1231
  });
1232
  });
1233
  """),
1234
+ title="uni-api"
1235
  ),
1236
  Body(
1237
  Div(
1238
+ sidebar.Sidebar("zap", "uni-api", sidebar_items, is_collapsed=False, active_item="dashboard"),
1239
+ Div(
1240
+ Div(
1241
+ data_table(data_table_columns, app.state.config["providers"], "users-table"),
1242
+ class_="p-4"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1243
  ),
1244
+ Div(id="sheet-container"), # sheet加载位置
1245
+ id="main-content",
1246
+ class_="ml-[240px] p-6 transition-[margin] duration-200 ease-in-out"
1247
  ),
1248
+ class_="flex"
 
 
 
 
1249
  ),
 
1250
  class_="container mx-auto",
1251
  id="body"
1252
  )
 
1254
  # print(result)
1255
  return result
1256
 
1257
+ @frontend_router.get("/sidebar/toggle", response_class=HTMLResponse)
1258
+ async def toggle_sidebar(is_collapsed: bool = False):
1259
+ return sidebar.Sidebar(
1260
+ "zap",
1261
+ "uni-api",
1262
+ sidebar_items,
1263
+ is_collapsed=not is_collapsed,
1264
+ active_item="dashboard"
1265
+ ).render()
1266
+
1267
  @frontend_router.get("/dropdown-menu/{menu_id}/{row_id}", response_class=HTMLResponse, dependencies=[Depends(frontend_rate_limit_dependency)])
1268
  async def get_columns_menu(menu_id: str, row_id: str):
1269
  columns = [