simondby
commited on
Commit
·
1bf1eba
1
Parent(s):
c38b1a2
update
Browse files- app.py +9 -4
- styles.css +6 -1
app.py
CHANGED
@@ -24,7 +24,7 @@ TEMPLATES_DIR = "templates"
|
|
24 |
def gen_sys_prompt():
|
25 |
tz = pytz.timezone('Asia/Shanghai')
|
26 |
now = datetime.datetime.now(tz)
|
27 |
-
timestamp = now.strftime("%Y年%m月%d日 %H:%M
|
28 |
sys_prompt = f"""你的目的是如实解答用户问题,对于不知道的问题,你需要回复你不知道。
|
29 |
现在是{timestamp},有些信息可能已经过时。
|
30 |
表格的效果展示直接以HTML格式输出而非markdown格式。"""
|
@@ -163,7 +163,7 @@ def parse_text(text):
|
|
163 |
lines[i] = f'</code></pre>'
|
164 |
in_code_block = False
|
165 |
|
166 |
-
#
|
167 |
elif in_code_block:
|
168 |
line = line.replace("&", "&")
|
169 |
# line = line.replace("\"", "`\"`")
|
@@ -181,11 +181,16 @@ def parse_text(text):
|
|
181 |
line = line.replace(")", ")")
|
182 |
lines[i] = line + "<br>"
|
183 |
|
|
|
|
|
|
|
|
|
|
|
184 |
text = "".join(lines)
|
|
|
185 |
return text
|
186 |
|
187 |
|
188 |
-
|
189 |
# 请求API
|
190 |
def openai_request(inputs, top_p, temperature, max_tokens, user_key, session_id, chat_id, chatbot=[], history=[], system_prompt=gen_sys_prompt, regenerate=False, summary=False): # repetition_penalty, top_k
|
191 |
|
@@ -456,7 +461,7 @@ with gr.Blocks(css=css_styles,title="Chatbot🚀"
|
|
456 |
# api key
|
457 |
with gr.Accordion(label="API Key(帮助节省额度)", open=False):
|
458 |
apiKey = gr.Textbox(show_label=True, placeholder=f"使用自己的OpenAI API key",
|
459 |
-
value='sk-
|
460 |
|
461 |
# sys prompt
|
462 |
promptSystem = gr.Textbox(lines=2,show_label=True, placeholder=f"在这里输入System Prompt...",
|
|
|
24 |
def gen_sys_prompt():
|
25 |
tz = pytz.timezone('Asia/Shanghai')
|
26 |
now = datetime.datetime.now(tz)
|
27 |
+
timestamp = now.strftime("%Y年%m月%d日 %H:%M")
|
28 |
sys_prompt = f"""你的目的是如实解答用户问题,对于不知道的问题,你需要回复你不知道。
|
29 |
现在是{timestamp},有些信息可能已经过时。
|
30 |
表格的效果展示直接以HTML格式输出而非markdown格式。"""
|
|
|
163 |
lines[i] = f'</code></pre>'
|
164 |
in_code_block = False
|
165 |
|
166 |
+
# code block content
|
167 |
elif in_code_block:
|
168 |
line = line.replace("&", "&")
|
169 |
# line = line.replace("\"", "`\"`")
|
|
|
181 |
line = line.replace(")", ")")
|
182 |
lines[i] = line + "<br>"
|
183 |
|
184 |
+
# normal text
|
185 |
+
else:
|
186 |
+
line += "\n"
|
187 |
+
# print(f"line: {line}")
|
188 |
+
# print(f"lines: {lines}")
|
189 |
text = "".join(lines)
|
190 |
+
text = re.sub(r'<br>+<br>', '<br>', text)
|
191 |
return text
|
192 |
|
193 |
|
|
|
194 |
# 请求API
|
195 |
def openai_request(inputs, top_p, temperature, max_tokens, user_key, session_id, chat_id, chatbot=[], history=[], system_prompt=gen_sys_prompt, regenerate=False, summary=False): # repetition_penalty, top_k
|
196 |
|
|
|
461 |
# api key
|
462 |
with gr.Accordion(label="API Key(帮助节省额度)", open=False):
|
463 |
apiKey = gr.Textbox(show_label=True, placeholder=f"使用自己的OpenAI API key",
|
464 |
+
value='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', label="默认的API额度可能很快用完,你可以使用自己的API Key,以帮忙节省额度。", type="password", visible=True).style(container=True)
|
465 |
|
466 |
# sys prompt
|
467 |
promptSystem = gr.Textbox(lines=2,show_label=True, placeholder=f"在这里输入System Prompt...",
|
styles.css
CHANGED
@@ -7,6 +7,10 @@
|
|
7 |
#ids{visibility: hidden;}
|
8 |
footer {visibility: hidden;}
|
9 |
|
|
|
|
|
|
|
|
|
10 |
/* 表格 */
|
11 |
table {
|
12 |
margin: 1em 0;
|
@@ -41,7 +45,8 @@ code {
|
|
41 |
/* 代码块 */
|
42 |
pre code {
|
43 |
display: block;
|
44 |
-
white-space: pre;
|
|
|
45 |
background-color: hsla(0, 0%, 0%, 80%)!important;
|
46 |
border-radius: 10px;
|
47 |
padding: 1rem 1.2rem 1rem;
|
|
|
7 |
#ids{visibility: hidden;}
|
8 |
footer {visibility: hidden;}
|
9 |
|
10 |
+
.message {
|
11 |
+
white-space: pre-line !important;
|
12 |
+
}
|
13 |
+
|
14 |
/* 表格 */
|
15 |
table {
|
16 |
margin: 1em 0;
|
|
|
45 |
/* 代码块 */
|
46 |
pre code {
|
47 |
display: block;
|
48 |
+
white-space: pre-wrap;
|
49 |
+
word-wrap: break-word;
|
50 |
background-color: hsla(0, 0%, 0%, 80%)!important;
|
51 |
border-radius: 10px;
|
52 |
padding: 1rem 1.2rem 1rem;
|