Spaces:
Sleeping
Sleeping
Tuchuanhuhuhu
commited on
Commit
·
b8b193d
1
Parent(s):
5dc3671
解决生成大量</br>标签的问题
Browse files- ChuanhuChatbot.py +9 -7
ChuanhuChatbot.py
CHANGED
|
@@ -38,6 +38,7 @@ if dockerflag:
|
|
| 38 |
|
| 39 |
def parse_text(text):
|
| 40 |
lines = text.split("\n")
|
|
|
|
| 41 |
count = 0
|
| 42 |
for i, line in enumerate(lines):
|
| 43 |
if "```" in line:
|
|
@@ -52,19 +53,20 @@ def parse_text(text):
|
|
| 52 |
if count % 2 == 1:
|
| 53 |
line = line.replace("&", "&")
|
| 54 |
line = line.replace("\"", """)
|
|
|
|
| 55 |
line = line.replace("\'", "'")
|
|
|
|
| 56 |
line = line.replace("<", "<")
|
| 57 |
line = line.replace(">", ">")
|
| 58 |
line = line.replace(" ", " ")
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
else:
|
| 63 |
-
lines[i] = line
|
| 64 |
-
return "".join(lines)
|
| 65 |
|
| 66 |
def predict(inputs, top_p, temperature, openai_api_key, chatbot=[], history=[], system_prompt=initial_prompt, retry=False, summary=False): # repetition_penalty, top_k
|
| 67 |
|
|
|
|
|
|
|
| 68 |
headers = {
|
| 69 |
"Content-Type": "application/json",
|
| 70 |
"Authorization": f"Bearer {openai_api_key}"
|
|
@@ -138,7 +140,7 @@ def predict(inputs, top_p, temperature, openai_api_key, chatbot=[], history=[],
|
|
| 138 |
break
|
| 139 |
except Exception as e:
|
| 140 |
chatbot.pop()
|
| 141 |
-
chatbot.append((history[-1], f"
|
| 142 |
history.pop()
|
| 143 |
yield chatbot, history
|
| 144 |
break
|
|
|
|
| 38 |
|
| 39 |
def parse_text(text):
|
| 40 |
lines = text.split("\n")
|
| 41 |
+
lines = [line for line in lines if line != ""]
|
| 42 |
count = 0
|
| 43 |
for i, line in enumerate(lines):
|
| 44 |
if "```" in line:
|
|
|
|
| 53 |
if count % 2 == 1:
|
| 54 |
line = line.replace("&", "&")
|
| 55 |
line = line.replace("\"", """)
|
| 56 |
+
# line = line.replace("\"", """)
|
| 57 |
line = line.replace("\'", "'")
|
| 58 |
+
# line = line.replace("\'", "'")
|
| 59 |
line = line.replace("<", "<")
|
| 60 |
line = line.replace(">", ">")
|
| 61 |
line = line.replace(" ", " ")
|
| 62 |
+
lines[i] = '<br>'+line
|
| 63 |
+
return "".join(lines).replace("<br>\n", "<br>")
|
| 64 |
+
# text = "</br>".join([ i for i in "".join(lines).split("<br/>") if i != ""])
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
def predict(inputs, top_p, temperature, openai_api_key, chatbot=[], history=[], system_prompt=initial_prompt, retry=False, summary=False): # repetition_penalty, top_k
|
| 67 |
|
| 68 |
+
print(f"chatbot 1: {chatbot}")
|
| 69 |
+
|
| 70 |
headers = {
|
| 71 |
"Content-Type": "application/json",
|
| 72 |
"Authorization": f"Bearer {openai_api_key}"
|
|
|
|
| 140 |
break
|
| 141 |
except Exception as e:
|
| 142 |
chatbot.pop()
|
| 143 |
+
chatbot.append((history[-1], f"☹️发生了错误<br>返回值:{response.text}<br>异常:{e}"))
|
| 144 |
history.pop()
|
| 145 |
yield chatbot, history
|
| 146 |
break
|