Spaces:
Sleeping
Sleeping
Keldos
commited on
Commit
·
8d81d5a
1
Parent(s):
ccd8f6d
feat: 重新加入将usage显示为进度条功能
Browse files原功能显示赠金进度条,
本在 ec10bf7faa610cac1d8ff35a420426fd9f60d3b6 引入,
在 94f0d7d23587384474abc2472c96689144208bba 移除
- assets/custom.css +1 -1
- config_example.json +1 -0
- locale/en_US.json +1 -0
- locale/ja_JP.json +1 -0
- modules/config.py +3 -0
- modules/models/models.py +14 -3
assets/custom.css
CHANGED
@@ -111,7 +111,7 @@ footer {
|
|
111 |
}
|
112 |
.progress-bar {
|
113 |
background-color: var(--input-background-fill);;
|
114 |
-
margin: 0
|
115 |
height: 20px;
|
116 |
border-radius: 10px;
|
117 |
overflow: hidden;
|
|
|
111 |
}
|
112 |
.progress-bar {
|
113 |
background-color: var(--input-background-fill);;
|
114 |
+
margin: .5em 0 !important;
|
115 |
height: 20px;
|
116 |
border-radius: 10px;
|
117 |
overflow: hidden;
|
config_example.json
CHANGED
@@ -2,6 +2,7 @@
|
|
2 |
// 你的OpenAI API Key,一般必填,
|
3 |
// 若缺省填为 "openai_api_key": "" 则必须再在图形界面中填入API Key
|
4 |
"openai_api_key": "",
|
|
|
5 |
// 你的xmchat API Key,与OpenAI API Key不同
|
6 |
"xmchat_api_key": "",
|
7 |
"language": "auto",
|
|
|
2 |
// 你的OpenAI API Key,一般必填,
|
3 |
// 若缺省填为 "openai_api_key": "" 则必须再在图形界面中填入API Key
|
4 |
"openai_api_key": "",
|
5 |
+
"usage_limit": 120, // API Key的当月限额,单位:美元
|
6 |
// 你的xmchat API Key,与OpenAI API Key不同
|
7 |
"xmchat_api_key": "",
|
8 |
"language": "auto",
|
locale/en_US.json
CHANGED
@@ -50,6 +50,7 @@
|
|
50 |
",本次对话累计消耗了 ": ",Total cost for this dialogue is ",
|
51 |
"**获取API使用情况失败**": "**Failed to get API usage**",
|
52 |
"**本月使用金额** ": "**Monthly usage** ",
|
|
|
53 |
"获取API使用情况失败:": "Failed to get API usage:",
|
54 |
"API密钥更改为了": "The API key is changed to",
|
55 |
"JSON解析错误,收到的内容: ": "JSON parsing error, received content: ",
|
|
|
50 |
",本次对话累计消耗了 ": ",Total cost for this dialogue is ",
|
51 |
"**获取API使用情况失败**": "**Failed to get API usage**",
|
52 |
"**本月使用金额** ": "**Monthly usage** ",
|
53 |
+
"本月使用金额": "Monthly usage",
|
54 |
"获取API使用情况失败:": "Failed to get API usage:",
|
55 |
"API密钥更改为了": "The API key is changed to",
|
56 |
"JSON解析错误,收到的内容: ": "JSON parsing error, received content: ",
|
locale/ja_JP.json
CHANGED
@@ -50,6 +50,7 @@
|
|
50 |
",本次对话累计消耗了 ": ", 今の会話で消費合計 ",
|
51 |
"**获取API使用情况失败**": "**API使用状況の取得に失敗しました**",
|
52 |
"**本月使用金额** ": "**今月の使用料金** ",
|
|
|
53 |
"获取API使用情况失败:": "API使用状況の取得に失敗しました:",
|
54 |
"API密钥更改为了": "APIキーが変更されました",
|
55 |
"JSON解析错误,收到的内容: ": "JSON解析エラー、受信内容: ",
|
|
|
50 |
",本次对话累计消耗了 ": ", 今の会話で消費合計 ",
|
51 |
"**获取API使用情况失败**": "**API使用状況の取得に失敗しました**",
|
52 |
"**本月使用金额** ": "**今月の使用料金** ",
|
53 |
+
"本月使用金额": "今月の使用料金",
|
54 |
"获取API使用情况失败:": "API使用状況の取得に失敗しました:",
|
55 |
"API密钥更改为了": "APIキーが変更されました",
|
56 |
"JSON解析错误,收到的内容: ": "JSON解析エラー、受信内容: ",
|
modules/config.py
CHANGED
@@ -19,6 +19,7 @@ __all__ = [
|
|
19 |
"advance_docs",
|
20 |
"update_doc_config",
|
21 |
"render_latex",
|
|
|
22 |
"multi_api_key",
|
23 |
"server_name",
|
24 |
"server_port",
|
@@ -82,6 +83,8 @@ if render_latex:
|
|
82 |
else:
|
83 |
os.environ["RENDER_LATEX"] = "no"
|
84 |
|
|
|
|
|
85 |
## 多账户机制
|
86 |
multi_api_key = config.get("multi_api_key", False) # 是否开启多账户机制
|
87 |
if multi_api_key:
|
|
|
19 |
"advance_docs",
|
20 |
"update_doc_config",
|
21 |
"render_latex",
|
22 |
+
"usage_limit",
|
23 |
"multi_api_key",
|
24 |
"server_name",
|
25 |
"server_port",
|
|
|
83 |
else:
|
84 |
os.environ["RENDER_LATEX"] = "no"
|
85 |
|
86 |
+
usage_limit = os.environ.get("USAGE_LIMIT", config.get("usage_limit", 120))
|
87 |
+
|
88 |
## 多账户机制
|
89 |
multi_api_key = config.get("multi_api_key", False) # 是否开启多账户机制
|
90 |
if multi_api_key:
|
modules/models/models.py
CHANGED
@@ -25,7 +25,7 @@ from ..presets import *
|
|
25 |
from ..llama_func import *
|
26 |
from ..utils import *
|
27 |
from .. import shared
|
28 |
-
from ..config import retrieve_proxy
|
29 |
from modules import config
|
30 |
from .base_model import BaseLLMModel, ModelType
|
31 |
|
@@ -90,8 +90,19 @@ class OpenAIClient(BaseLLMModel):
|
|
90 |
except Exception as e:
|
91 |
logging.error(f"获取API使用情况失败:" + str(e))
|
92 |
return i18n("**获取API使用情况失败**")
|
93 |
-
rounded_usage = "{:.5f}".format(usage_data["total_usage"] / 100)
|
94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
except requests.exceptions.ConnectTimeout:
|
96 |
status_text = (
|
97 |
STANDARD_ERROR_MSG + CONNECTION_TIMEOUT_MSG + ERROR_RETRIEVE_MSG
|
|
|
25 |
from ..llama_func import *
|
26 |
from ..utils import *
|
27 |
from .. import shared
|
28 |
+
from ..config import retrieve_proxy, usage_limit
|
29 |
from modules import config
|
30 |
from .base_model import BaseLLMModel, ModelType
|
31 |
|
|
|
90 |
except Exception as e:
|
91 |
logging.error(f"获取API使用情况失败:" + str(e))
|
92 |
return i18n("**获取API使用情况失败**")
|
93 |
+
# rounded_usage = "{:.5f}".format(usage_data["total_usage"] / 100)
|
94 |
+
rounded_usage = round(usage_data["total_usage"] / 100, 5)
|
95 |
+
usage_percent = round(usage_data["total_usage"] / usage_limit, 2)
|
96 |
+
# return i18n("**本月使用金额** ") + f"\u3000 ${rounded_usage}"
|
97 |
+
return """\
|
98 |
+
<b>""" + i18n("本月使用金额") + f"""</b>
|
99 |
+
<div class="progress-bar">
|
100 |
+
<div class="progress" style="width: {usage_percent}%;">
|
101 |
+
<span class="progress-text">{usage_percent}%</span>
|
102 |
+
</div>
|
103 |
+
</div>
|
104 |
+
<div style="display: flex; justify-content: space-between;"><span>${rounded_usage}</span><span>${usage_limit}</span></div>
|
105 |
+
"""
|
106 |
except requests.exceptions.ConnectTimeout:
|
107 |
status_text = (
|
108 |
STANDARD_ERROR_MSG + CONNECTION_TIMEOUT_MSG + ERROR_RETRIEVE_MSG
|