Spaces:
Running
Running
JohnSmith9982
commited on
Commit
•
7bab2f2
1
Parent(s):
1405e1c
Upload 114 files
Browse files- ChuanhuChatbot.py +5 -1
- config_example.json +2 -0
- modules/.DS_Store +0 -0
- modules/__pycache__/__init__.cpython-311.pyc +0 -0
- modules/__pycache__/config.cpython-311.pyc +0 -0
- modules/__pycache__/index_func.cpython-311.pyc +0 -0
- modules/__pycache__/overwrites.cpython-311.pyc +0 -0
- modules/__pycache__/presets.cpython-311.pyc +0 -0
- modules/__pycache__/repo.cpython-311.pyc +0 -0
- modules/__pycache__/shared.cpython-311.pyc +0 -0
- modules/__pycache__/train_func.cpython-311.pyc +0 -0
- modules/__pycache__/utils.cpython-311.pyc +0 -0
- modules/__pycache__/webui.cpython-311.pyc +0 -0
- modules/__pycache__/webui_locale.cpython-311.pyc +0 -0
- modules/config.py +5 -0
- modules/models/ERNIE.py +96 -0
- modules/models/OpenAI.py +1 -1
- modules/models/OpenAIVision.py +1 -1
- modules/models/__pycache__/OpenAI.cpython-311.pyc +0 -0
- modules/models/__pycache__/__init__.cpython-311.pyc +0 -0
- modules/models/__pycache__/base_model.cpython-311.pyc +0 -0
- modules/models/__pycache__/models.cpython-311.pyc +0 -0
- modules/models/base_model.py +8 -2
- modules/models/models.py +3 -0
- modules/presets.py +21 -1
- modules/utils.py +19 -12
- requirements.txt +2 -0
- web_assets/.DS_Store +0 -0
- web_assets/javascript/message-button.js +5 -1
- web_assets/javascript/updater.js +17 -4
- web_assets/javascript/webui.js +5 -1
- web_assets/stylesheet/ChuanhuChat.css +15 -1
- web_assets/stylesheet/chatbot.css +15 -1
ChuanhuChatbot.py
CHANGED
@@ -135,6 +135,7 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
135 |
label="Chuanhu Chat",
|
136 |
elem_id="chuanhu-chatbot",
|
137 |
latex_delimiters=latex_delimiters_set,
|
|
|
138 |
# height=700,
|
139 |
show_label=False,
|
140 |
avatar_images=[config.user_avatar, config.bot_avatar],
|
@@ -244,7 +245,7 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
244 |
use_websearch_checkbox = gr.Checkbox(label=i18n(
|
245 |
"使用在线搜索"), value=False, elem_classes="switch-checkbox", elem_id="gr-websearch-cb", visible=False)
|
246 |
index_files = gr.Files(label=i18n(
|
247 |
-
"上传"), type="file", elem_id="upload-index-file")
|
248 |
two_column = gr.Checkbox(label=i18n(
|
249 |
"双栏pdf"), value=advance_docs["pdf"].get("two_column", False))
|
250 |
summarize_btn = gr.Button(i18n("总结"))
|
@@ -645,6 +646,8 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
645 |
current_model, status_display, chatbot, lora_select_dropdown, user_api_key, keyTxt], show_progress=True, api_name="get_model")
|
646 |
model_select_dropdown.change(toggle_like_btn_visibility, [model_select_dropdown], [
|
647 |
like_dislike_area], show_progress=False)
|
|
|
|
|
648 |
lora_select_dropdown.change(get_model, [model_select_dropdown, lora_select_dropdown, user_api_key, temperature_slider,
|
649 |
top_p_slider, systemPromptTxt, user_name, current_model], [current_model, status_display, chatbot], show_progress=True)
|
650 |
|
@@ -798,6 +801,7 @@ if __name__ == "__main__":
|
|
798 |
reload_javascript()
|
799 |
demo.queue(concurrency_count=CONCURRENT_COUNT).launch(
|
800 |
allowed_paths=["history", "web_assets"],
|
|
|
801 |
auth=auth_from_conf if authflag else None,
|
802 |
favicon_path="./web_assets/favicon.ico",
|
803 |
inbrowser=not dockerflag, # 禁止在docker下开启inbrowser
|
|
|
135 |
label="Chuanhu Chat",
|
136 |
elem_id="chuanhu-chatbot",
|
137 |
latex_delimiters=latex_delimiters_set,
|
138 |
+
sanitize_html=False,
|
139 |
# height=700,
|
140 |
show_label=False,
|
141 |
avatar_images=[config.user_avatar, config.bot_avatar],
|
|
|
245 |
use_websearch_checkbox = gr.Checkbox(label=i18n(
|
246 |
"使用在线搜索"), value=False, elem_classes="switch-checkbox", elem_id="gr-websearch-cb", visible=False)
|
247 |
index_files = gr.Files(label=i18n(
|
248 |
+
"上传"), type="file", file_types=[".pdf", ".docx", ".pptx", ".epub", ".xlsx", ".txt", "text", "image"], elem_id="upload-index-file")
|
249 |
two_column = gr.Checkbox(label=i18n(
|
250 |
"双栏pdf"), value=advance_docs["pdf"].get("two_column", False))
|
251 |
summarize_btn = gr.Button(i18n("总结"))
|
|
|
646 |
current_model, status_display, chatbot, lora_select_dropdown, user_api_key, keyTxt], show_progress=True, api_name="get_model")
|
647 |
model_select_dropdown.change(toggle_like_btn_visibility, [model_select_dropdown], [
|
648 |
like_dislike_area], show_progress=False)
|
649 |
+
# model_select_dropdown.change(
|
650 |
+
# toggle_file_type, [model_select_dropdown], [index_files], show_progress=False)
|
651 |
lora_select_dropdown.change(get_model, [model_select_dropdown, lora_select_dropdown, user_api_key, temperature_slider,
|
652 |
top_p_slider, systemPromptTxt, user_name, current_model], [current_model, status_display, chatbot], show_progress=True)
|
653 |
|
|
|
801 |
reload_javascript()
|
802 |
demo.queue(concurrency_count=CONCURRENT_COUNT).launch(
|
803 |
allowed_paths=["history", "web_assets"],
|
804 |
+
share=share,
|
805 |
auth=auth_from_conf if authflag else None,
|
806 |
favicon_path="./web_assets/favicon.ico",
|
807 |
inbrowser=not dockerflag, # 禁止在docker下开启inbrowser
|
config_example.json
CHANGED
@@ -15,6 +15,8 @@
|
|
15 |
"spark_api_key": "", // 你的 讯飞星火大模型 API Key,用于讯飞星火大模型对话模型
|
16 |
"spark_api_secret": "", // 你的 讯飞星火大模型 API Secret,用于讯飞星火大模型对话模型
|
17 |
"claude_api_secret":"",// 你的 Claude API Secret,用于 Claude 对话模型
|
|
|
|
|
18 |
|
19 |
|
20 |
//== Azure ==
|
|
|
15 |
"spark_api_key": "", // 你的 讯飞星火大模型 API Key,用于讯飞星火大模型对话模型
|
16 |
"spark_api_secret": "", // 你的 讯飞星火大模型 API Secret,用于讯飞星火大模型对话模型
|
17 |
"claude_api_secret":"",// 你的 Claude API Secret,用于 Claude 对话模型
|
18 |
+
"ernie_api_key": "",// 你的文心一言在百度云中的API Key,用于文心一言对话模型
|
19 |
+
"ernie_secret_key": "",// 你的文心一言在百度云中的Secret Key,用于文心一言对话模型
|
20 |
|
21 |
|
22 |
//== Azure ==
|
modules/.DS_Store
CHANGED
Binary files a/modules/.DS_Store and b/modules/.DS_Store differ
|
|
modules/__pycache__/__init__.cpython-311.pyc
CHANGED
Binary files a/modules/__pycache__/__init__.cpython-311.pyc and b/modules/__pycache__/__init__.cpython-311.pyc differ
|
|
modules/__pycache__/config.cpython-311.pyc
CHANGED
Binary files a/modules/__pycache__/config.cpython-311.pyc and b/modules/__pycache__/config.cpython-311.pyc differ
|
|
modules/__pycache__/index_func.cpython-311.pyc
CHANGED
Binary files a/modules/__pycache__/index_func.cpython-311.pyc and b/modules/__pycache__/index_func.cpython-311.pyc differ
|
|
modules/__pycache__/overwrites.cpython-311.pyc
CHANGED
Binary files a/modules/__pycache__/overwrites.cpython-311.pyc and b/modules/__pycache__/overwrites.cpython-311.pyc differ
|
|
modules/__pycache__/presets.cpython-311.pyc
CHANGED
Binary files a/modules/__pycache__/presets.cpython-311.pyc and b/modules/__pycache__/presets.cpython-311.pyc differ
|
|
modules/__pycache__/repo.cpython-311.pyc
CHANGED
Binary files a/modules/__pycache__/repo.cpython-311.pyc and b/modules/__pycache__/repo.cpython-311.pyc differ
|
|
modules/__pycache__/shared.cpython-311.pyc
CHANGED
Binary files a/modules/__pycache__/shared.cpython-311.pyc and b/modules/__pycache__/shared.cpython-311.pyc differ
|
|
modules/__pycache__/train_func.cpython-311.pyc
CHANGED
Binary files a/modules/__pycache__/train_func.cpython-311.pyc and b/modules/__pycache__/train_func.cpython-311.pyc differ
|
|
modules/__pycache__/utils.cpython-311.pyc
CHANGED
Binary files a/modules/__pycache__/utils.cpython-311.pyc and b/modules/__pycache__/utils.cpython-311.pyc differ
|
|
modules/__pycache__/webui.cpython-311.pyc
CHANGED
Binary files a/modules/__pycache__/webui.cpython-311.pyc and b/modules/__pycache__/webui.cpython-311.pyc differ
|
|
modules/__pycache__/webui_locale.cpython-311.pyc
CHANGED
Binary files a/modules/__pycache__/webui_locale.cpython-311.pyc and b/modules/__pycache__/webui_locale.cpython-311.pyc differ
|
|
modules/config.py
CHANGED
@@ -135,6 +135,11 @@ os.environ["SPARK_API_SECRET"] = spark_api_secret
|
|
135 |
claude_api_secret = config.get("claude_api_secret", "")
|
136 |
os.environ["CLAUDE_API_SECRET"] = claude_api_secret
|
137 |
|
|
|
|
|
|
|
|
|
|
|
138 |
load_config_to_environ(["openai_api_type", "azure_openai_api_key", "azure_openai_api_base_url",
|
139 |
"azure_openai_api_version", "azure_deployment_name", "azure_embedding_deployment_name", "azure_embedding_model_name"])
|
140 |
|
|
|
135 |
claude_api_secret = config.get("claude_api_secret", "")
|
136 |
os.environ["CLAUDE_API_SECRET"] = claude_api_secret
|
137 |
|
138 |
+
ernie_api_key = config.get("ernie_api_key", "")
|
139 |
+
os.environ["ERNIE_APIKEY"] = ernie_api_key
|
140 |
+
ernie_secret_key = config.get("ernie_secret_key", "")
|
141 |
+
os.environ["ERNIE_SECRETKEY"] = ernie_secret_key
|
142 |
+
|
143 |
load_config_to_environ(["openai_api_type", "azure_openai_api_key", "azure_openai_api_base_url",
|
144 |
"azure_openai_api_version", "azure_deployment_name", "azure_embedding_deployment_name", "azure_embedding_model_name"])
|
145 |
|
modules/models/ERNIE.py
ADDED
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from ..presets import *
|
2 |
+
from ..utils import *
|
3 |
+
|
4 |
+
from .base_model import BaseLLMModel
|
5 |
+
|
6 |
+
|
7 |
+
class ERNIE_Client(BaseLLMModel):
|
8 |
+
def __init__(self, model_name, api_key, secret_key) -> None:
|
9 |
+
super().__init__(model_name=model_name)
|
10 |
+
self.api_key = api_key
|
11 |
+
self.api_secret = secret_key
|
12 |
+
if None in [self.api_secret, self.api_key]:
|
13 |
+
raise Exception("请在配置文件或者环境变量中设置文心一言的API Key 和 Secret Key")
|
14 |
+
|
15 |
+
if self.model_name == "ERNIE-Bot-turbo":
|
16 |
+
self.ERNIE_url = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/eb-instant?access_token="
|
17 |
+
elif self.model_name == "ERNIE-Bot":
|
18 |
+
self.ERNIE_url = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions?access_token="
|
19 |
+
elif self.model_name == "ERNIE-Bot-4":
|
20 |
+
self.ERNIE_url = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions_pro?access_token="
|
21 |
+
|
22 |
+
def get_access_token(self):
|
23 |
+
"""
|
24 |
+
使用 AK,SK 生成鉴权签名(Access Token)
|
25 |
+
:return: access_token,或是None(如果错误)
|
26 |
+
"""
|
27 |
+
url = "https://aip.baidubce.com/oauth/2.0/token?client_id=" + self.api_key + "&client_secret=" + self.api_secret + "&grant_type=client_credentials"
|
28 |
+
|
29 |
+
payload = json.dumps("")
|
30 |
+
headers = {
|
31 |
+
'Content-Type': 'application/json',
|
32 |
+
'Accept': 'application/json'
|
33 |
+
}
|
34 |
+
|
35 |
+
response = requests.request("POST", url, headers=headers, data=payload)
|
36 |
+
|
37 |
+
return response.json()["access_token"]
|
38 |
+
def get_answer_stream_iter(self):
|
39 |
+
url = self.ERNIE_url + self.get_access_token()
|
40 |
+
system_prompt = self.system_prompt
|
41 |
+
history = self.history
|
42 |
+
if system_prompt is not None:
|
43 |
+
history = [construct_system(system_prompt), *history]
|
44 |
+
|
45 |
+
# 去除history中 history的role为system的
|
46 |
+
history = [i for i in history if i["role"] != "system"]
|
47 |
+
|
48 |
+
payload = json.dumps({
|
49 |
+
"messages":history,
|
50 |
+
"stream": True
|
51 |
+
})
|
52 |
+
headers = {
|
53 |
+
'Content-Type': 'application/json'
|
54 |
+
}
|
55 |
+
|
56 |
+
response = requests.request("POST", url, headers=headers, data=payload, stream=True)
|
57 |
+
|
58 |
+
if response.status_code == 200:
|
59 |
+
partial_text = ""
|
60 |
+
for line in response.iter_lines():
|
61 |
+
if len(line) == 0:
|
62 |
+
continue
|
63 |
+
line = json.loads(line[5:])
|
64 |
+
partial_text += line['result']
|
65 |
+
yield partial_text
|
66 |
+
else:
|
67 |
+
yield STANDARD_ERROR_MSG + GENERAL_ERROR_MSG
|
68 |
+
|
69 |
+
|
70 |
+
def get_answer_at_once(self):
|
71 |
+
url = self.ERNIE_url + self.get_access_token()
|
72 |
+
system_prompt = self.system_prompt
|
73 |
+
history = self.history
|
74 |
+
if system_prompt is not None:
|
75 |
+
history = [construct_system(system_prompt), *history]
|
76 |
+
|
77 |
+
# 去除history中 history的role为system的
|
78 |
+
history = [i for i in history if i["role"] != "system"]
|
79 |
+
|
80 |
+
payload = json.dumps({
|
81 |
+
"messages": history,
|
82 |
+
"stream": True
|
83 |
+
})
|
84 |
+
headers = {
|
85 |
+
'Content-Type': 'application/json'
|
86 |
+
}
|
87 |
+
|
88 |
+
response = requests.request("POST", url, headers=headers, data=payload, stream=True)
|
89 |
+
|
90 |
+
if response.status_code == 200:
|
91 |
+
|
92 |
+
return str(response.json()["result"]),len(response.json()["result"])
|
93 |
+
else:
|
94 |
+
return "获取资源错误", 0
|
95 |
+
|
96 |
+
|
modules/models/OpenAI.py
CHANGED
@@ -26,7 +26,7 @@ class OpenAIClient(BaseLLMModel):
|
|
26 |
user_name=""
|
27 |
) -> None:
|
28 |
super().__init__(
|
29 |
-
model_name=
|
30 |
temperature=temperature,
|
31 |
top_p=top_p,
|
32 |
system_prompt=system_prompt,
|
|
|
26 |
user_name=""
|
27 |
) -> None:
|
28 |
super().__init__(
|
29 |
+
model_name=model_name,
|
30 |
temperature=temperature,
|
31 |
top_p=top_p,
|
32 |
system_prompt=system_prompt,
|
modules/models/OpenAIVision.py
CHANGED
@@ -32,7 +32,7 @@ class OpenAIVisionClient(BaseLLMModel):
|
|
32 |
user_name=""
|
33 |
) -> None:
|
34 |
super().__init__(
|
35 |
-
model_name=
|
36 |
temperature=temperature,
|
37 |
top_p=top_p,
|
38 |
system_prompt=system_prompt,
|
|
|
32 |
user_name=""
|
33 |
) -> None:
|
34 |
super().__init__(
|
35 |
+
model_name=model_name,
|
36 |
temperature=temperature,
|
37 |
top_p=top_p,
|
38 |
system_prompt=system_prompt,
|
modules/models/__pycache__/OpenAI.cpython-311.pyc
ADDED
Binary file (14.6 kB). View file
|
|
modules/models/__pycache__/__init__.cpython-311.pyc
CHANGED
Binary files a/modules/models/__pycache__/__init__.cpython-311.pyc and b/modules/models/__pycache__/__init__.cpython-311.pyc differ
|
|
modules/models/__pycache__/base_model.cpython-311.pyc
CHANGED
Binary files a/modules/models/__pycache__/base_model.cpython-311.pyc and b/modules/models/__pycache__/base_model.cpython-311.pyc differ
|
|
modules/models/__pycache__/models.cpython-311.pyc
CHANGED
Binary files a/modules/models/__pycache__/models.cpython-311.pyc and b/modules/models/__pycache__/models.cpython-311.pyc differ
|
|
modules/models/base_model.py
CHANGED
@@ -78,7 +78,7 @@ def get_action_description(text):
|
|
78 |
action_name = json_dict['action']
|
79 |
action_input = json_dict['action_input']
|
80 |
if action_name != "Final Answer":
|
81 |
-
return f'<!-- S O PREFIX --><p class="agent-prefix">{action_name}: {action_input}\n
|
82 |
else:
|
83 |
return ""
|
84 |
|
@@ -148,6 +148,7 @@ class ModelType(Enum):
|
|
148 |
Claude = 14
|
149 |
Qwen = 15
|
150 |
OpenAIVision = 16
|
|
|
151 |
|
152 |
@classmethod
|
153 |
def get_type(cls, model_name: str):
|
@@ -188,6 +189,8 @@ class ModelType(Enum):
|
|
188 |
model_type = ModelType.Claude
|
189 |
elif "qwen" in model_name_lower:
|
190 |
model_type = ModelType.Qwen
|
|
|
|
|
191 |
else:
|
192 |
model_type = ModelType.LLaMA
|
193 |
return model_type
|
@@ -210,7 +213,10 @@ class BaseLLMModel:
|
|
210 |
) -> None:
|
211 |
self.history = []
|
212 |
self.all_token_counts = []
|
213 |
-
|
|
|
|
|
|
|
214 |
self.model_type = ModelType.get_type(model_name)
|
215 |
try:
|
216 |
self.token_upper_limit = MODEL_METADATA[model_name]["token_limit"]
|
|
|
78 |
action_name = json_dict['action']
|
79 |
action_input = json_dict['action_input']
|
80 |
if action_name != "Final Answer":
|
81 |
+
return f'<!-- S O PREFIX --><p class="agent-prefix">{action_name}: {action_input}\n</p><!-- E O PREFIX -->'
|
82 |
else:
|
83 |
return ""
|
84 |
|
|
|
148 |
Claude = 14
|
149 |
Qwen = 15
|
150 |
OpenAIVision = 16
|
151 |
+
ERNIE = 17
|
152 |
|
153 |
@classmethod
|
154 |
def get_type(cls, model_name: str):
|
|
|
189 |
model_type = ModelType.Claude
|
190 |
elif "qwen" in model_name_lower:
|
191 |
model_type = ModelType.Qwen
|
192 |
+
elif "ernie" in model_name_lower:
|
193 |
+
model_type = ModelType.ERNIE
|
194 |
else:
|
195 |
model_type = ModelType.LLaMA
|
196 |
return model_type
|
|
|
213 |
) -> None:
|
214 |
self.history = []
|
215 |
self.all_token_counts = []
|
216 |
+
if model_name in MODEL_METADATA:
|
217 |
+
self.model_name = MODEL_METADATA[model_name]["model_name"]
|
218 |
+
else:
|
219 |
+
self.model_name = model_name
|
220 |
self.model_type = ModelType.get_type(model_name)
|
221 |
try:
|
222 |
self.token_upper_limit = MODEL_METADATA[model_name]["token_limit"]
|
modules/models/models.py
CHANGED
@@ -128,6 +128,9 @@ def get_model(
|
|
128 |
elif model_type == ModelType.Qwen:
|
129 |
from .Qwen import Qwen_Client
|
130 |
model = Qwen_Client(model_name, user_name=user_name)
|
|
|
|
|
|
|
131 |
elif model_type == ModelType.Unknown:
|
132 |
raise ValueError(f"未知模型: {model_name}")
|
133 |
logging.info(msg)
|
|
|
128 |
elif model_type == ModelType.Qwen:
|
129 |
from .Qwen import Qwen_Client
|
130 |
model = Qwen_Client(model_name, user_name=user_name)
|
131 |
+
elif model_type == ModelType.ERNIE:
|
132 |
+
from .ERNIE import ERNIE_Client
|
133 |
+
model = ERNIE_Client(model_name, api_key=os.getenv("ERNIE_APIKEY"),secret_key=os.getenv("ERNIE_SECRETKEY"))
|
134 |
elif model_type == ModelType.Unknown:
|
135 |
raise ValueError(f"未知模型: {model_name}")
|
136 |
logging.info(msg)
|
modules/presets.py
CHANGED
@@ -56,6 +56,7 @@ ONLINE_MODELS = [
|
|
56 |
"GPT3.5 Turbo 16K",
|
57 |
"GPT3.5 Turbo 0301",
|
58 |
"GPT3.5 Turbo 0613",
|
|
|
59 |
"GPT4",
|
60 |
"GPT4 32K",
|
61 |
"GPT4 Turbo",
|
@@ -74,7 +75,10 @@ ONLINE_MODELS = [
|
|
74 |
"讯飞星火大模型V3.0",
|
75 |
"讯飞星火大模型V2.0",
|
76 |
"讯飞星火大模型V1.5",
|
77 |
-
"Claude"
|
|
|
|
|
|
|
78 |
]
|
79 |
|
80 |
LOCAL_MODELS = [
|
@@ -126,6 +130,10 @@ MODEL_METADATA = {
|
|
126 |
"model_name": "gpt-3.5-turbo-0613",
|
127 |
"token_limit": 4096,
|
128 |
},
|
|
|
|
|
|
|
|
|
129 |
"GPT4": {
|
130 |
"model_name": "gpt-4",
|
131 |
"token_limit": 8192,
|
@@ -146,6 +154,18 @@ MODEL_METADATA = {
|
|
146 |
"model_name": "Claude",
|
147 |
"token_limit": 4096,
|
148 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
}
|
150 |
|
151 |
if os.environ.get('HIDE_LOCAL_MODELS', 'false') == 'true':
|
|
|
56 |
"GPT3.5 Turbo 16K",
|
57 |
"GPT3.5 Turbo 0301",
|
58 |
"GPT3.5 Turbo 0613",
|
59 |
+
"GPT3.5 Turbo 1106",
|
60 |
"GPT4",
|
61 |
"GPT4 32K",
|
62 |
"GPT4 Turbo",
|
|
|
75 |
"讯飞星火大模型V3.0",
|
76 |
"讯飞星火大模型V2.0",
|
77 |
"讯飞星火大模型V1.5",
|
78 |
+
"Claude",
|
79 |
+
"ERNIE-Bot-turbo",
|
80 |
+
"ERNIE-Bot",
|
81 |
+
"ERNIE-Bot-4",
|
82 |
]
|
83 |
|
84 |
LOCAL_MODELS = [
|
|
|
130 |
"model_name": "gpt-3.5-turbo-0613",
|
131 |
"token_limit": 4096,
|
132 |
},
|
133 |
+
"GPT3.5 Turbo 1106": {
|
134 |
+
"model_name": "gpt-3.5-turbo-1106",
|
135 |
+
"token_limit": 16384,
|
136 |
+
},
|
137 |
"GPT4": {
|
138 |
"model_name": "gpt-4",
|
139 |
"token_limit": 8192,
|
|
|
154 |
"model_name": "Claude",
|
155 |
"token_limit": 4096,
|
156 |
},
|
157 |
+
"ERNIE-Bot-turbo": {
|
158 |
+
"model_name": "ERNIE-Bot-turbo",
|
159 |
+
"token_limit": 1024,
|
160 |
+
},
|
161 |
+
"ERNIE-Bot": {
|
162 |
+
"model_name": "ERNIE-Bot",
|
163 |
+
"token_limit": 1024,
|
164 |
+
},
|
165 |
+
"ERNIE-Bot-4": {
|
166 |
+
"model_name": "ERNIE-Bot-4",
|
167 |
+
"token_limit": 1024,
|
168 |
+
},
|
169 |
}
|
170 |
|
171 |
if os.environ.get('HIDE_LOCAL_MODELS', 'false') == 'true':
|
modules/utils.py
CHANGED
@@ -211,18 +211,16 @@ def clip_rawtext(chat_message, need_escape=True):
|
|
211 |
hr_match = re.search(hr_pattern, chat_message, re.DOTALL)
|
212 |
message_clipped = chat_message[:hr_match.start()] if hr_match else chat_message
|
213 |
# second, avoid agent-prefix being escaped
|
214 |
-
agent_prefix_pattern = r'<!-- S O PREFIX --><p class="agent-prefix"
|
215 |
-
agent_matches = re.findall(agent_prefix_pattern, message_clipped)
|
|
|
216 |
final_message = ""
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
final_message += f'<!-- S O PREFIX --><p class="agent-prefix">{part}</p><!-- E O PREFIX -->'
|
224 |
-
else:
|
225 |
-
final_message = escape_markdown(message_clipped) if need_escape else message_clipped
|
226 |
return final_message
|
227 |
|
228 |
|
@@ -233,7 +231,7 @@ def convert_bot_before_marked(chat_message):
|
|
233 |
if '<div class="md-message">' in chat_message:
|
234 |
return chat_message
|
235 |
else:
|
236 |
-
raw = f'<div class="raw-message hideM"
|
237 |
# really_raw = f'{START_OF_OUTPUT_MARK}<div class="really-raw hideM">{clip_rawtext(chat_message, need_escape=False)}\n</div>{END_OF_OUTPUT_MARK}'
|
238 |
|
239 |
code_block_pattern = re.compile(r"```(.*?)(?:```|$)", re.DOTALL)
|
@@ -661,6 +659,15 @@ def toggle_like_btn_visibility(selected_model_name):
|
|
661 |
else:
|
662 |
return gr.update(visible=False)
|
663 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
664 |
def new_auto_history_filename(username):
|
665 |
latest_file = get_first_history_name(username)
|
666 |
if latest_file:
|
|
|
211 |
hr_match = re.search(hr_pattern, chat_message, re.DOTALL)
|
212 |
message_clipped = chat_message[:hr_match.start()] if hr_match else chat_message
|
213 |
# second, avoid agent-prefix being escaped
|
214 |
+
agent_prefix_pattern = r'(<!-- S O PREFIX --><p class="agent-prefix">.*?<\/p><!-- E O PREFIX -->)'
|
215 |
+
# agent_matches = re.findall(agent_prefix_pattern, message_clipped)
|
216 |
+
agent_parts = re.split(agent_prefix_pattern, message_clipped, flags=re.DOTALL)
|
217 |
final_message = ""
|
218 |
+
for i, part in enumerate(agent_parts):
|
219 |
+
if i % 2 == 0:
|
220 |
+
if part != "" and part != "\n":
|
221 |
+
final_message += f'<pre class="fake-pre">{escape_markdown(part)}</pre>' if need_escape else f'<pre class="fake-pre">{part}</pre>'
|
222 |
+
else:
|
223 |
+
final_message += part
|
|
|
|
|
|
|
224 |
return final_message
|
225 |
|
226 |
|
|
|
231 |
if '<div class="md-message">' in chat_message:
|
232 |
return chat_message
|
233 |
else:
|
234 |
+
raw = f'<div class="raw-message hideM">{clip_rawtext(chat_message)}</div>'
|
235 |
# really_raw = f'{START_OF_OUTPUT_MARK}<div class="really-raw hideM">{clip_rawtext(chat_message, need_escape=False)}\n</div>{END_OF_OUTPUT_MARK}'
|
236 |
|
237 |
code_block_pattern = re.compile(r"```(.*?)(?:```|$)", re.DOTALL)
|
|
|
659 |
else:
|
660 |
return gr.update(visible=False)
|
661 |
|
662 |
+
def get_corresponding_file_type_by_model_name(selected_model_name):
|
663 |
+
if selected_model_name in ["xmchat", "GPT4 Vision"]:
|
664 |
+
return ["image"]
|
665 |
+
else:
|
666 |
+
return [".pdf", ".docx", ".pptx", ".epub", ".xlsx", ".txt", "text"]
|
667 |
+
|
668 |
+
# def toggle_file_type(selected_model_name):
|
669 |
+
# return gr.Files.update(file_types=get_corresponding_file_type_by_model_name(selected_model_name))
|
670 |
+
|
671 |
def new_auto_history_filename(username):
|
672 |
latest_file = get_first_history_name(username)
|
673 |
if latest_file:
|
requirements.txt
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
gradio==3.43.2
|
2 |
gradio_client==0.5.0
|
3 |
pypinyin
|
@@ -31,3 +32,4 @@ websocket_client
|
|
31 |
pydantic==1.10.8
|
32 |
google-search-results
|
33 |
anthropic==0.3.11
|
|
|
|
1 |
+
httpx==0.25.1
|
2 |
gradio==3.43.2
|
3 |
gradio_client==0.5.0
|
4 |
pypinyin
|
|
|
32 |
pydantic==1.10.8
|
33 |
google-search-results
|
34 |
anthropic==0.3.11
|
35 |
+
Pillow>=10.1.0
|
web_assets/.DS_Store
CHANGED
Binary files a/web_assets/.DS_Store and b/web_assets/.DS_Store differ
|
|
web_assets/javascript/message-button.js
CHANGED
@@ -95,7 +95,11 @@ function addChuanhuButton(botElement) {
|
|
95 |
function removeMarkdownText(message) {
|
96 |
var rawDiv = message.querySelector('.raw-message');
|
97 |
if (rawDiv) {
|
98 |
-
|
|
|
|
|
|
|
|
|
99 |
rawDiv.classList.remove('hideM');
|
100 |
}
|
101 |
var mdDiv = message.querySelector('.md-message');
|
|
|
95 |
function removeMarkdownText(message) {
|
96 |
var rawDiv = message.querySelector('.raw-message');
|
97 |
if (rawDiv) {
|
98 |
+
// 判断pre是否存在fake-pre类,如果不存在,则为20231118之前的历史记录格式,需要转换,增加fake-pre类用于适配
|
99 |
+
if (!rawDiv.querySelector('pre')?.classList.contains('fake-pre')) {
|
100 |
+
rawDiv.innerHTML = rawDiv.innerHTML.replace(/<pre>/g, '<pre class="fake-pre">');
|
101 |
+
}
|
102 |
+
// rawDiv.innerHTML = rawDiv.querySelector('pre')?.innerHTML || rawDiv.innerHTML;
|
103 |
rawDiv.classList.remove('hideM');
|
104 |
}
|
105 |
var mdDiv = message.querySelector('.md-message');
|
web_assets/javascript/updater.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
|
2 |
var updateInfoGotten = false;
|
3 |
-
var isLatestVersion = localStorage.getItem('isLatestVersion') || false;
|
|
|
4 |
|
5 |
function setUpdater() {
|
6 |
const enableCheckUpdate = gradioApp().querySelector('#enableCheckUpdate_config').innerText;
|
@@ -10,11 +11,15 @@ function setUpdater() {
|
|
10 |
return;
|
11 |
}
|
12 |
|
|
|
|
|
|
|
13 |
const lastCheckTime = localStorage.getItem('lastCheckTime') || 0;
|
|
|
14 |
const longTimeNoCheck = currentTime - lastCheckTime > 3 * 24 * 60 * 60 * 1000;
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
}
|
19 |
|
20 |
var statusObserver = new MutationObserver(function (mutationsList) {
|
@@ -26,6 +31,7 @@ var statusObserver = new MutationObserver(function (mutationsList) {
|
|
26 |
noUpdateHtml();
|
27 |
localStorage.setItem('isLatestVersion', 'true');
|
28 |
isLatestVersion = true;
|
|
|
29 |
enableUpdateBtns();
|
30 |
} else if (getUpdateStatus() === "failure") {
|
31 |
updatingInfoElement.innerHTML = marked.parse(updateFailure_i18n, {mangle: false, headerIds: false});
|
@@ -86,11 +92,16 @@ async function updateLatestVersion() {
|
|
86 |
if (currentVersion) {
|
87 |
if (latestVersion <= currentVersion) {
|
88 |
noUpdate();
|
|
|
|
|
|
|
89 |
} else {
|
90 |
latestVersionElement.textContent = latestVersion;
|
91 |
console.log(`New version ${latestVersion} found!`);
|
92 |
if (!isInIframe) openUpdateToast();
|
93 |
gradioApp().classList.add('is-outdated');
|
|
|
|
|
94 |
}
|
95 |
enableUpdateBtns();
|
96 |
} else { //如果当前版本号获取失败,使用时间比较
|
@@ -119,6 +130,8 @@ async function updateLatestVersion() {
|
|
119 |
noUpdate("Local version check failed, it seems to be a local rivision. <br>But your revision is newer than the latest release.");
|
120 |
gradioApp().classList.add('is-outdated');
|
121 |
enableUpdateBtns()
|
|
|
|
|
122 |
}
|
123 |
}
|
124 |
}
|
|
|
1 |
|
2 |
var updateInfoGotten = false;
|
3 |
+
var isLatestVersion = localStorage.getItem('isLatestVersion') === "true" || false;
|
4 |
+
var shouldCheckUpdate = false;
|
5 |
|
6 |
function setUpdater() {
|
7 |
const enableCheckUpdate = gradioApp().querySelector('#enableCheckUpdate_config').innerText;
|
|
|
11 |
return;
|
12 |
}
|
13 |
|
14 |
+
if (!isLatestVersion) {
|
15 |
+
gradioApp().classList.add('is-outdated');
|
16 |
+
}
|
17 |
const lastCheckTime = localStorage.getItem('lastCheckTime') || 0;
|
18 |
+
currentTime = new Date().getTime();
|
19 |
const longTimeNoCheck = currentTime - lastCheckTime > 3 * 24 * 60 * 60 * 1000;
|
20 |
+
shouldCheckUpdate = !updateInfoGotten && (!isLatestVersion && longTimeNoCheck || isLatestVersion);
|
21 |
+
// console.log(`shouldCheckUpdate`, shouldCheckUpdate);
|
22 |
+
if (shouldCheckUpdate) updateLatestVersion();
|
23 |
}
|
24 |
|
25 |
var statusObserver = new MutationObserver(function (mutationsList) {
|
|
|
31 |
noUpdateHtml();
|
32 |
localStorage.setItem('isLatestVersion', 'true');
|
33 |
isLatestVersion = true;
|
34 |
+
gradioApp().classList.remove('is-outdated');
|
35 |
enableUpdateBtns();
|
36 |
} else if (getUpdateStatus() === "failure") {
|
37 |
updatingInfoElement.innerHTML = marked.parse(updateFailure_i18n, {mangle: false, headerIds: false});
|
|
|
92 |
if (currentVersion) {
|
93 |
if (latestVersion <= currentVersion) {
|
94 |
noUpdate();
|
95 |
+
localStorage.setItem('isLatestVersion', 'true');
|
96 |
+
isLatestVersion = true;
|
97 |
+
gradioApp().classList.remove('is-outdated');
|
98 |
} else {
|
99 |
latestVersionElement.textContent = latestVersion;
|
100 |
console.log(`New version ${latestVersion} found!`);
|
101 |
if (!isInIframe) openUpdateToast();
|
102 |
gradioApp().classList.add('is-outdated');
|
103 |
+
localStorage.setItem('isLatestVersion', 'false');
|
104 |
+
isLatestVersion = false;
|
105 |
}
|
106 |
enableUpdateBtns();
|
107 |
} else { //如果当前版本号获取失败,使用时间比较
|
|
|
130 |
noUpdate("Local version check failed, it seems to be a local rivision. <br>But your revision is newer than the latest release.");
|
131 |
gradioApp().classList.add('is-outdated');
|
132 |
enableUpdateBtns()
|
133 |
+
localStorage.setItem('isLatestVersion', 'false');
|
134 |
+
isLatestVersion = false;
|
135 |
}
|
136 |
}
|
137 |
}
|
web_assets/javascript/webui.js
CHANGED
@@ -39,11 +39,15 @@ function showMask(obj) {
|
|
39 |
chatbotArea.querySelector('#chatbot-input-more-area').parentNode.appendChild(mask);
|
40 |
} else if (obj == "update-toast") {
|
41 |
mask.classList.add('chuanhu-top-mask');
|
|
|
|
|
|
|
|
|
|
|
42 |
document.body.appendChild(mask);
|
43 |
// mask.classList.add('transparent-mask');
|
44 |
}
|
45 |
|
46 |
-
|
47 |
|
48 |
mask.addEventListener('click', () => {
|
49 |
if (obj == "box") {
|
|
|
39 |
chatbotArea.querySelector('#chatbot-input-more-area').parentNode.appendChild(mask);
|
40 |
} else if (obj == "update-toast") {
|
41 |
mask.classList.add('chuanhu-top-mask');
|
42 |
+
if (document.querySelector('.chuanhu-top-mask')) {
|
43 |
+
for (var i = 0; i < document.querySelectorAll('.chuanhu-top-mask').length; i++) {
|
44 |
+
document.querySelectorAll('.chuanhu-top-mask')[i].remove();
|
45 |
+
}
|
46 |
+
}
|
47 |
document.body.appendChild(mask);
|
48 |
// mask.classList.add('transparent-mask');
|
49 |
}
|
50 |
|
|
|
51 |
|
52 |
mask.addEventListener('click', () => {
|
53 |
if (obj == "box") {
|
web_assets/stylesheet/ChuanhuChat.css
CHANGED
@@ -60,6 +60,7 @@ body.popup-open {
|
|
60 |
flex-direction: row;
|
61 |
display: inline-flex;
|
62 |
align-items: center;
|
|
|
63 |
}
|
64 |
#description {
|
65 |
text-align: center;
|
@@ -123,12 +124,25 @@ body.popup-open {
|
|
123 |
}
|
124 |
|
125 |
/* status-display */
|
126 |
-
#status-display {
|
127 |
display: flex;
|
128 |
min-height: 2em;
|
129 |
align-items: flex-end;
|
130 |
justify-content: flex-end;
|
131 |
transition: all 0.6s;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
}
|
133 |
#status-display p {
|
134 |
font-size: .85em;
|
|
|
60 |
flex-direction: row;
|
61 |
display: inline-flex;
|
62 |
align-items: center;
|
63 |
+
position: absolute;
|
64 |
}
|
65 |
#description {
|
66 |
text-align: center;
|
|
|
124 |
}
|
125 |
|
126 |
/* status-display */
|
127 |
+
#chuanhu-header > #status-display {
|
128 |
display: flex;
|
129 |
min-height: 2em;
|
130 |
align-items: flex-end;
|
131 |
justify-content: flex-end;
|
132 |
transition: all 0.6s;
|
133 |
+
max-width: 50%;
|
134 |
+
height: 100%;
|
135 |
+
bottom: 0;
|
136 |
+
position: absolute;
|
137 |
+
|
138 |
+
@media screen and (max-width: 639px) {
|
139 |
+
right: 16px;
|
140 |
+
right: max(16px, env(safe-area-inset-right));
|
141 |
+
}
|
142 |
+
@media screen and (min-width: 640px) {
|
143 |
+
right: 24px;
|
144 |
+
right: max(24px, env(safe-area-inset-right));
|
145 |
+
}
|
146 |
}
|
147 |
#status-display p {
|
148 |
font-size: .85em;
|
web_assets/stylesheet/chatbot.css
CHANGED
@@ -42,7 +42,13 @@ hr.append-display {
|
|
42 |
.agent-prefix {
|
43 |
font-size: smaller;
|
44 |
opacity: 0.6;
|
45 |
-
padding: 6px 0
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
}
|
47 |
.agent-prefix::before {
|
48 |
content: '🐯';
|
@@ -216,6 +222,14 @@ hr.append-display {
|
|
216 |
.message .raw-message p {
|
217 |
margin:0 !important;
|
218 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
.message .raw-message {
|
220 |
display: block;
|
221 |
padding: 0 !important;
|
|
|
42 |
.agent-prefix {
|
43 |
font-size: smaller;
|
44 |
opacity: 0.6;
|
45 |
+
padding: 6px 0 12px;
|
46 |
+
}
|
47 |
+
.raw-message p.agent-prefix + p.agent-prefix {
|
48 |
+
margin-top: -1.2em !important;
|
49 |
+
}
|
50 |
+
.md-message p.agent-prefix + p.agent-prefix {
|
51 |
+
margin-top: -1.8em !important;
|
52 |
}
|
53 |
.agent-prefix::before {
|
54 |
content: '🐯';
|
|
|
222 |
.message .raw-message p {
|
223 |
margin:0 !important;
|
224 |
}
|
225 |
+
.message .raw-message pre.fake-pre {
|
226 |
+
background: unset;
|
227 |
+
margin: unset;
|
228 |
+
font-size: unset;
|
229 |
+
/* font-family: unset; */
|
230 |
+
padding: unset;
|
231 |
+
white-space: inherit;
|
232 |
+
}
|
233 |
.message .raw-message {
|
234 |
display: block;
|
235 |
padding: 0 !important;
|