Spaces:
Sleeping
Sleeping
MZhao
commited on
update markdown parse
Browse files- ChuanhuChatbot.py +18 -2
ChuanhuChatbot.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import openai
|
3 |
-
import markdown
|
4 |
|
5 |
|
6 |
我的API密钥 = "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # 在这里输入你的 API 密钥
|
@@ -8,6 +8,22 @@ initial_prompt = "You are a helpful assistant."
|
|
8 |
|
9 |
openai.api_key = 我的API密钥
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
def get_response(system, context, raw = False):
|
12 |
response = openai.ChatCompletion.create(
|
13 |
model="gpt-3.5-turbo",
|
@@ -20,7 +36,7 @@ def get_response(system, context, raw = False):
|
|
20 |
message = response["choices"][0]["message"]["content"]
|
21 |
|
22 |
message_with_stats = f'{message}\n\n================\n\n{statistics}'
|
23 |
-
|
24 |
|
25 |
return message, message_with_stats
|
26 |
|
|
|
1 |
import gradio as gr
|
2 |
import openai
|
3 |
+
# import markdown
|
4 |
|
5 |
|
6 |
我的API密钥 = "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # 在这里输入你的 API 密钥
|
|
|
8 |
|
9 |
openai.api_key = 我的API密钥
|
10 |
|
11 |
+
def parse_text(text):
|
12 |
+
lines = text.split("\n")
|
13 |
+
for i,line in enumerate(lines):
|
14 |
+
if "```" in line:
|
15 |
+
items = line.split('`')
|
16 |
+
if items[-1]:
|
17 |
+
lines[i] = f'<pre><code class="{items[-1]}">'
|
18 |
+
else:
|
19 |
+
lines[i] = f'</code></pre>'
|
20 |
+
else:
|
21 |
+
if i>0:
|
22 |
+
line = line.replace("<", "<")
|
23 |
+
line = line.replace(">", ">")
|
24 |
+
lines[i] = '<br/>'+line.replace(" ", " ")
|
25 |
+
return "".join(lines)
|
26 |
+
|
27 |
def get_response(system, context, raw = False):
|
28 |
response = openai.ChatCompletion.create(
|
29 |
model="gpt-3.5-turbo",
|
|
|
36 |
message = response["choices"][0]["message"]["content"]
|
37 |
|
38 |
message_with_stats = f'{message}\n\n================\n\n{statistics}'
|
39 |
+
# message_with_stats = markdown.markdown(message_with_stats)
|
40 |
|
41 |
return message, message_with_stats
|
42 |
|