25/09/24 10:00~11:30 停机维护

This commit is contained in:
Cai
2025-09-24 18:12:45 +08:00
parent 07cf2363ab
commit 3ad36c29ed
13 changed files with 2997 additions and 224 deletions

View File

@@ -2,6 +2,7 @@ import signal
import sys
import os
import time
import re
import uuid
current_directory = os.path.dirname(os.path.abspath(__file__))
sys.path.append(current_directory)
@@ -70,6 +71,12 @@ class ChatManager:
print("ERROR: disconnect",e)
print("disconnect success stop code-server success")
def load_code_in_markdown(self):
nowchapter_content = self.chapter_chain[self.chapter_chain_now].chapter
code_texts = extract_code_blocks(nowchapter_content)
for code_text in code_texts:
self.vscode_ws.emit('code-file', {'type':'create', 'data':code_text, 'chapter_title': self.chapter_chain[self.chapter_chain_now].title}, room=self.user_uuid ,namespace='/vscode')
def next_chapter(self):
assert self.chapter_chain_now + 1 < len(self.chapter_chain), "chapter_chain_now out of range"
@@ -85,6 +92,7 @@ class ChatManager:
def load_next_chapter(self):
print(f"now load next chapter markdown {self.chapter_chain_now}")
self.ase_client.loadmarkdown(self.chapter_chain[self.chapter_chain_now].chapter, self.chapter_chain[self.chapter_chain_now].chapter_prompt, self.chapter_chain[self.chapter_chain_now].score_prompt)
self.load_code_in_markdown()
def upload_bb(self):
@@ -278,4 +286,21 @@ class ChatManager:
for k in keys:
self.stop(k)
def extract_code_blocks(text):
"""
从文本中提取所有用```标记的代码段(包括标记本身)
参数:
text: 包含代码段的原始文本
返回:
提取到的代码段列表,每个元素是一个完整的代码块(包括```标记)
"""
# 正则表达式匹配```开始和结束的代码块
# 考虑可能的语言指定(如```python
pattern = r'```.*?```'
# 使用DOTALL模式让.匹配包括换行符在内的所有字符
code_blocks = re.findall(pattern, text, re.DOTALL)
return code_blocks