mirror of
https://github.com/Xueheng-Li/SynologyChatbotGPT.git
synced 2025-07-22 01:23:00 +00:00
update
This commit is contained in:
43
my_module.py
43
my_module.py
@ -677,30 +677,31 @@ class ChatBot:
|
|||||||
# print(r.choices[0]["delta"])
|
# print(r.choices[0]["delta"])
|
||||||
if "content" in r.choices[0]["delta"]:
|
if "content" in r.choices[0]["delta"]:
|
||||||
word = r.choices[0]["delta"]["content"]
|
word = r.choices[0]["delta"]["content"]
|
||||||
text.append(word)
|
if word is not None:
|
||||||
whole_text.append(word)
|
text.append(word)
|
||||||
|
whole_text.append(word)
|
||||||
|
|
||||||
# Check if the current output ends with \n
|
# Check if the current output ends with \n
|
||||||
if re.search(r'[\n]', word[-1]):
|
if re.search(r'[\n]', word[-1]):
|
||||||
sentence = ''.join(text).strip()
|
sentence = ''.join(text).strip()
|
||||||
|
|
||||||
if re.search(r'`{3}$', sentence) and code_block:
|
if re.search(r'`{3}$', sentence) and code_block:
|
||||||
# print("code: " , code_block , ", sentence: " + sentence)
|
# print("code: " , code_block , ", sentence: " + sentence)
|
||||||
send_back_message(self.user_id, sentence)
|
send_back_message(self.user_id, sentence)
|
||||||
text = []
|
|
||||||
code_block = False
|
|
||||||
else:
|
|
||||||
if re.search(r'`{3}', sentence) and not code_block:
|
|
||||||
code_block = True
|
|
||||||
if re.search(r'\n', sentence):
|
|
||||||
sentences = text.split("\n")
|
|
||||||
send_back_message(self.user_id, sentences[0])
|
|
||||||
sentence = sentences[1]
|
|
||||||
|
|
||||||
if not code_block:
|
|
||||||
sentence = sentence.replace("\n", "")
|
|
||||||
send_stream(self.user_id, sentence)
|
|
||||||
text = []
|
text = []
|
||||||
|
code_block = False
|
||||||
|
else:
|
||||||
|
if re.search(r'`{3}', sentence) and not code_block:
|
||||||
|
code_block = True
|
||||||
|
if re.search(r'\n', sentence):
|
||||||
|
sentences = text.split("\n")
|
||||||
|
send_back_message(self.user_id, sentences[0])
|
||||||
|
sentence = sentences[1]
|
||||||
|
|
||||||
|
if not code_block:
|
||||||
|
sentence = sentence.replace("\n", "")
|
||||||
|
send_stream(self.user_id, sentence)
|
||||||
|
text = []
|
||||||
text = ''.join(text)
|
text = ''.join(text)
|
||||||
if len(text) > 0:
|
if len(text) > 0:
|
||||||
send(self.user_id, text, stream=self.stream)
|
send(self.user_id, text, stream=self.stream)
|
||||||
|
Reference in New Issue
Block a user