gitignore

This commit is contained in:
CakeCN
2024-12-04 23:24:09 +08:00
parent 4198ca63b1
commit 202b8ea4e2
229 changed files with 1 additions and 11180 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
Html/runs/*

View File

@@ -1,7 +0,0 @@
{
"project": "CCpiuC",
"name": "2h3jhw",
"run_id": "run_20241114-163533_2h3jhw",
"timestamp": "2024-11-14 16:35:33",
"pid": 24464
}

View File

@@ -1,171 +0,0 @@
from flask import Flask, session, request, jsonify, render_template, send_from_directory
from flask_cors import CORS
from flask_socketio import SocketIO, join_room, emit
import markdown
import os
import uuid
import shutil
import sys
import json
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(0, parent_dir)
from AlgoriAgent.projects.algoriAgent.agent_manager import AgentManager
app = Flask(__name__)
app.secret_key = 'cakebaker'
# 配置 CORS
CORS(app, resources={r"/*": {"origins": "http://localhost:9888"}}, supports_credentials=True)
'''
Backboard
'''
class Backboard:
pass
@app.route('/backboard')
def backboard():
return jsonify({'status': 'success'})
'''
Agent and Chat
'''
socketio = SocketIO(app, cors_allowed_origins="*")
agent_manager = AgentManager()
def realtime_response(config, realtime_action):
print("config"+str(config))
print("realtime_action"+str(realtime_action))
pass
@socketio.on('connect')
def handle_connect():
user_id = session.get('user_id')
if (user_id is None):
print("No user_id in session")
return jsonify({'error': 'Connection failed bacause no user_id found'}), 401
print(f'User connected with session user_id: {user_id}')
id, agent = agent_manager.get_agent(user_id)
if user_id:
join_room(user_id) # 将该用户加入以user_id为名的room
# 当接收到前端的消息时,触发此事件
@socketio.on('send_message')
def handle_message(data):
print(f"Message from client: {data}")
id = session.get('user_id')
# 构造回复消息
res = agent_manager.invoke(id, data)
reply = f"AI: {res.content['speak']}"
# 将回复发送回前端
emit('receive_message', reply)
'''
Markdown to HTML
'''
# 配置文件路径
MARKDOWN_DIR = 'books/markdown' # 存放 markdown 文件的文件夹
STATIC_DIR = 'static' # 存放生成的 HTML 和图片资源的文件夹
IMAGE_DIR = 'image' # 图片资源相对于 markdown 的位置
@app.route('/<filename>-markdown', methods=['GET'])
def convert_md(filename):
md_file_path = os.path.join(MARKDOWN_DIR, f'{filename}.md')
if not os.path.exists(md_file_path):
return jsonify({'error': 'Markdown file not found'}), 404
# 读取 markdown 文件内容
with open(md_file_path, 'r', encoding='utf-8') as file:
md_content = file.read()
# 将 markdown 转换为 HTML
html_content = markdown.markdown(md_content)
# 插入 CSS 样式,限制图片最大宽度为 100%,高度自动调整
html_with_styles = f"""
<html>
<head>
<style>
img {{
max-width: 100%;
height: auto;
}}
</style>
</head>
<body>
{html_content}
</body>
</html>
"""
# 保存 HTML 文件到 static 文件夹
html_output_path = os.path.join(STATIC_DIR, f'{filename}.html')
with open(html_output_path, 'w', encoding='utf-8') as html_file:
html_file.write(html_with_styles)
# 处理图片资源,将 image/xxx 文件夹拷贝到 static/image/xxx
image_source_dir = os.path.join(MARKDOWN_DIR, IMAGE_DIR, filename)
image_target_dir = os.path.join(STATIC_DIR, IMAGE_DIR, filename)
print(f"Copying image resources from {image_source_dir} to {image_target_dir}")
if os.path.exists(image_source_dir):
# 确保 static/image/xxx 目录存在
if not os.path.exists(image_target_dir):
os.makedirs(image_target_dir)
# 拷贝图片资源
for image_file in os.listdir(image_source_dir):
full_image_file_path = os.path.join(image_source_dir, image_file)
if os.path.isfile(full_image_file_path):
shutil.copy(full_image_file_path, image_target_dir)
return jsonify({'html_url': f'/static/{filename}.html'})
# 静态文件HTML 和图片资源)的访问
@app.route('/static/<path:filename>')
def serve_static(filename):
return send_from_directory(STATIC_DIR, filename)
'''
Vscode
'''
@app.route('/desktop/<user_id>/<path>')
def hello_world(user_id, path):
print("session"+str(session))
if 'user_id' not in session:
session['user_id'] = 'user_' + str(uuid.uuid4())
# 在上层 目录下创建一个名为 user_id_path 的文件夹
path_dir = os.path.join(parent_dir, user_id, path)
os.makedirs(path_dir, exist_ok=True)
# 在此文件夹内部创建一个.config文件并写入 user_id=user_id\n path=path
config_path = os.path.join(path_dir, '.config')
with open(config_path, 'w') as f:
f.write(f"user_id={user_id}\npath={path}")
return render_template('index.html', user_id=user_id, path=path)
@app.route('/vscode_data', methods=['POST'])
def vscode_data():
data = request.json
config = data['config']
realtime_response(config,data)
print(f"Received data from VSCode: {data}")
return jsonify({"status": "success", "received": data})
@app.route('/get_session')
def get_session():
user_session = session.get('user_id', 'default_session')
return jsonify({"session": user_session})
if __name__ == '__main__':
socketio.run(app, host='0.0.0.0', port=5500)

View File

@@ -1,51 +0,0 @@
import time
class BackBoardManager:
def __init__(self):
self.backboards = {} # user_id: Backboard
def add_backboard(self, user_id, folder):
self.backboards[user_id] = Backboard(user_id, folder)
def get_backboard(self, user_id):
if user_id not in self.backboards:
return None
return self.backboards[user_id]
class Backboard:
def __init__(self, user_id, folder):
self.user_id = user_id
self.folder = folder
self.create_time = time.time()
self.enter_chapter_time = time.time()
def next_chapter(self):
self.enter_chapter_time = time.time()
def get_info_prompt(self):
return f"###Global Info:###\n\
User is {self.user_id}\n\
User's total study time is {self.get_deltatime_mmss(self.create_time, time.time())}\n\
User's current chapter study time is {self.get_deltatime_mmss(self.enter_chapter_time, time.time())}\n\
\n\n\
"
def get_deltatime_mmss(self, start_time, end_time):
elapsed_time = end_time - start_time
hours = int(elapsed_time // 3600)
minutes = int((elapsed_time % 3600) // 60)
seconds = int(elapsed_time % 60)
return f"{hours:02d}:{minutes:02d}:{seconds:02d}"

View File

@@ -1 +0,0 @@
2024-11-14 16:35:40.507 | INFO | agentscope.models:read_model_configs:186 - Load configs for model wrapper: openai_cfg

View File

@@ -1,7 +0,0 @@
{
"project": "7rGHWe",
"name": "jmd8td",
"run_id": "run_20241114-164343_jmd8td",
"timestamp": "2024-11-14 16:43:43",
"pid": 28598
}

View File

@@ -1,169 +0,0 @@
from flask import Flask, session, request, jsonify, render_template, send_from_directory
from flask_cors import CORS
from flask_socketio import SocketIO, join_room, emit
import markdown
import os
import uuid
import shutil
import sys
import json
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(0, parent_dir)
from AlgoriAgent.projects.algoriAgent.agent_manager import AgentManager
app = Flask(__name__)
app.secret_key = 'cakebaker'
# 配置 CORS
CORS(app, resources={r"/*": {"origins": "http://localhost:9888"}}, supports_credentials=True)
'''
Backboard
'''
class Backboard:
pass
@app.route('/backboard')
def backboard():
return jsonify({'status': 'success'})
'''
Agent and Chat
'''
socketio = SocketIO(app, cors_allowed_origins="*")
agent_manager = AgentManager()
def realtime_response(config, realtime_action):
print("config"+str(config))
print("realtime_action"+str(realtime_action))
pass
@socketio.on('connect')
def handle_connect():
user_id = session.get('user_id')
if (user_id is None):
print("No user_id in session")
return jsonify({'error': 'Connection failed bacause no user_id found'}), 401
print(f'User connected with session user_id: {user_id}')
id, agent = agent_manager.get_agent(user_id)
if user_id:
join_room(user_id) # 将该用户加入以user_id为名的room
# 当接收到前端的消息时,触发此事件
@socketio.on('send_message')
def handle_message(data):
print(f"Message from client: {data}")
id = session.get('user_id')
# 构造回复消息
res = agent_manager.invoke(id, data)
reply = f"AI: {res.content['speak']}"
# 将回复发送回前端
emit('receive_message', reply)
'''
Markdown to HTML
'''
# 配置文件路径
MARKDOWN_DIR = 'books/markdown' # 存放 markdown 文件的文件夹
STATIC_DIR = 'static' # 存放生成的 HTML 和图片资源的文件夹
IMAGE_DIR = 'image' # 图片资源相对于 markdown 的位置
@app.route('/<filename>-markdown', methods=['GET'])
def convert_md(filename):
md_file_path = os.path.join(MARKDOWN_DIR, f'{filename}.md')
if not os.path.exists(md_file_path):
return jsonify({'error': 'Markdown file not found'}), 404
# 读取 markdown 文件内容
with open(md_file_path, 'r', encoding='utf-8') as file:
md_content = file.read()
# 将 markdown 转换为 HTML
html_content = markdown.markdown(md_content)
# 插入 CSS 样式,限制图片最大宽度为 100%,高度自动调整
html_with_styles = f"""
<html>
<head>
<style>
img {{
max-width: 100%;
height: auto;
}}
</style>
</head>
<body>
{html_content}
</body>
</html>
"""
# 保存 HTML 文件到 static 文件夹
html_output_path = os.path.join(STATIC_DIR, f'{filename}.html')
with open(html_output_path, 'w', encoding='utf-8') as html_file:
html_file.write(html_with_styles)
# 处理图片资源,将 image/xxx 文件夹拷贝到 static/image/xxx
image_source_dir = os.path.join(MARKDOWN_DIR, IMAGE_DIR, filename)
image_target_dir = os.path.join(STATIC_DIR, IMAGE_DIR, filename)
print(f"Copying image resources from {image_source_dir} to {image_target_dir}")
if os.path.exists(image_source_dir):
# 确保 static/image/xxx 目录存在
if not os.path.exists(image_target_dir):
os.makedirs(image_target_dir)
# 拷贝图片资源
for image_file in os.listdir(image_source_dir):
full_image_file_path = os.path.join(image_source_dir, image_file)
if os.path.isfile(full_image_file_path):
shutil.copy(full_image_file_path, image_target_dir)
return jsonify({'html_url': f'/static/{filename}.html'})
# 静态文件HTML 和图片资源)的访问
@app.route('/static/<path:filename>')
def serve_static(filename):
return send_from_directory(STATIC_DIR, filename)
'''
Vscode
'''
@app.route('/desktop/<user_id>/<path>')
def hello_world(user_id, path):
if 'user_id' not in session:
session['user_id'] = 'user_' + str(uuid.uuid4())
# 在上层 目录下创建一个名为 user_id_path 的文件夹
path_dir = os.path.join(parent_dir, user_id, path)
os.makedirs(path_dir, exist_ok=True)
# 在此文件夹内部创建一个.config文件并写入 user_id=user_id\n path=path
config_path = os.path.join(path_dir, '.config')
with open(config_path, 'w') as f:
f.write(f"user_id={user_id}\npath={path}")
return render_template('index.html', user_id=user_id, path=path)
@app.route('/vscode_data', methods=['POST'])
def vscode_data():
data = request.json
config = data['config']
realtime_response(config,data)
print(f"Received data from VSCode: {data}")
return jsonify({"status": "success", "received": data})
@app.route('/get_session')
def get_session():
user_session = session.get('user_id', 'default_session')
return jsonify({"session": user_session})
if __name__ == '__main__':
socketio.run(app, host='0.0.0.0', port=5500)

View File

@@ -1,51 +0,0 @@
import time
class BackBoardManager:
def __init__(self):
self.backboards = {} # user_id: Backboard
def add_backboard(self, user_id, folder):
self.backboards[user_id] = Backboard(user_id, folder)
def get_backboard(self, user_id):
if user_id not in self.backboards:
return None
return self.backboards[user_id]
class Backboard:
def __init__(self, user_id, folder):
self.user_id = user_id
self.folder = folder
self.create_time = time.time()
self.enter_chapter_time = time.time()
def next_chapter(self):
self.enter_chapter_time = time.time()
def get_info_prompt(self):
return f"###Global Info:###\n\
User is {self.user_id}\n\
User's total study time is {self.get_deltatime_mmss(self.create_time, time.time())}\n\
User's current chapter study time is {self.get_deltatime_mmss(self.enter_chapter_time, time.time())}\n\
\n\n\
"
def get_deltatime_mmss(self, start_time, end_time):
elapsed_time = end_time - start_time
hours = int(elapsed_time // 3600)
minutes = int((elapsed_time % 3600) // 60)
seconds = int(elapsed_time % 60)
return f"{hours:02d}:{minutes:02d}:{seconds:02d}"

View File

@@ -1 +0,0 @@
2024-11-14 16:43:59.414 | INFO | agentscope.models:read_model_configs:186 - Load configs for model wrapper: openai_cfg

View File

@@ -1,7 +0,0 @@
{
"project": "28cXo4",
"name": "wb6exw",
"run_id": "run_20241114-214752_wb6exw",
"timestamp": "2024-11-14 21:47:52",
"pid": 15325
}

View File

@@ -1,180 +0,0 @@
from flask import Flask, session, request, jsonify, render_template, send_from_directory
from flask_cors import CORS
from flask_socketio import SocketIO, join_room, emit
import markdown
import os
import uuid
import shutil
import sys
import json
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(0, parent_dir)
current_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '.'))
sys.path.insert(0, current_dir)
from AlgoriAgent.projects.algoriAgent.agent_manager import AgentManager
app = Flask(__name__)
app.secret_key = 'cakebaker'
# 配置 CORS
CORS(app, resources={r"/*": {"origins": "http://localhost:9888"}}, supports_credentials=True)
userid_recorder = {} # user_id&path -> session['user_id']
'''
Backboard
'''
from backboardManager import BackBoardManager
backboard_manager = BackBoardManager()
@app.route('/backboard')
def backboard():
return jsonify({'status': 'success'})
'''
Agent and Chat
'''
socketio = SocketIO(app, cors_allowed_origins="*")
agent_manager = AgentManager()
def realtime_response(config, realtime_action):
print("config"+str(config))
print("realtime_action"+str(realtime_action))
pass
@socketio.on('connect')
def handle_connect():
user = request.args.get('username')
folder_name = request.args.get('folder')
user_id = userid_recorder[user+'&'+folder_name]
session['user_id'] = user_id
print(f'User connected with session user_id: {user_id}')
# 从markdown、markdown_prompts、score_prompts中各读取数据folder.md并进行new_agent
with open(f'books/markdown/{folder_name}.md','r') as fmd, open(f'books/markdown_prompts/{folder_name}.md','r')as fmdp, open(f'books/score_prompts/{folder_name}.md','r') as fsp:
markdown = fmd.read()
markdown_prompts = fmdp.read()
score_prompts = fsp.read()
id, agent = agent_manager.new_agent(markdown, markdown_prompts, score_prompts, id=user_id)
join_room(id) # 将该用户加入以user_id为名的room
# 当接收到前端的消息时,触发此事件
@socketio.on('send_message')
def handle_message(data):
print(f"Message from client: {data}")
id = session.get('user_id')
# 构造回复消息
res = agent_manager.invoke(id, data)
reply = f"AI: {res.content['speak']}"
# 将回复发送回前端
emit('receive_message', reply)
'''
Markdown to HTML
'''
# 配置文件路径
MARKDOWN_DIR = 'books/markdown' # 存放 markdown 文件的文件夹
STATIC_DIR = 'static' # 存放生成的 HTML 和图片资源的文件夹
IMAGE_DIR = 'image' # 图片资源相对于 markdown 的位置
@app.route('/<filename>-markdown', methods=['GET'])
def convert_md(filename):
md_file_path = os.path.join(MARKDOWN_DIR, f'{filename}.md')
if not os.path.exists(md_file_path):
return jsonify({'error': 'Markdown file not found'}), 404
# 读取 markdown 文件内容
with open(md_file_path, 'r', encoding='utf-8') as file:
md_content = file.read()
# 将 markdown 转换为 HTML
html_content = markdown.markdown(md_content)
# 插入 CSS 样式,限制图片最大宽度为 100%,高度自动调整
html_with_styles = f"""
<html>
<head>
<style>
img {{
max-width: 100%;
height: auto;
}}
</style>
</head>
<body>
{html_content}
</body>
</html>
"""
# 保存 HTML 文件到 static 文件夹
html_output_path = os.path.join(STATIC_DIR, f'{filename}.html')
with open(html_output_path, 'w', encoding='utf-8') as html_file:
html_file.write(html_with_styles)
# 处理图片资源,将 image/xxx 文件夹拷贝到 static/image/xxx
image_source_dir = os.path.join(MARKDOWN_DIR, IMAGE_DIR, filename)
image_target_dir = os.path.join(STATIC_DIR, IMAGE_DIR, filename)
print(f"Copying image resources from {image_source_dir} to {image_target_dir}")
if os.path.exists(image_source_dir):
# 确保 static/image/xxx 目录存在
if not os.path.exists(image_target_dir):
os.makedirs(image_target_dir)
# 拷贝图片资源
for image_file in os.listdir(image_source_dir):
full_image_file_path = os.path.join(image_source_dir, image_file)
if os.path.isfile(full_image_file_path):
shutil.copy(full_image_file_path, image_target_dir)
return jsonify({'html_url': f'/static/{filename}.html'})
# 静态文件HTML 和图片资源)的访问
@app.route('/static/<path:filename>')
def serve_static(filename):
return send_from_directory(STATIC_DIR, filename)
'''
Vscode
'''
@app.route('/desktop/<user_id>/<path>')
def hello_world(user_id, path):
if 'user_id' not in session:
session['user_id'] = 'user_' + str(uuid.uuid4())
userid_recorder[user_id+'&'+path] = session['user_id']
# 在上层 目录下创建一个名为 user_id_path 的文件夹
path_dir = os.path.join(parent_dir, user_id, path)
os.makedirs(path_dir, exist_ok=True)
# 在此文件夹内部创建一个.config文件并写入 user_id=user_id\n path=path
config_path = os.path.join(path_dir, '.config')
with open(config_path, 'w') as f:
f.write(f"user_id={user_id}\npath={path}")
return render_template('index.html', user_id=user_id, path=path)
@app.route('/vscode_data', methods=['POST'])
def vscode_data():
data = request.json
config = data['config']
realtime_response(config,data)
print(f"Received data from VSCode: {data}")
return jsonify({"status": "success", "received": data})
@app.route('/get_session')
def get_session():
user_session = session.get('user_id', 'default_session')
return jsonify({"session": user_session})
if __name__ == '__main__':
socketio.run(app, host='0.0.0.0', port=5500)

View File

@@ -1,51 +0,0 @@
import time
class BackBoardManager:
def __init__(self):
self.backboards = {} # user_id: Backboard
def add_backboard(self, user_id, folder):
self.backboards[user_id] = Backboard(user_id, folder)
def get_backboard(self, user_id):
if user_id not in self.backboards:
return None
return self.backboards[user_id]
class Backboard:
def __init__(self, user_id, folder):
self.user_id = user_id
self.folder = folder
self.create_time = time.time()
self.enter_chapter_time = time.time()
def next_chapter(self):
self.enter_chapter_time = time.time()
def get_info_prompt(self):
return f"###Global Info:###\n\
User is {self.user_id}\n\
User's total study time is {self.get_deltatime_mmss(self.create_time, time.time())}\n\
User's current chapter study time is {self.get_deltatime_mmss(self.enter_chapter_time, time.time())}\n\
\n\n\
"
def get_deltatime_mmss(self, start_time, end_time):
elapsed_time = end_time - start_time
hours = int(elapsed_time // 3600)
minutes = int((elapsed_time % 3600) // 60)
seconds = int(elapsed_time % 60)
return f"{hours:02d}:{minutes:02d}:{seconds:02d}"

View File

@@ -1 +0,0 @@
2024-11-14 21:48:13.935 | INFO | agentscope.models:read_model_configs:186 - Load configs for model wrapper: openai_cfg

View File

@@ -1,7 +0,0 @@
{
"project": "JOBFuf",
"name": "mgm60l",
"run_id": "run_20241114-214935_mgm60l",
"timestamp": "2024-11-14 21:49:35",
"pid": 16725
}

View File

@@ -1,180 +0,0 @@
from flask import Flask, session, request, jsonify, render_template, send_from_directory
from flask_cors import CORS
from flask_socketio import SocketIO, join_room, emit
import markdown
import os
import uuid
import shutil
import sys
import json
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(0, parent_dir)
current_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '.'))
sys.path.insert(0, current_dir)
from AlgoriAgent.projects.algoriAgent.agent_manager import AgentManager
app = Flask(__name__)
app.secret_key = 'cakebaker'
# 配置 CORS
CORS(app, resources={r"/*": {"origins": "http://localhost:9888"}}, supports_credentials=True)
userid_recorder = {} # user_id&path -> session['user_id']
'''
Backboard
'''
from backboardManager import BackBoardManager
backboard_manager = BackBoardManager()
@app.route('/backboard')
def backboard():
return jsonify({'status': 'success'})
'''
Agent and Chat
'''
socketio = SocketIO(app, cors_allowed_origins="*")
agent_manager = AgentManager()
def realtime_response(config, realtime_action):
print("config"+str(config))
print("realtime_action"+str(realtime_action))
pass
@socketio.on('connect')
def handle_connect():
user = request.args.get('username')
folder_name = request.args.get('folder')
user_id = userid_recorder[user+'&'+folder_name]
session['user_id'] = user_id
print(f'User connected with session user_id: {user_id}')
# 从markdown、markdown_prompts、score_prompts中各读取数据folder.md并进行new_agent
with open(f'books/markdown/{folder_name}.md','r') as fmd, open(f'books/markdown_prompts/{folder_name}.md','r')as fmdp, open(f'books/score_prompts/{folder_name}.md','r') as fsp:
markdown = fmd.read()
markdown_prompts = fmdp.read()
score_prompts = fsp.read()
id, agent = agent_manager.new_agent(markdown, markdown_prompts, score_prompts, id=user_id)
join_room(id) # 将该用户加入以user_id为名的room
# 当接收到前端的消息时,触发此事件
@socketio.on('send_message')
def handle_message(data):
print(f"Message from client: {data}")
id = session.get('user_id')
# 构造回复消息
res = agent_manager.invoke(id, data)
reply = f"AI: {res.content['speak']}"
# 将回复发送回前端
emit('receive_message', reply)
'''
Markdown to HTML
'''
# 配置文件路径
MARKDOWN_DIR = 'books/markdown' # 存放 markdown 文件的文件夹
STATIC_DIR = 'static' # 存放生成的 HTML 和图片资源的文件夹
IMAGE_DIR = 'image' # 图片资源相对于 markdown 的位置
@app.route('/<filename>-markdown', methods=['GET'])
def convert_md(filename):
md_file_path = os.path.join(MARKDOWN_DIR, f'{filename}.md')
if not os.path.exists(md_file_path):
return jsonify({'error': 'Markdown file not found'}), 404
# 读取 markdown 文件内容
with open(md_file_path, 'r', encoding='utf-8') as file:
md_content = file.read()
# 将 markdown 转换为 HTML
html_content = markdown.markdown(md_content)
# 插入 CSS 样式,限制图片最大宽度为 100%,高度自动调整
html_with_styles = f"""
<html>
<head>
<style>
img {{
max-width: 100%;
height: auto;
}}
</style>
</head>
<body>
{html_content}
</body>
</html>
"""
# 保存 HTML 文件到 static 文件夹
html_output_path = os.path.join(STATIC_DIR, f'{filename}.html')
with open(html_output_path, 'w', encoding='utf-8') as html_file:
html_file.write(html_with_styles)
# 处理图片资源,将 image/xxx 文件夹拷贝到 static/image/xxx
image_source_dir = os.path.join(MARKDOWN_DIR, IMAGE_DIR, filename)
image_target_dir = os.path.join(STATIC_DIR, IMAGE_DIR, filename)
print(f"Copying image resources from {image_source_dir} to {image_target_dir}")
if os.path.exists(image_source_dir):
# 确保 static/image/xxx 目录存在
if not os.path.exists(image_target_dir):
os.makedirs(image_target_dir)
# 拷贝图片资源
for image_file in os.listdir(image_source_dir):
full_image_file_path = os.path.join(image_source_dir, image_file)
if os.path.isfile(full_image_file_path):
shutil.copy(full_image_file_path, image_target_dir)
return jsonify({'html_url': f'/static/{filename}.html'})
# 静态文件HTML 和图片资源)的访问
@app.route('/static/<path:filename>')
def serve_static(filename):
return send_from_directory(STATIC_DIR, filename)
'''
Vscode
'''
@app.route('/desktop/<user_id>/<path>')
def hello_world(user_id, path):
if 'user_id' not in session:
session['user_id'] = 'user_' + str(uuid.uuid4())
userid_recorder[user_id+'&'+path] = session['user_id']
# 在上层 目录下创建一个名为 user_id_path 的文件夹
path_dir = os.path.join(parent_dir, user_id, path)
os.makedirs(path_dir, exist_ok=True)
# 在此文件夹内部创建一个.config文件并写入 user_id=user_id\n path=path
config_path = os.path.join(path_dir, '.config')
with open(config_path, 'w') as f:
f.write(f"user_id={user_id}\npath={path}")
return render_template('index.html', user_id=user_id, path=path)
@app.route('/vscode_data', methods=['POST'])
def vscode_data():
data = request.json
config = data['config']
realtime_response(config,data)
print(f"Received data from VSCode: {data}")
return jsonify({"status": "success", "received": data})
@app.route('/get_session')
def get_session():
user_session = session.get('user_id', 'default_session')
return jsonify({"session": user_session})
if __name__ == '__main__':
socketio.run(app, host='0.0.0.0', port=5500)

View File

@@ -1,51 +0,0 @@
import time
class BackBoardManager:
def __init__(self):
self.backboards = {} # user_id: Backboard
def add_backboard(self, user_id, folder):
self.backboards[user_id] = Backboard(user_id, folder)
def get_backboard(self, user_id):
if user_id not in self.backboards:
return None
return self.backboards[user_id]
class Backboard:
def __init__(self, user_id, folder):
self.user_id = user_id
self.folder = folder
self.create_time = time.time()
self.enter_chapter_time = time.time()
def next_chapter(self):
self.enter_chapter_time = time.time()
def get_info_prompt(self):
return f"###Global Info:###\n\
User is {self.user_id}\n\
User's total study time is {self.get_deltatime_mmss(self.create_time, time.time())}\n\
User's current chapter study time is {self.get_deltatime_mmss(self.enter_chapter_time, time.time())}\n\
\n\n\
"
def get_deltatime_mmss(self, start_time, end_time):
elapsed_time = end_time - start_time
hours = int(elapsed_time // 3600)
minutes = int((elapsed_time % 3600) // 60)
seconds = int(elapsed_time % 60)
return f"{hours:02d}:{minutes:02d}:{seconds:02d}"

View File

@@ -1 +0,0 @@
2024-11-14 21:49:45.643 | INFO | agentscope.models:read_model_configs:186 - Load configs for model wrapper: openai_cfg

View File

@@ -1,7 +0,0 @@
{
"project": "adTV6W",
"name": "4l1w9g",
"run_id": "run_20241114-215220_4l1w9g",
"timestamp": "2024-11-14 21:52:20",
"pid": 18255
}

View File

@@ -1,182 +0,0 @@
from flask import Flask, session, request, jsonify, render_template, send_from_directory
from flask_cors import CORS
from flask_socketio import SocketIO, join_room, emit
import markdown
import os
import uuid
import shutil
import sys
import json
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(0, parent_dir)
current_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '.'))
sys.path.insert(0, current_dir)
from AlgoriAgent.projects.algoriAgent.agent_manager import AgentManager
app = Flask(__name__)
app.secret_key = 'cakebaker'
# 配置 CORS
CORS(app, resources={r"/*": {"origins": "http://localhost:9888"}}, supports_credentials=True)
userid_recorder = {} # user_id&path -> session['user_id']
'''
Backboard
'''
from backboardManager import BackBoardManager
backboard_manager = BackBoardManager()
@app.route('/backboard')
def backboard():
return jsonify({'status': 'success'})
'''
Agent and Chat
'''
socketio = SocketIO(app, cors_allowed_origins="*")
agent_manager = AgentManager()
def realtime_response(config, realtime_action):
print("config"+str(config))
print("realtime_action"+str(realtime_action))
pass
@socketio.on('connect')
def handle_connect():
user = request.args.get('username')
folder_name = request.args.get('folder')
user_id = userid_recorder[user+'&'+folder_name]
session['user_id'] = user_id
print(f'User connected with session user_id: {user_id}')
# 从markdown、markdown_prompts、score_prompts中各读取数据folder.md并进行new_agent
with open(f'books/markdown/{folder_name}.md','r') as fmd,\
open(f'books/markdown_prompts/{folder_name}.md','r')as fmdp,\
open(f'books/score_prompts/{folder_name}.md','r') as fsp:
markdown = fmd.read()
markdown_prompts = fmdp.read()
score_prompts = fsp.read()
id, agent = agent_manager.new_agent(markdown, markdown_prompts, score_prompts, id=user_id)
join_room(id) # 将该用户加入以user_id为名的room
# 当接收到前端的消息时,触发此事件
@socketio.on('send_message')
def handle_message(data):
print(f"Message from client: {data}")
id = session.get('user_id')
# 构造回复消息
res = agent_manager.invoke(id, data)
reply = f"AI: {res.content['speak']}"
# 将回复发送回前端
emit('receive_message', reply)
'''
Markdown to HTML
'''
# 配置文件路径
MARKDOWN_DIR = 'books/markdown' # 存放 markdown 文件的文件夹
STATIC_DIR = 'static' # 存放生成的 HTML 和图片资源的文件夹
IMAGE_DIR = 'image' # 图片资源相对于 markdown 的位置
@app.route('/<filename>-markdown', methods=['GET'])
def convert_md(filename):
md_file_path = os.path.join(MARKDOWN_DIR, f'{filename}.md')
if not os.path.exists(md_file_path):
return jsonify({'error': 'Markdown file not found'}), 404
# 读取 markdown 文件内容
with open(md_file_path, 'r', encoding='utf-8') as file:
md_content = file.read()
# 将 markdown 转换为 HTML
html_content = markdown.markdown(md_content)
# 插入 CSS 样式,限制图片最大宽度为 100%,高度自动调整
html_with_styles = f"""
<html>
<head>
<style>
img {{
max-width: 100%;
height: auto;
}}
</style>
</head>
<body>
{html_content}
</body>
</html>
"""
# 保存 HTML 文件到 static 文件夹
html_output_path = os.path.join(STATIC_DIR, f'{filename}.html')
with open(html_output_path, 'w', encoding='utf-8') as html_file:
html_file.write(html_with_styles)
# 处理图片资源,将 image/xxx 文件夹拷贝到 static/image/xxx
image_source_dir = os.path.join(MARKDOWN_DIR, IMAGE_DIR, filename)
image_target_dir = os.path.join(STATIC_DIR, IMAGE_DIR, filename)
print(f"Copying image resources from {image_source_dir} to {image_target_dir}")
if os.path.exists(image_source_dir):
# 确保 static/image/xxx 目录存在
if not os.path.exists(image_target_dir):
os.makedirs(image_target_dir)
# 拷贝图片资源
for image_file in os.listdir(image_source_dir):
full_image_file_path = os.path.join(image_source_dir, image_file)
if os.path.isfile(full_image_file_path):
shutil.copy(full_image_file_path, image_target_dir)
return jsonify({'html_url': f'/static/{filename}.html'})
# 静态文件HTML 和图片资源)的访问
@app.route('/static/<path:filename>')
def serve_static(filename):
return send_from_directory(STATIC_DIR, filename)
'''
Vscode
'''
@app.route('/desktop/<user_id>/<path>')
def hello_world(user_id, path):
if 'user_id' not in session:
session['user_id'] = 'user_' + str(uuid.uuid4())
userid_recorder[user_id+'&'+path] = session['user_id']
# 在上层 目录下创建一个名为 user_id_path 的文件夹
path_dir = os.path.join(parent_dir, user_id, path)
os.makedirs(path_dir, exist_ok=True)
# 在此文件夹内部创建一个.config文件并写入 user_id=user_id\n path=path
config_path = os.path.join(path_dir, '.config')
with open(config_path, 'w') as f:
f.write(f"user_id={user_id}\npath={path}")
return render_template('index.html', user_id=user_id, path=path)
@app.route('/vscode_data', methods=['POST'])
def vscode_data():
data = request.json
config = data['config']
realtime_response(config,data)
print(f"Received data from VSCode: {data}")
return jsonify({"status": "success", "received": data})
@app.route('/get_session')
def get_session():
user_session = session.get('user_id', 'default_session')
return jsonify({"session": user_session})
if __name__ == '__main__':
socketio.run(app, host='0.0.0.0', port=5500)

View File

@@ -1,51 +0,0 @@
import time
class BackBoardManager:
def __init__(self):
self.backboards = {} # user_id: Backboard
def add_backboard(self, user_id, folder):
self.backboards[user_id] = Backboard(user_id, folder)
def get_backboard(self, user_id):
if user_id not in self.backboards:
return None
return self.backboards[user_id]
class Backboard:
def __init__(self, user_id, folder):
self.user_id = user_id
self.folder = folder
self.create_time = time.time()
self.enter_chapter_time = time.time()
def next_chapter(self):
self.enter_chapter_time = time.time()
def get_info_prompt(self):
return f"###Global Info:###\n\
User is {self.user_id}\n\
User's total study time is {self.get_deltatime_mmss(self.create_time, time.time())}\n\
User's current chapter study time is {self.get_deltatime_mmss(self.enter_chapter_time, time.time())}\n\
\n\n\
"
def get_deltatime_mmss(self, start_time, end_time):
elapsed_time = end_time - start_time
hours = int(elapsed_time // 3600)
minutes = int((elapsed_time % 3600) // 60)
seconds = int(elapsed_time % 60)
return f"{hours:02d}:{minutes:02d}:{seconds:02d}"

View File

@@ -1 +0,0 @@
2024-11-14 21:52:45.458 | INFO | agentscope.models:read_model_configs:186 - Load configs for model wrapper: openai_cfg

View File

@@ -1,7 +0,0 @@
{
"project": "bWVpBF",
"name": "13ob9v",
"run_id": "run_20241114-215426_13ob9v",
"timestamp": "2024-11-14 21:54:26",
"pid": 19572
}

View File

@@ -1,182 +0,0 @@
from flask import Flask, session, request, jsonify, render_template, send_from_directory
from flask_cors import CORS
from flask_socketio import SocketIO, join_room, emit
import markdown
import os
import uuid
import shutil
import sys
import json
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(0, parent_dir)
current_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '.'))
sys.path.insert(0, current_dir)
from AlgoriAgent.projects.algoriAgent.agent_manager import AgentManager
app = Flask(__name__)
app.secret_key = 'cakebaker'
# 配置 CORS
CORS(app, resources={r"/*": {"origins": "http://localhost:9888"}}, supports_credentials=True)
userid_recorder = {} # user_id&path -> session['user_id']
'''
Backboard
'''
from backboardManager import BackBoardManager
backboard_manager = BackBoardManager()
@app.route('/backboard')
def backboard():
return jsonify({'status': 'success'})
'''
Agent and Chat
'''
socketio = SocketIO(app, cors_allowed_origins="*")
agent_manager = AgentManager()
def realtime_response(config, realtime_action):
print("config"+str(config))
print("realtime_action"+str(realtime_action))
pass
@socketio.on('connect')
def handle_connect():
user = request.args.get('username')
folder_name = request.args.get('folder')
user_id = userid_recorder[user+'&'+folder_name]
session['user_id'] = user_id
print(f'User connected with session user_id: {user_id}')
# 从markdown、markdown_prompts、score_prompts中各读取数据folder.md并进行new_agent
with open(f'books/markdown/{folder_name}.md','r') as fmd,\
open(f'books/markdown_prompts/{folder_name}.md','r')as fmdp,\
open(f'books/score_prompts/{folder_name}.md','r') as fsp:
markdown = fmd.read()
markdown_prompts = fmdp.read()
score_prompts = fsp.read()
id, agent = agent_manager.new_agent(markdown, markdown_prompts, score_prompts, id=user_id)
join_room(id) # 将该用户加入以user_id为名的room
# 当接收到前端的消息时,触发此事件
@socketio.on('send_message')
def handle_message(data):
print(f"Message from client: {data}")
id = session.get('user_id')
# 构造回复消息
res = agent_manager.invoke(id, data)
reply = f"AI: {res.content['speak']}"
# 将回复发送回前端
emit('receive_message', reply)
'''
Markdown to HTML
'''
# 配置文件路径
MARKDOWN_DIR = 'books/markdown' # 存放 markdown 文件的文件夹
STATIC_DIR = 'static' # 存放生成的 HTML 和图片资源的文件夹
IMAGE_DIR = 'image' # 图片资源相对于 markdown 的位置
@app.route('/<filename>-markdown', methods=['GET'])
def convert_md(filename):
md_file_path = os.path.join(MARKDOWN_DIR, f'{filename}.md')
if not os.path.exists(md_file_path):
return jsonify({'error': 'Markdown file not found'}), 404
# 读取 markdown 文件内容
with open(md_file_path, 'r', encoding='utf-8') as file:
md_content = file.read()
# 将 markdown 转换为 HTML
html_content = markdown.markdown(md_content)
# 插入 CSS 样式,限制图片最大宽度为 100%,高度自动调整
html_with_styles = f"""
<html>
<head>
<style>
img {{
max-width: 100%;
height: auto;
}}
</style>
</head>
<body>
{html_content}
</body>
</html>
"""
# 保存 HTML 文件到 static 文件夹
html_output_path = os.path.join(STATIC_DIR, f'{filename}.html')
with open(html_output_path, 'w', encoding='utf-8') as html_file:
html_file.write(html_with_styles)
# 处理图片资源,将 image/xxx 文件夹拷贝到 static/image/xxx
image_source_dir = os.path.join(MARKDOWN_DIR, IMAGE_DIR, filename)
image_target_dir = os.path.join(STATIC_DIR, IMAGE_DIR, filename)
print(f"Copying image resources from {image_source_dir} to {image_target_dir}")
if os.path.exists(image_source_dir):
# 确保 static/image/xxx 目录存在
if not os.path.exists(image_target_dir):
os.makedirs(image_target_dir)
# 拷贝图片资源
for image_file in os.listdir(image_source_dir):
full_image_file_path = os.path.join(image_source_dir, image_file)
if os.path.isfile(full_image_file_path):
shutil.copy(full_image_file_path, image_target_dir)
return jsonify({'html_url': f'/static/{filename}.html'})
# 静态文件HTML 和图片资源)的访问
@app.route('/static/<path:filename>')
def serve_static(filename):
return send_from_directory(STATIC_DIR, filename)
'''
Vscode
'''
@app.route('/desktop/<user_id>/<path>')
def hello_world(user_id, path):
if 'user_id' not in session:
session['user_id'] = 'user_' + str(uuid.uuid4())
userid_recorder[user_id+'&'+path] = session['user_id']
# 在上层 目录下创建一个名为 user_id_path 的文件夹
path_dir = os.path.join(parent_dir, user_id, path)
os.makedirs(path_dir, exist_ok=True)
# 在此文件夹内部创建一个.config文件并写入 user_id=user_id\n path=path
config_path = os.path.join(path_dir, '.config')
with open(config_path, 'w') as f:
f.write(f"user_id={user_id}\npath={path}")
return render_template('index.html', user_id=user_id, path=path)
@app.route('/vscode_data', methods=['POST'])
def vscode_data():
data = request.json
config = data['config']
realtime_response(config,data)
print(f"Received data from VSCode: {data}")
return jsonify({"status": "success", "received": data})
@app.route('/get_session')
def get_session():
user_session = session.get('user_id', 'default_session')
return jsonify({"session": user_session})
if __name__ == '__main__':
socketio.run(app, host='0.0.0.0', port=5500)

View File

@@ -1,51 +0,0 @@
import time
class BackBoardManager:
def __init__(self):
self.backboards = {} # user_id: Backboard
def add_backboard(self, user_id, folder):
self.backboards[user_id] = Backboard(user_id, folder)
def get_backboard(self, user_id):
if user_id not in self.backboards:
return None
return self.backboards[user_id]
class Backboard:
def __init__(self, user_id, folder):
self.user_id = user_id
self.folder = folder
self.create_time = time.time()
self.enter_chapter_time = time.time()
def next_chapter(self):
self.enter_chapter_time = time.time()
def get_info_prompt(self):
return f"###Global Info:###\n\
User is {self.user_id}\n\
User's total study time is {self.get_deltatime_mmss(self.create_time, time.time())}\n\
User's current chapter study time is {self.get_deltatime_mmss(self.enter_chapter_time, time.time())}\n\
\n\n\
"
def get_deltatime_mmss(self, start_time, end_time):
elapsed_time = end_time - start_time
hours = int(elapsed_time // 3600)
minutes = int((elapsed_time % 3600) // 60)
seconds = int(elapsed_time % 60)
return f"{hours:02d}:{minutes:02d}:{seconds:02d}"

View File

@@ -1 +0,0 @@
2024-11-14 21:54:42.058 | INFO | agentscope.models:read_model_configs:186 - Load configs for model wrapper: openai_cfg

View File

@@ -1,7 +0,0 @@
{
"project": "JpOniY",
"name": "4hht6r",
"run_id": "run_20241114-215514_4hht6r",
"timestamp": "2024-11-14 21:55:14",
"pid": 20265
}

View File

@@ -1,183 +0,0 @@
from flask import Flask, session, request, jsonify, render_template, send_from_directory
from flask_cors import CORS
from flask_socketio import SocketIO, join_room, emit
import markdown
import os
import uuid
import shutil
import sys
import json
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(0, parent_dir)
current_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '.'))
sys.path.insert(0, current_dir)
from AlgoriAgent.projects.algoriAgent.agent_manager import AgentManager
app = Flask(__name__)
app.secret_key = 'cakebaker'
# 配置 CORS
CORS(app, resources={r"/*": {"origins": "http://localhost:9888"}}, supports_credentials=True)
userid_recorder = {} # user_id&path -> session['user_id']
'''
Backboard
'''
from backboardManager import BackBoardManager
backboard_manager = BackBoardManager()
@app.route('/backboard')
def backboard():
return jsonify({'status': 'success'})
'''
Agent and Chat
'''
socketio = SocketIO(app, cors_allowed_origins="*")
agent_manager = AgentManager()
def realtime_response(config, realtime_action):
print("config"+str(config))
print("realtime_action"+str(realtime_action))
pass
@socketio.on('connect')
def handle_connect():
user = request.args.get('username')
folder_name = request.args.get('folder')
user_id = userid_recorder[user+'&'+folder_name]
session['user_id'] = user_id
print(f'User connected with session user_id: {user_id}')
# 从markdown、markdown_prompts、score_prompts中各读取数据folder.md并进行new_agent
with open(f'books/markdown/{folder_name}.md','r') as fmd,\
open(f'books/markdown_prompts/{folder_name}.md','r')as fmdp,\
open(f'books/score_prompts/{folder_name}.md','r') as fsp:
markdown = fmd.read()
markdown_prompts = fmdp.read()
score_prompts = fsp.read()
print(user_id)
id, agent = agent_manager.new_agent(markdown, markdown_prompts, score_prompts, id=user_id)
join_room(id) # 将该用户加入以user_id为名的room
# 当接收到前端的消息时,触发此事件
@socketio.on('send_message')
def handle_message(data):
print(f"Message from client: {data}")
id = session.get('user_id')
# 构造回复消息
res = agent_manager.invoke(id, data)
reply = f"AI: {res.content['speak']}"
# 将回复发送回前端
emit('receive_message', reply)
'''
Markdown to HTML
'''
# 配置文件路径
MARKDOWN_DIR = 'books/markdown' # 存放 markdown 文件的文件夹
STATIC_DIR = 'static' # 存放生成的 HTML 和图片资源的文件夹
IMAGE_DIR = 'image' # 图片资源相对于 markdown 的位置
@app.route('/<filename>-markdown', methods=['GET'])
def convert_md(filename):
md_file_path = os.path.join(MARKDOWN_DIR, f'{filename}.md')
if not os.path.exists(md_file_path):
return jsonify({'error': 'Markdown file not found'}), 404
# 读取 markdown 文件内容
with open(md_file_path, 'r', encoding='utf-8') as file:
md_content = file.read()
# 将 markdown 转换为 HTML
html_content = markdown.markdown(md_content)
# 插入 CSS 样式,限制图片最大宽度为 100%,高度自动调整
html_with_styles = f"""
<html>
<head>
<style>
img {{
max-width: 100%;
height: auto;
}}
</style>
</head>
<body>
{html_content}
</body>
</html>
"""
# 保存 HTML 文件到 static 文件夹
html_output_path = os.path.join(STATIC_DIR, f'{filename}.html')
with open(html_output_path, 'w', encoding='utf-8') as html_file:
html_file.write(html_with_styles)
# 处理图片资源,将 image/xxx 文件夹拷贝到 static/image/xxx
image_source_dir = os.path.join(MARKDOWN_DIR, IMAGE_DIR, filename)
image_target_dir = os.path.join(STATIC_DIR, IMAGE_DIR, filename)
print(f"Copying image resources from {image_source_dir} to {image_target_dir}")
if os.path.exists(image_source_dir):
# 确保 static/image/xxx 目录存在
if not os.path.exists(image_target_dir):
os.makedirs(image_target_dir)
# 拷贝图片资源
for image_file in os.listdir(image_source_dir):
full_image_file_path = os.path.join(image_source_dir, image_file)
if os.path.isfile(full_image_file_path):
shutil.copy(full_image_file_path, image_target_dir)
return jsonify({'html_url': f'/static/{filename}.html'})
# 静态文件HTML 和图片资源)的访问
@app.route('/static/<path:filename>')
def serve_static(filename):
return send_from_directory(STATIC_DIR, filename)
'''
Vscode
'''
@app.route('/desktop/<user_id>/<path>')
def hello_world(user_id, path):
if 'user_id' not in session:
session['user_id'] = 'user_' + str(uuid.uuid4())
userid_recorder[user_id+'&'+path] = session['user_id']
# 在上层 目录下创建一个名为 user_id_path 的文件夹
path_dir = os.path.join(parent_dir, user_id, path)
os.makedirs(path_dir, exist_ok=True)
# 在此文件夹内部创建一个.config文件并写入 user_id=user_id\n path=path
config_path = os.path.join(path_dir, '.config')
with open(config_path, 'w') as f:
f.write(f"user_id={user_id}\npath={path}")
return render_template('index.html', user_id=user_id, path=path)
@app.route('/vscode_data', methods=['POST'])
def vscode_data():
data = request.json
config = data['config']
realtime_response(config,data)
print(f"Received data from VSCode: {data}")
return jsonify({"status": "success", "received": data})
@app.route('/get_session')
def get_session():
user_session = session.get('user_id', 'default_session')
return jsonify({"session": user_session})
if __name__ == '__main__':
socketio.run(app, host='0.0.0.0', port=5500)

View File

@@ -1,51 +0,0 @@
import time
class BackBoardManager:
def __init__(self):
self.backboards = {} # user_id: Backboard
def add_backboard(self, user_id, folder):
self.backboards[user_id] = Backboard(user_id, folder)
def get_backboard(self, user_id):
if user_id not in self.backboards:
return None
return self.backboards[user_id]
class Backboard:
def __init__(self, user_id, folder):
self.user_id = user_id
self.folder = folder
self.create_time = time.time()
self.enter_chapter_time = time.time()
def next_chapter(self):
self.enter_chapter_time = time.time()
def get_info_prompt(self):
return f"###Global Info:###\n\
User is {self.user_id}\n\
User's total study time is {self.get_deltatime_mmss(self.create_time, time.time())}\n\
User's current chapter study time is {self.get_deltatime_mmss(self.enter_chapter_time, time.time())}\n\
\n\n\
"
def get_deltatime_mmss(self, start_time, end_time):
elapsed_time = end_time - start_time
hours = int(elapsed_time // 3600)
minutes = int((elapsed_time % 3600) // 60)
seconds = int(elapsed_time % 60)
return f"{hours:02d}:{minutes:02d}:{seconds:02d}"

View File

@@ -1 +0,0 @@
2024-11-14 21:55:29.213 | INFO | agentscope.models:read_model_configs:186 - Load configs for model wrapper: openai_cfg

View File

@@ -1,7 +0,0 @@
{
"project": "c6FVzt",
"name": "s92n8y",
"run_id": "run_20241114-215712_s92n8y",
"timestamp": "2024-11-14 21:57:12",
"pid": 21458
}

View File

@@ -1,184 +0,0 @@
from flask import Flask, session, request, jsonify, render_template, send_from_directory
from flask_cors import CORS
from flask_socketio import SocketIO, join_room, emit
import markdown
import os
import uuid
import shutil
import sys
import json
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(0, parent_dir)
current_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '.'))
sys.path.insert(0, current_dir)
from AlgoriAgent.projects.algoriAgent.agent_manager import AgentManager
app = Flask(__name__)
app.secret_key = 'cakebaker'
# 配置 CORS
CORS(app, resources={r"/*": {"origins": "http://localhost:9888"}}, supports_credentials=True)
userid_recorder = {} # user_id&path -> session['user_id']
'''
Backboard
'''
from backboardManager import BackBoardManager
backboard_manager = BackBoardManager()
@app.route('/backboard')
def backboard():
return jsonify({'status': 'success'})
'''
Agent and Chat
'''
socketio = SocketIO(app, cors_allowed_origins="*")
agent_manager = AgentManager()
def realtime_response(config, realtime_action):
print("config"+str(config))
print("realtime_action"+str(realtime_action))
pass
@socketio.on('connect')
def handle_connect():
user = request.args.get('username')
folder_name = request.args.get('folder')
user_id = userid_recorder[user+'&'+folder_name]
session['user_id'] = user_id
print(f'User connected with session user_id: {user_id}')
# 从markdown、markdown_prompts、score_prompts中各读取数据folder.md并进行new_agent
with open(f'books/markdown/{folder_name}.md','r') as fmd,\
open(f'books/markdown_prompts/{folder_name}.md','r')as fmdp,\
open(f'books/score_prompts/{folder_name}.md','r') as fsp:
markdown = fmd.read()
markdown_prompts = fmdp.read()
score_prompts = fsp.read()
print('-----------------------')
print(user_id)
id, agent = agent_manager.new_agent(markdown, markdown_prompts, score_prompts, id=user_id)
join_room(id) # 将该用户加入以user_id为名的room
# 当接收到前端的消息时,触发此事件
@socketio.on('send_message')
def handle_message(data):
print(f"Message from client: {data}")
id = session.get('user_id')
# 构造回复消息
res = agent_manager.invoke(id, data)
reply = f"AI: {res.content['speak']}"
# 将回复发送回前端
emit('receive_message', reply)
'''
Markdown to HTML
'''
# 配置文件路径
MARKDOWN_DIR = 'books/markdown' # 存放 markdown 文件的文件夹
STATIC_DIR = 'static' # 存放生成的 HTML 和图片资源的文件夹
IMAGE_DIR = 'image' # 图片资源相对于 markdown 的位置
@app.route('/<filename>-markdown', methods=['GET'])
def convert_md(filename):
md_file_path = os.path.join(MARKDOWN_DIR, f'{filename}.md')
if not os.path.exists(md_file_path):
return jsonify({'error': 'Markdown file not found'}), 404
# 读取 markdown 文件内容
with open(md_file_path, 'r', encoding='utf-8') as file:
md_content = file.read()
# 将 markdown 转换为 HTML
html_content = markdown.markdown(md_content)
# 插入 CSS 样式,限制图片最大宽度为 100%,高度自动调整
html_with_styles = f"""
<html>
<head>
<style>
img {{
max-width: 100%;
height: auto;
}}
</style>
</head>
<body>
{html_content}
</body>
</html>
"""
# 保存 HTML 文件到 static 文件夹
html_output_path = os.path.join(STATIC_DIR, f'{filename}.html')
with open(html_output_path, 'w', encoding='utf-8') as html_file:
html_file.write(html_with_styles)
# 处理图片资源,将 image/xxx 文件夹拷贝到 static/image/xxx
image_source_dir = os.path.join(MARKDOWN_DIR, IMAGE_DIR, filename)
image_target_dir = os.path.join(STATIC_DIR, IMAGE_DIR, filename)
print(f"Copying image resources from {image_source_dir} to {image_target_dir}")
if os.path.exists(image_source_dir):
# 确保 static/image/xxx 目录存在
if not os.path.exists(image_target_dir):
os.makedirs(image_target_dir)
# 拷贝图片资源
for image_file in os.listdir(image_source_dir):
full_image_file_path = os.path.join(image_source_dir, image_file)
if os.path.isfile(full_image_file_path):
shutil.copy(full_image_file_path, image_target_dir)
return jsonify({'html_url': f'/static/{filename}.html'})
# 静态文件HTML 和图片资源)的访问
@app.route('/static/<path:filename>')
def serve_static(filename):
return send_from_directory(STATIC_DIR, filename)
'''
Vscode
'''
@app.route('/desktop/<user_id>/<path>')
def hello_world(user_id, path):
if 'user_id' not in session:
session['user_id'] = 'user_' + str(uuid.uuid4())
userid_recorder[user_id+'&'+path] = session['user_id']
# 在上层 目录下创建一个名为 user_id_path 的文件夹
path_dir = os.path.join(parent_dir, user_id, path)
os.makedirs(path_dir, exist_ok=True)
# 在此文件夹内部创建一个.config文件并写入 user_id=user_id\n path=path
config_path = os.path.join(path_dir, '.config')
with open(config_path, 'w') as f:
f.write(f"user_id={user_id}\npath={path}")
return render_template('index.html', user_id=user_id, path=path)
@app.route('/vscode_data', methods=['POST'])
def vscode_data():
data = request.json
config = data['config']
realtime_response(config,data)
print(f"Received data from VSCode: {data}")
return jsonify({"status": "success", "received": data})
@app.route('/get_session')
def get_session():
user_session = session.get('user_id', 'default_session')
return jsonify({"session": user_session})
if __name__ == '__main__':
socketio.run(app, host='0.0.0.0', port=5500)

View File

@@ -1,51 +0,0 @@
import time
class BackBoardManager:
def __init__(self):
self.backboards = {} # user_id: Backboard
def add_backboard(self, user_id, folder):
self.backboards[user_id] = Backboard(user_id, folder)
def get_backboard(self, user_id):
if user_id not in self.backboards:
return None
return self.backboards[user_id]
class Backboard:
def __init__(self, user_id, folder):
self.user_id = user_id
self.folder = folder
self.create_time = time.time()
self.enter_chapter_time = time.time()
def next_chapter(self):
self.enter_chapter_time = time.time()
def get_info_prompt(self):
return f"###Global Info:###\n\
User is {self.user_id}\n\
User's total study time is {self.get_deltatime_mmss(self.create_time, time.time())}\n\
User's current chapter study time is {self.get_deltatime_mmss(self.enter_chapter_time, time.time())}\n\
\n\n\
"
def get_deltatime_mmss(self, start_time, end_time):
elapsed_time = end_time - start_time
hours = int(elapsed_time // 3600)
minutes = int((elapsed_time % 3600) // 60)
seconds = int(elapsed_time % 60)
return f"{hours:02d}:{minutes:02d}:{seconds:02d}"

View File

@@ -1 +0,0 @@
2024-11-14 21:57:23.583 | INFO | agentscope.models:read_model_configs:186 - Load configs for model wrapper: openai_cfg

View File

@@ -1,7 +0,0 @@
{
"project": "pGMDpY",
"name": "1j41on",
"run_id": "run_20241114-220215_1j41on",
"timestamp": "2024-11-14 22:02:15",
"pid": 24013
}

View File

@@ -1,184 +0,0 @@
from flask import Flask, session, request, jsonify, render_template, send_from_directory
from flask_cors import CORS
from flask_socketio import SocketIO, join_room, emit
import markdown
import os
import uuid
import shutil
import sys
import json
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(0, parent_dir)
current_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '.'))
sys.path.insert(0, current_dir)
from AlgoriAgent.projects.algoriAgent.agent_manager import AgentManager
app = Flask(__name__)
app.secret_key = 'cakebaker'
# 配置 CORS
CORS(app, resources={r"/*": {"origins": "http://localhost:9888"}}, supports_credentials=True)
userid_recorder = {} # user_id&path -> session['user_id']
'''
Backboard
'''
from backboardManager import BackBoardManager
backboard_manager = BackBoardManager()
@app.route('/backboard')
def backboard():
return jsonify({'status': 'success'})
'''
Agent and Chat
'''
socketio = SocketIO(app, cors_allowed_origins="*")
agent_manager = AgentManager()
def realtime_response(config, realtime_action):
print("config"+str(config))
print("realtime_action"+str(realtime_action))
pass
@socketio.on('connect')
def handle_connect():
user = request.args.get('username')
folder_name = request.args.get('folder')
user_id = userid_recorder[user+'&'+folder_name]
session['user_id'] = user_id
print(f'User connected with session user_id: {user_id}')
# 从markdown、markdown_prompts、score_prompts中各读取数据folder.md并进行new_agent
with open(f'books/markdown/{folder_name}.md','r') as fmd,\
open(f'books/markdown_prompts/{folder_name}.md','r')as fmdp,\
open(f'books/score_prompts/{folder_name}.md','r') as fsp:
markdown = fmd.read()
markdown_prompts = fmdp.read()
score_prompts = fsp.read()
print('-----------------------')
print(user_id)
user_id, agent = agent_manager.new_agent(markdown, markdown_prompts, score_prompts, id=user_id)
join_room(user_id) # 将该用户加入以user_id为名的room
# 当接收到前端的消息时,触发此事件
@socketio.on('send_message')
def handle_message(data):
print(f"Message from client: {data}")
id = session.get('user_id')
# 构造回复消息
res = agent_manager.invoke(id, data)
reply = f"AI: {res.content['speak']}"
# 将回复发送回前端
emit('receive_message', reply)
'''
Markdown to HTML
'''
# 配置文件路径
MARKDOWN_DIR = 'books/markdown' # 存放 markdown 文件的文件夹
STATIC_DIR = 'static' # 存放生成的 HTML 和图片资源的文件夹
IMAGE_DIR = 'image' # 图片资源相对于 markdown 的位置
@app.route('/<filename>-markdown', methods=['GET'])
def convert_md(filename):
md_file_path = os.path.join(MARKDOWN_DIR, f'{filename}.md')
if not os.path.exists(md_file_path):
return jsonify({'error': 'Markdown file not found'}), 404
# 读取 markdown 文件内容
with open(md_file_path, 'r', encoding='utf-8') as file:
md_content = file.read()
# 将 markdown 转换为 HTML
html_content = markdown.markdown(md_content)
# 插入 CSS 样式,限制图片最大宽度为 100%,高度自动调整
html_with_styles = f"""
<html>
<head>
<style>
img {{
max-width: 100%;
height: auto;
}}
</style>
</head>
<body>
{html_content}
</body>
</html>
"""
# 保存 HTML 文件到 static 文件夹
html_output_path = os.path.join(STATIC_DIR, f'{filename}.html')
with open(html_output_path, 'w', encoding='utf-8') as html_file:
html_file.write(html_with_styles)
# 处理图片资源,将 image/xxx 文件夹拷贝到 static/image/xxx
image_source_dir = os.path.join(MARKDOWN_DIR, IMAGE_DIR, filename)
image_target_dir = os.path.join(STATIC_DIR, IMAGE_DIR, filename)
print(f"Copying image resources from {image_source_dir} to {image_target_dir}")
if os.path.exists(image_source_dir):
# 确保 static/image/xxx 目录存在
if not os.path.exists(image_target_dir):
os.makedirs(image_target_dir)
# 拷贝图片资源
for image_file in os.listdir(image_source_dir):
full_image_file_path = os.path.join(image_source_dir, image_file)
if os.path.isfile(full_image_file_path):
shutil.copy(full_image_file_path, image_target_dir)
return jsonify({'html_url': f'/static/{filename}.html'})
# 静态文件HTML 和图片资源)的访问
@app.route('/static/<path:filename>')
def serve_static(filename):
return send_from_directory(STATIC_DIR, filename)
'''
Vscode
'''
@app.route('/desktop/<user_id>/<path>')
def hello_world(user_id, path):
if 'user_id' not in session:
session['user_id'] = 'user_' + str(uuid.uuid4())
userid_recorder[user_id+'&'+path] = session['user_id']
# 在上层 目录下创建一个名为 user_id_path 的文件夹
path_dir = os.path.join(parent_dir, user_id, path)
os.makedirs(path_dir, exist_ok=True)
# 在此文件夹内部创建一个.config文件并写入 user_id=user_id\n path=path
config_path = os.path.join(path_dir, '.config')
with open(config_path, 'w') as f:
f.write(f"user_id={user_id}\npath={path}")
return render_template('index.html', user_id=user_id, path=path)
@app.route('/vscode_data', methods=['POST'])
def vscode_data():
data = request.json
config = data['config']
realtime_response(config,data)
print(f"Received data from VSCode: {data}")
return jsonify({"status": "success", "received": data})
@app.route('/get_session')
def get_session():
user_session = session.get('user_id', 'default_session')
return jsonify({"session": user_session})
if __name__ == '__main__':
socketio.run(app, host='0.0.0.0', port=5500)

View File

@@ -1,51 +0,0 @@
import time
class BackBoardManager:
def __init__(self):
self.backboards = {} # user_id: Backboard
def add_backboard(self, user_id, folder):
self.backboards[user_id] = Backboard(user_id, folder)
def get_backboard(self, user_id):
if user_id not in self.backboards:
return None
return self.backboards[user_id]
class Backboard:
def __init__(self, user_id, folder):
self.user_id = user_id
self.folder = folder
self.create_time = time.time()
self.enter_chapter_time = time.time()
def next_chapter(self):
self.enter_chapter_time = time.time()
def get_info_prompt(self):
return f"###Global Info:###\n\
User is {self.user_id}\n\
User's total study time is {self.get_deltatime_mmss(self.create_time, time.time())}\n\
User's current chapter study time is {self.get_deltatime_mmss(self.enter_chapter_time, time.time())}\n\
\n\n\
"
def get_deltatime_mmss(self, start_time, end_time):
elapsed_time = end_time - start_time
hours = int(elapsed_time // 3600)
minutes = int((elapsed_time % 3600) // 60)
seconds = int(elapsed_time % 60)
return f"{hours:02d}:{minutes:02d}:{seconds:02d}"

View File

@@ -1 +0,0 @@
2024-11-14 22:02:22.004 | INFO | agentscope.models:read_model_configs:186 - Load configs for model wrapper: openai_cfg

View File

@@ -1,7 +0,0 @@
{
"project": "GMuxD5",
"name": "9vj7vr",
"run_id": "run_20241114-220531_9vj7vr",
"timestamp": "2024-11-14 22:05:31",
"pid": 25780
}

View File

@@ -1,184 +0,0 @@
from flask import Flask, session, request, jsonify, render_template, send_from_directory
from flask_cors import CORS
from flask_socketio import SocketIO, join_room, emit
import markdown
import os
import uuid
import shutil
import sys
import json
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(0, parent_dir)
current_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '.'))
sys.path.insert(0, current_dir)
from AlgoriAgent.projects.algoriAgent.agent_manager import AgentManager
app = Flask(__name__)
app.secret_key = 'cakebaker'
# 配置 CORS
CORS(app, resources={r"/*": {"origins": "http://localhost:9888"}}, supports_credentials=True)
userid_recorder = {} # user_id&path -> session['user_id']
'''
Backboard
'''
from backboardManager import BackBoardManager
backboard_manager = BackBoardManager()
@app.route('/backboard')
def backboard():
return jsonify({'status': 'success'})
'''
Agent and Chat
'''
socketio = SocketIO(app, cors_allowed_origins="*")
agent_manager = AgentManager()
def realtime_response(config, realtime_action):
print("config"+str(config))
print("realtime_action"+str(realtime_action))
pass
@socketio.on('connect')
def handle_connect():
user = request.args.get('username')
folder_name = request.args.get('folder')
user_id = userid_recorder[user+'&'+folder_name]
session['user_id'] = user_id
print(f'User connected with session user_id: {user_id}')
# 从markdown、markdown_prompts、score_prompts中各读取数据folder.md并进行new_agent
with open(f'books/markdown/{folder_name}.md','r') as fmd,\
open(f'books/markdown_prompts/{folder_name}.md','r')as fmdp,\
open(f'books/score_prompts/{folder_name}.md','r') as fsp:
markdown = fmd.read()
markdown_prompts = fmdp.read()
score_prompts = fsp.read()
print('-----------------------')
print(user_id)
user_id, agent = agent_manager.new_agent(markdown, markdown_prompts, score_prompts, id=user_id)
join_room(user_id) # 将该用户加入以user_id为名的room
# 当接收到前端的消息时,触发此事件
@socketio.on('send_message')
def handle_message(data):
print(f"Message from client: {data}")
id = session.get('user_id')
# 构造回复消息
res = agent_manager.invoke(id, data)
reply = f"AI: {res.content['speak']}"
# 将回复发送回前端
emit('receive_message', reply)
'''
Markdown to HTML
'''
# 配置文件路径
MARKDOWN_DIR = 'books/markdown' # 存放 markdown 文件的文件夹
STATIC_DIR = 'static' # 存放生成的 HTML 和图片资源的文件夹
IMAGE_DIR = 'image' # 图片资源相对于 markdown 的位置
@app.route('/<filename>-markdown', methods=['GET'])
def convert_md(filename):
md_file_path = os.path.join(MARKDOWN_DIR, f'{filename}.md')
if not os.path.exists(md_file_path):
return jsonify({'error': 'Markdown file not found'}), 404
# 读取 markdown 文件内容
with open(md_file_path, 'r', encoding='utf-8') as file:
md_content = file.read()
# 将 markdown 转换为 HTML
html_content = markdown.markdown(md_content)
# 插入 CSS 样式,限制图片最大宽度为 100%,高度自动调整
html_with_styles = f"""
<html>
<head>
<style>
img {{
max-width: 100%;
height: auto;
}}
</style>
</head>
<body>
{html_content}
</body>
</html>
"""
# 保存 HTML 文件到 static 文件夹
html_output_path = os.path.join(STATIC_DIR, f'{filename}.html')
with open(html_output_path, 'w', encoding='utf-8') as html_file:
html_file.write(html_with_styles)
# 处理图片资源,将 image/xxx 文件夹拷贝到 static/image/xxx
image_source_dir = os.path.join(MARKDOWN_DIR, IMAGE_DIR, filename)
image_target_dir = os.path.join(STATIC_DIR, IMAGE_DIR, filename)
print(f"Copying image resources from {image_source_dir} to {image_target_dir}")
if os.path.exists(image_source_dir):
# 确保 static/image/xxx 目录存在
if not os.path.exists(image_target_dir):
os.makedirs(image_target_dir)
# 拷贝图片资源
for image_file in os.listdir(image_source_dir):
full_image_file_path = os.path.join(image_source_dir, image_file)
if os.path.isfile(full_image_file_path):
shutil.copy(full_image_file_path, image_target_dir)
return jsonify({'html_url': f'/static/{filename}.html'})
# 静态文件HTML 和图片资源)的访问
@app.route('/static/<path:filename>')
def serve_static(filename):
return send_from_directory(STATIC_DIR, filename)
'''
Vscode
'''
@app.route('/desktop/<user_id>/<path>')
def hello_world(user_id, path):
if 'user_id' not in session:
session['user_id'] = 'user_' + str(uuid.uuid4())
userid_recorder[user_id+'&'+path] = session['user_id']
# 在上层 目录下创建一个名为 user_id_path 的文件夹
path_dir = os.path.join(parent_dir, user_id, path)
os.makedirs(path_dir, exist_ok=True)
# 在此文件夹内部创建一个.config文件并写入 user_id=user_id\n path=path
config_path = os.path.join(path_dir, '.config')
with open(config_path, 'w') as f:
f.write(f"user_id={user_id}\npath={path}")
return render_template('index.html', user_id=user_id, path=path)
@app.route('/vscode_data', methods=['POST'])
def vscode_data():
data = request.json
config = data['config']
realtime_response(config,data)
print(f"Received data from VSCode: {data}")
return jsonify({"status": "success", "received": data})
@app.route('/get_session')
def get_session():
user_session = session.get('user_id', 'default_session')
return jsonify({"session": user_session})
if __name__ == '__main__':
socketio.run(app, host='0.0.0.0', port=5500)

View File

@@ -1,51 +0,0 @@
import time
class BackBoardManager:
def __init__(self):
self.backboards = {} # user_id: Backboard
def add_backboard(self, user_id, folder):
self.backboards[user_id] = Backboard(user_id, folder)
def get_backboard(self, user_id):
if user_id not in self.backboards:
return None
return self.backboards[user_id]
class Backboard:
def __init__(self, user_id, folder):
self.user_id = user_id
self.folder = folder
self.create_time = time.time()
self.enter_chapter_time = time.time()
def next_chapter(self):
self.enter_chapter_time = time.time()
def get_info_prompt(self):
return f"###Global Info:###\n\
User is {self.user_id}\n\
User's total study time is {self.get_deltatime_mmss(self.create_time, time.time())}\n\
User's current chapter study time is {self.get_deltatime_mmss(self.enter_chapter_time, time.time())}\n\
\n\n\
"
def get_deltatime_mmss(self, start_time, end_time):
elapsed_time = end_time - start_time
hours = int(elapsed_time // 3600)
minutes = int((elapsed_time % 3600) // 60)
seconds = int(elapsed_time % 60)
return f"{hours:02d}:{minutes:02d}:{seconds:02d}"

View File

@@ -1 +0,0 @@
2024-11-14 22:05:42.392 | INFO | agentscope.models:read_model_configs:186 - Load configs for model wrapper: openai_cfg

View File

@@ -1,7 +0,0 @@
{
"project": "9nK6ES",
"name": "a9u1xe",
"run_id": "run_20241114-221323_a9u1xe",
"timestamp": "2024-11-14 22:13:23",
"pid": 29558
}

View File

@@ -1,184 +0,0 @@
from flask import Flask, session, request, jsonify, render_template, send_from_directory
from flask_cors import CORS
from flask_socketio import SocketIO, join_room, emit
import markdown
import os
import uuid
import shutil
import sys
import json
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(0, parent_dir)
current_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '.'))
sys.path.insert(0, current_dir)
from AlgoriAgent.projects.algoriAgent.agent_manager import AgentManager
app = Flask(__name__)
app.secret_key = 'cakebaker'
# 配置 CORS
CORS(app, resources={r"/*": {"origins": "http://localhost:9888"}}, supports_credentials=True)
userid_recorder = {} # user_id&path -> session['user_id']
'''
Backboard
'''
from backboardManager import BackBoardManager
backboard_manager = BackBoardManager()
@app.route('/backboard')
def backboard():
return jsonify({'status': 'success'})
'''
Agent and Chat
'''
socketio = SocketIO(app, cors_allowed_origins="*")
agent_manager = AgentManager()
def realtime_response(config, realtime_action):
print("config"+str(config))
print("realtime_action"+str(realtime_action))
pass
@socketio.on('connect')
def handle_connect():
user = request.args.get('username')
folder_name = request.args.get('folder')
user_id = userid_recorder[user+'&'+folder_name]
session['user_id'] = user_id
print(f'User connected with session user_id: {user_id}')
# 从markdown、markdown_prompts、score_prompts中各读取数据folder.md并进行new_agent
with open(f'books/markdown/{folder_name}.md','r') as fmd,\
open(f'books/markdown_prompts/{folder_name}.md','r')as fmdp,\
open(f'books/score_prompts/{folder_name}.md','r') as fsp:
markdown = fmd.read()
markdown_prompts = fmdp.read()
score_prompts = fsp.read()
print('-----------------------')
print(user_id)
user_id, agent = agent_manager.new_agent(markdown, markdown_prompts, score_prompts, id=user_id)
join_room(user_id) # 将该用户加入以user_id为名的room
# 当接收到前端的消息时,触发此事件
@socketio.on('send_message')
def handle_message(data):
print(f"Message from client: {data}")
id = session.get('user_id')
# 构造回复消息
res = agent_manager.invoke(id, data)
reply = f"AI: {res.content['speak']}"
# 将回复发送回前端
emit('receive_message', reply)
'''
Markdown to HTML
'''
# 配置文件路径
MARKDOWN_DIR = 'books/markdown' # 存放 markdown 文件的文件夹
STATIC_DIR = 'static' # 存放生成的 HTML 和图片资源的文件夹
IMAGE_DIR = 'image' # 图片资源相对于 markdown 的位置
@app.route('/<filename>-markdown', methods=['GET'])
def convert_md(filename):
md_file_path = os.path.join(MARKDOWN_DIR, f'{filename}.md')
if not os.path.exists(md_file_path):
return jsonify({'error': 'Markdown file not found'}), 404
# 读取 markdown 文件内容
with open(md_file_path, 'r', encoding='utf-8') as file:
md_content = file.read()
# 将 markdown 转换为 HTML
html_content = markdown.markdown(md_content)
# 插入 CSS 样式,限制图片最大宽度为 100%,高度自动调整
html_with_styles = f"""
<html>
<head>
<style>
img {{
max-width: 100%;
height: auto;
}}
</style>
</head>
<body>
{html_content}
</body>
</html>
"""
# 保存 HTML 文件到 static 文件夹
html_output_path = os.path.join(STATIC_DIR, f'{filename}.html')
with open(html_output_path, 'w', encoding='utf-8') as html_file:
html_file.write(html_with_styles)
# 处理图片资源,将 image/xxx 文件夹拷贝到 static/image/xxx
image_source_dir = os.path.join(MARKDOWN_DIR, IMAGE_DIR, filename)
image_target_dir = os.path.join(STATIC_DIR, IMAGE_DIR, filename)
print(f"Copying image resources from {image_source_dir} to {image_target_dir}")
if os.path.exists(image_source_dir):
# 确保 static/image/xxx 目录存在
if not os.path.exists(image_target_dir):
os.makedirs(image_target_dir)
# 拷贝图片资源
for image_file in os.listdir(image_source_dir):
full_image_file_path = os.path.join(image_source_dir, image_file)
if os.path.isfile(full_image_file_path):
shutil.copy(full_image_file_path, image_target_dir)
return jsonify({'html_url': f'/static/{filename}.html'})
# 静态文件HTML 和图片资源)的访问
@app.route('/static/<path:filename>')
def serve_static(filename):
return send_from_directory(STATIC_DIR, filename)
'''
Vscode
'''
@app.route('/desktop/<user_id>/<path>')
def hello_world(user_id, path):
if 'user_id' not in session:
session['user_id'] = 'user_' + str(uuid.uuid4())
userid_recorder[user_id+'&'+path] = session['user_id']
# 在上层 目录下创建一个名为 user_id_path 的文件夹
path_dir = os.path.join(parent_dir, user_id, path)
os.makedirs(path_dir, exist_ok=True)
# 在此文件夹内部创建一个.config文件并写入 user_id=user_id\n path=path
config_path = os.path.join(path_dir, '.config')
with open(config_path, 'w') as f:
f.write(f"user_id={user_id}\npath={path}")
return render_template('index.html', user_id=user_id, path=path)
@app.route('/vscode_data', methods=['POST'])
def vscode_data():
data = request.json
config = data['config']
realtime_response(config,data)
print(f"Received data from VSCode: {data}")
return jsonify({"status": "success", "received": data})
@app.route('/get_session')
def get_session():
user_session = session.get('user_id', 'default_session')
return jsonify({"session": user_session})
if __name__ == '__main__':
socketio.run(app, host='0.0.0.0', port=5500)

View File

@@ -1,51 +0,0 @@
import time
class BackBoardManager:
def __init__(self):
self.backboards = {} # user_id: Backboard
def add_backboard(self, user_id, folder):
self.backboards[user_id] = Backboard(user_id, folder)
def get_backboard(self, user_id):
if user_id not in self.backboards:
return None
return self.backboards[user_id]
class Backboard:
def __init__(self, user_id, folder):
self.user_id = user_id
self.folder = folder
self.create_time = time.time()
self.enter_chapter_time = time.time()
def next_chapter(self):
self.enter_chapter_time = time.time()
def get_info_prompt(self):
return f"###Global Info:###\n\
User is {self.user_id}\n\
User's total study time is {self.get_deltatime_mmss(self.create_time, time.time())}\n\
User's current chapter study time is {self.get_deltatime_mmss(self.enter_chapter_time, time.time())}\n\
\n\n\
"
def get_deltatime_mmss(self, start_time, end_time):
elapsed_time = end_time - start_time
hours = int(elapsed_time // 3600)
minutes = int((elapsed_time % 3600) // 60)
seconds = int(elapsed_time % 60)
return f"{hours:02d}:{minutes:02d}:{seconds:02d}"

View File

@@ -1 +0,0 @@
2024-11-14 22:13:39.282 | INFO | agentscope.models:read_model_configs:186 - Load configs for model wrapper: openai_cfg

View File

@@ -1,7 +0,0 @@
{
"project": "Dyp9cf",
"name": "rqje7y",
"run_id": "run_20241114-221631_rqje7y",
"timestamp": "2024-11-14 22:16:31",
"pid": 31289
}

View File

@@ -1,184 +0,0 @@
from flask import Flask, session, request, jsonify, render_template, send_from_directory
from flask_cors import CORS
from flask_socketio import SocketIO, join_room, emit
import markdown
import os
import uuid
import shutil
import sys
import json
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(0, parent_dir)
current_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '.'))
sys.path.insert(0, current_dir)
from AlgoriAgent.projects.algoriAgent.agent_manager import AgentManager
app = Flask(__name__)
app.secret_key = 'cakebaker'
# 配置 CORS
CORS(app, resources={r"/*": {"origins": "http://localhost:9888"}}, supports_credentials=True)
userid_recorder = {} # user_id&path -> session['user_id']
'''
Backboard
'''
from backboardManager import BackBoardManager
backboard_manager = BackBoardManager()
@app.route('/backboard')
def backboard():
return jsonify({'status': 'success'})
'''
Agent and Chat
'''
socketio = SocketIO(app, cors_allowed_origins="*")
agent_manager = AgentManager()
def realtime_response(config, realtime_action):
print("config"+str(config))
print("realtime_action"+str(realtime_action))
pass
@socketio.on('connect')
def handle_connect():
user = request.args.get('username')
folder_name = request.args.get('folder')
user_id = userid_recorder[user+'&'+folder_name]
session['user_id'] = user_id
print(f'User connected with session user_id: {user_id}')
# 从markdown、markdown_prompts、score_prompts中各读取数据folder.md并进行new_agent
with open(f'books/markdown/{folder_name}.md','r') as fmd,\
open(f'books/markdown_prompts/{folder_name}.md','r')as fmdp,\
open(f'books/score_prompts/{folder_name}.md','r') as fsp:
markdown = fmd.read()
markdown_prompts = fmdp.read()
score_prompts = fsp.read()
print('-----------------------')
print(user_id)
user_id, agent = agent_manager.new_agent(markdown, markdown_prompts, score_prompts, id=user_id)
join_room(user_id) # 将该用户加入以user_id为名的room
# 当接收到前端的消息时,触发此事件
@socketio.on('send_message')
def handle_message(data):
print(f"Message from client: {data}")
id = session.get('user_id')
# 构造回复消息
res = agent_manager.invoke(id, data)
reply = f"AI: {res.content['speak']}"
# 将回复发送回前端
emit('receive_message', reply)
'''
Markdown to HTML
'''
# 配置文件路径
MARKDOWN_DIR = 'books/markdown' # 存放 markdown 文件的文件夹
STATIC_DIR = 'static' # 存放生成的 HTML 和图片资源的文件夹
IMAGE_DIR = 'image' # 图片资源相对于 markdown 的位置
@app.route('/<filename>-markdown', methods=['GET'])
def convert_md(filename):
md_file_path = os.path.join(MARKDOWN_DIR, f'{filename}.md')
if not os.path.exists(md_file_path):
return jsonify({'error': 'Markdown file not found'}), 404
# 读取 markdown 文件内容
with open(md_file_path, 'r', encoding='utf-8') as file:
md_content = file.read()
# 将 markdown 转换为 HTML
html_content = markdown.markdown(md_content)
# 插入 CSS 样式,限制图片最大宽度为 100%,高度自动调整
html_with_styles = f"""
<html>
<head>
<style>
img {{
max-width: 100%;
height: auto;
}}
</style>
</head>
<body>
{html_content}
</body>
</html>
"""
# 保存 HTML 文件到 static 文件夹
html_output_path = os.path.join(STATIC_DIR, f'{filename}.html')
with open(html_output_path, 'w', encoding='utf-8') as html_file:
html_file.write(html_with_styles)
# 处理图片资源,将 image/xxx 文件夹拷贝到 static/image/xxx
image_source_dir = os.path.join(MARKDOWN_DIR, IMAGE_DIR, filename)
image_target_dir = os.path.join(STATIC_DIR, IMAGE_DIR, filename)
print(f"Copying image resources from {image_source_dir} to {image_target_dir}")
if os.path.exists(image_source_dir):
# 确保 static/image/xxx 目录存在
if not os.path.exists(image_target_dir):
os.makedirs(image_target_dir)
# 拷贝图片资源
for image_file in os.listdir(image_source_dir):
full_image_file_path = os.path.join(image_source_dir, image_file)
if os.path.isfile(full_image_file_path):
shutil.copy(full_image_file_path, image_target_dir)
return jsonify({'html_url': f'/static/{filename}.html'})
# 静态文件HTML 和图片资源)的访问
@app.route('/static/<path:filename>')
def serve_static(filename):
return send_from_directory(STATIC_DIR, filename)
'''
Vscode
'''
@app.route('/desktop/<user_id>/<path>')
def hello_world(user_id, path):
if 'user_id' not in session:
session['user_id'] = 'user_' + str(uuid.uuid4())
userid_recorder[user_id+'&'+path] = session['user_id']
# 在上层 目录下创建一个名为 user_id_path 的文件夹
path_dir = os.path.join(parent_dir, user_id, path)
os.makedirs(path_dir, exist_ok=True)
# 在此文件夹内部创建一个.config文件并写入 user_id=user_id\n path=path
config_path = os.path.join(path_dir, '.config')
with open(config_path, 'w') as f:
f.write(f"user_id={user_id}\npath={path}")
return render_template('index.html', user_id=user_id, path=path)
@app.route('/vscode_data', methods=['POST'])
def vscode_data():
data = request.json
config = data['config']
realtime_response(config,data)
print(f"Received data from VSCode: {data}")
return jsonify({"status": "success", "received": data})
@app.route('/get_session')
def get_session():
user_session = session.get('user_id', 'default_session')
return jsonify({"session": user_session})
if __name__ == '__main__':
socketio.run(app, host='0.0.0.0', port=5500)

View File

@@ -1,51 +0,0 @@
import time
class BackBoardManager:
def __init__(self):
self.backboards = {} # user_id: Backboard
def add_backboard(self, user_id, folder):
self.backboards[user_id] = Backboard(user_id, folder)
def get_backboard(self, user_id):
if user_id not in self.backboards:
return None
return self.backboards[user_id]
class Backboard:
def __init__(self, user_id, folder):
self.user_id = user_id
self.folder = folder
self.create_time = time.time()
self.enter_chapter_time = time.time()
def next_chapter(self):
self.enter_chapter_time = time.time()
def get_info_prompt(self):
return f"###Global Info:###\n\
User is {self.user_id}\n\
User's total study time is {self.get_deltatime_mmss(self.create_time, time.time())}\n\
User's current chapter study time is {self.get_deltatime_mmss(self.enter_chapter_time, time.time())}\n\
\n\n\
"
def get_deltatime_mmss(self, start_time, end_time):
elapsed_time = end_time - start_time
hours = int(elapsed_time // 3600)
minutes = int((elapsed_time % 3600) // 60)
seconds = int(elapsed_time % 60)
return f"{hours:02d}:{minutes:02d}:{seconds:02d}"

View File

@@ -1,9 +0,0 @@
{"id": "634c922077c342c297ab1eccea71c77e", "timestamp": "2024-11-14 22:17:54", "name": "assistant", "content": "##################### ITER 1, STEP 1: REASONING ######################", "role": "assistant", "url": null, "metadata": null}
{"id": "d08bda7bbbd748f9875913304466e4bd", "timestamp": "2024-11-14 22:17:54", "name": "system", "content": "", "role": "system", "url": null, "metadata": null}
{"id": "aec083afdf9b4d47b48b780ef9dc1b3d", "timestamp": "2024-11-14 22:17:54", "name": "system", "content": "Respond a JSON dictionary in a markdown's fenced code block as follows:\n```json\n{\"thought\": \"what you thought\", \"speak\": \"what you speak\", \"function\": \"[{\\\"name\\\": \\\"{function name}\\\", \\\"arguments\\\": {\\\"{argument1 name}\\\": xxx, \\\"{argument2 name}\\\": xxx}}]\"}\n```\n ####", "role": "system", "url": null, "metadata": null}
{"id": "aad82dbb9b8640139dc08f854c269259", "timestamp": "2024-11-14 22:17:54", "name": "assistant", "content": "################################Prompt################################", "role": "assistant", "url": null, "metadata": null}
{"id": "1a3eb9af6c4f4cbebb0e3ed480bd69cc", "timestamp": "2024-11-14 22:17:54", "name": "assistant", "content": "你好\n", "role": "assistant", "url": null, "metadata": null}
{"id": "311ab2b2b08649ae81124ee10901d1d8", "timestamp": "2024-11-14 22:17:58", "name": "assistant", "content": "############################Result Parsed#############################", "role": "assistant", "url": null, "metadata": null}
{"id": "737dcdff4adf441d86532e25d4d9ee32", "timestamp": "2024-11-14 22:17:58", "name": "assistant", "content": "{'thought': 'The student is greeting, indicating they are ready to learn about binary search.', 'speak': '你好今天我们将学习有关二分查找的基本概念。如果你有问题可以随时问我。我们先来思考一下1到4000之间的区间最差情况下需要猜测几次', 'function': []}", "role": "assistant", "url": null, "metadata": null}
{"id": "5dd3c37d27d544928ba8f065b3fedd4a", "timestamp": "2024-11-14 22:17:58", "name": "assistant", "content": "################################Speak#################################", "role": "assistant", "url": null, "metadata": null}
{"id": "69861e706dc941b1b60626af8b049ee5", "timestamp": "2024-11-14 22:17:58", "name": "assistant", "content": {"thought": "The student is greeting, indicating they are ready to learn about binary search.", "speak": "你好今天我们将学习有关二分查找的基本概念。如果你有问题可以随时问我。我们先来思考一下1到4000之间的区间最差情况下需要猜测几次", "function": []}, "role": "assistant", "url": null, "metadata": null}

View File

@@ -1,23 +0,0 @@
2024-11-14 22:16:42.016 | INFO | agentscope.models:read_model_configs:186 - Load configs for model wrapper: openai_cfg
2024-11-14 22:16:49.610 | INFO | agentscope.models.model:__init__:201 - Initialize model by configuration [openai_cfg]
2024-11-14 22:16:49.626 | WARNING | agentscope.models.openai_model:__init__:83 - fail to get max_length for gpt-4o-mini: 'Model [gpt-4o-mini] not found in OPENAI_MAX_LENGTH. The last updated date is 20231212'
2024-11-14 22:16:49.626 | INFO | agentscope.utils.monitor:register_budget:609 - set budget None to gpt-4o-mini
2024-11-14 22:16:49.627 | WARNING | agentscope.utils.monitor:register_budget:639 - Calculate budgets for model [gpt-4o-mini] is not supported
2024-11-14 22:16:49.642 | INFO | agentscope.utils.monitor:register:417 - Register metric [gpt-4o-mini.call_counter] to SqliteMonitor with unit [times] and quota [None]
2024-11-14 22:16:49.666 | INFO | agentscope.utils.monitor:register:417 - Register metric [gpt-4o-mini.prompt_tokens] to SqliteMonitor with unit [token] and quota [None]
2024-11-14 22:16:49.695 | INFO | agentscope.utils.monitor:register:417 - Register metric [gpt-4o-mini.completion_tokens] to SqliteMonitor with unit [token] and quota [None]
2024-11-14 22:16:49.721 | INFO | agentscope.utils.monitor:register:417 - Register metric [gpt-4o-mini.total_tokens] to SqliteMonitor with unit [token] and quota [None]
assistant: ##################### ITER 1, STEP 1: REASONING ######################
system:
system: Respond a JSON dictionary in a markdown's fenced code block as follows:
```json
{"thought": "what you thought", "speak": "what you speak", "function": "[{\"name\": \"{function name}\", \"arguments\": {\"{argument1 name}\": xxx, \"{argument2 name}\": xxx}}]"}
```
####
assistant: ################################Prompt################################
assistant: 你好
assistant: ############################Result Parsed#############################
assistant: {'thought': 'The student is greeting, indicating they are ready to learn about binary search.', 'speak': '你好今天我们将学习有关二分查找的基本概念。如果你有问题可以随时问我。我们先来思考一下1到4000之间的区间最差情况下需要猜测几次', 'function': []}
assistant: ################################Speak#################################
assistant: {'thought': 'The student is greeting, indicating they are ready to learn about binary search.', 'speak': '你好今天我们将学习有关二分查找的基本概念。如果你有问题可以随时问我。我们先来思考一下1到4000之间的区间最差情况下需要猜测几次', 'function': []}

View File

@@ -1,7 +0,0 @@
{
"project": "5tV7eR",
"name": "1b3pyz",
"run_id": "run_20241122-165210_1b3pyz",
"timestamp": "2024-11-22 16:52:10",
"pid": 10044
}

View File

@@ -1,184 +0,0 @@
from flask import Flask, session, request, jsonify, render_template, send_from_directory
from flask_cors import CORS
from flask_socketio import SocketIO, join_room, emit
import markdown
import os
import uuid
import shutil
import sys
import json
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(0, parent_dir)
current_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '.'))
sys.path.insert(0, current_dir)
from AlgoriAgent.projects.algoriAgent.agent_manager import AgentManager
app = Flask(__name__)
app.secret_key = 'cakebaker'
# 配置 CORS
CORS(app, resources={r"/*": {"origins": "http://localhost:9888"}}, supports_credentials=True)
userid_recorder = {} # user_id&path -> session['user_id']
'''
Backboard
'''
from backboardManager import BackBoardManager
backboard_manager = BackBoardManager()
@app.route('/backboard')
def backboard():
return jsonify({'status': 'success'})
'''
Agent and Chat
'''
socketio = SocketIO(app, cors_allowed_origins="*")
agent_manager = AgentManager()
def realtime_response(config, realtime_action):
print("config"+str(config))
print("realtime_action"+str(realtime_action))
pass
@socketio.on('connect')
def handle_connect():
user = request.args.get('username')
folder_name = request.args.get('folder')
user_id = userid_recorder[user+'&'+folder_name]
session['user_id'] = user_id
print(f'User connected with session user_id: {user_id}')
# 从markdown、markdown_prompts、score_prompts中各读取数据folder.md并进行new_agent
with open(f'books/markdown/{folder_name}.md','r') as fmd,\
open(f'books/markdown_prompts/{folder_name}.md','r')as fmdp,\
open(f'books/score_prompts/{folder_name}.md','r') as fsp:
markdown = fmd.read()
markdown_prompts = fmdp.read()
score_prompts = fsp.read()
print('-----------------------')
print(user_id)
user_id, agent = agent_manager.new_agent(markdown, markdown_prompts, score_prompts, id=user_id)
join_room(user_id) # 将该用户加入以user_id为名的room
# 当接收到前端的消息时,触发此事件
@socketio.on('send_message')
def handle_message(data):
print(f"Message from client: {data}")
id = session.get('user_id')
# 构造回复消息
res = agent_manager.invoke(id, data)
reply = f"AI: {res.content['speak']}"
# 将回复发送回前端
emit('receive_message', reply)
'''
Markdown to HTML
'''
# 配置文件路径
MARKDOWN_DIR = 'books/markdown' # 存放 markdown 文件的文件夹
STATIC_DIR = 'static' # 存放生成的 HTML 和图片资源的文件夹
IMAGE_DIR = 'image' # 图片资源相对于 markdown 的位置
@app.route('/<filename>-markdown', methods=['GET'])
def convert_md(filename):
md_file_path = os.path.join(MARKDOWN_DIR, f'{filename}.md')
if not os.path.exists(md_file_path):
return jsonify({'error': 'Markdown file not found'}), 404
# 读取 markdown 文件内容
with open(md_file_path, 'r', encoding='utf-8') as file:
md_content = file.read()
# 将 markdown 转换为 HTML
html_content = markdown.markdown(md_content)
# 插入 CSS 样式,限制图片最大宽度为 100%,高度自动调整
html_with_styles = f"""
<html>
<head>
<style>
img {{
max-width: 100%;
height: auto;
}}
</style>
</head>
<body>
{html_content}
</body>
</html>
"""
# 保存 HTML 文件到 static 文件夹
html_output_path = os.path.join(STATIC_DIR, f'{filename}.html')
with open(html_output_path, 'w', encoding='utf-8') as html_file:
html_file.write(html_with_styles)
# 处理图片资源,将 image/xxx 文件夹拷贝到 static/image/xxx
image_source_dir = os.path.join(MARKDOWN_DIR, IMAGE_DIR, filename)
image_target_dir = os.path.join(STATIC_DIR, IMAGE_DIR, filename)
print(f"Copying image resources from {image_source_dir} to {image_target_dir}")
if os.path.exists(image_source_dir):
# 确保 static/image/xxx 目录存在
if not os.path.exists(image_target_dir):
os.makedirs(image_target_dir)
# 拷贝图片资源
for image_file in os.listdir(image_source_dir):
full_image_file_path = os.path.join(image_source_dir, image_file)
if os.path.isfile(full_image_file_path):
shutil.copy(full_image_file_path, image_target_dir)
return jsonify({'html_url': f'/static/{filename}.html'})
# 静态文件HTML 和图片资源)的访问
@app.route('/static/<path:filename>')
def serve_static(filename):
return send_from_directory(STATIC_DIR, filename)
'''
Vscode
'''
@app.route('/desktop/<user_id>/<path>')
def hello_world(user_id, path):
if 'user_id' not in session:
session['user_id'] = 'user_' + str(uuid.uuid4())
userid_recorder[user_id+'&'+path] = session['user_id']
# 在上层 目录下创建一个名为 user_id_path 的文件夹
path_dir = os.path.join(parent_dir, user_id, path)
os.makedirs(path_dir, exist_ok=True)
# 在此文件夹内部创建一个.config文件并写入 user_id=user_id\n path=path
config_path = os.path.join(path_dir, '.config')
with open(config_path, 'w') as f:
f.write(f"user_id={user_id}\npath={path}")
return render_template('index.html', user_id=user_id, path=path)
@app.route('/vscode_data', methods=['POST'])
def vscode_data():
data = request.json
config = data['config']
realtime_response(config,data)
print(f"Received data from VSCode: {data}")
return jsonify({"status": "success", "received": data})
@app.route('/get_session')
def get_session():
user_session = session.get('user_id', 'default_session')
return jsonify({"session": user_session})
if __name__ == '__main__':
socketio.run(app, host='0.0.0.0', port=5500)

View File

@@ -1,51 +0,0 @@
import time
class BackBoardManager:
def __init__(self):
self.backboards = {} # user_id: Backboard
def add_backboard(self, user_id, folder):
self.backboards[user_id] = Backboard(user_id, folder)
def get_backboard(self, user_id):
if user_id not in self.backboards:
return None
return self.backboards[user_id]
class Backboard:
def __init__(self, user_id, folder):
self.user_id = user_id
self.folder = folder
self.create_time = time.time()
self.enter_chapter_time = time.time()
def next_chapter(self):
self.enter_chapter_time = time.time()
def get_info_prompt(self):
return f"###Global Info:###\n\
User is {self.user_id}\n\
User's total study time is {self.get_deltatime_mmss(self.create_time, time.time())}\n\
User's current chapter study time is {self.get_deltatime_mmss(self.enter_chapter_time, time.time())}\n\
\n\n\
"
def get_deltatime_mmss(self, start_time, end_time):
elapsed_time = end_time - start_time
hours = int(elapsed_time // 3600)
minutes = int((elapsed_time % 3600) // 60)
seconds = int(elapsed_time % 60)
return f"{hours:02d}:{minutes:02d}:{seconds:02d}"

View File

@@ -1,13 +0,0 @@
2024-11-22 16:52:16.843 | INFO | agentscope.models:read_model_configs:186 - Load configs for model wrapper: openai_cfg
2024-11-22 16:53:07.868 | INFO | agentscope.models.model:__init__:201 - Initialize model by configuration [openai_cfg]
2024-11-22 16:53:07.885 | WARNING | agentscope.models.openai_model:__init__:83 - fail to get max_length for gpt-4o-mini: 'Model [gpt-4o-mini] not found in OPENAI_MAX_LENGTH. The last updated date is 20231212'
2024-11-22 16:53:07.885 | INFO | agentscope.utils.monitor:register_budget:609 - set budget None to gpt-4o-mini
2024-11-22 16:53:07.885 | WARNING | agentscope.utils.monitor:register_budget:639 - Calculate budgets for model [gpt-4o-mini] is not supported
2024-11-22 16:53:07.896 | INFO | agentscope.utils.monitor:register:417 - Register metric [gpt-4o-mini.call_counter] to SqliteMonitor with unit [times] and quota [None]
2024-11-22 16:53:07.915 | INFO | agentscope.utils.monitor:register:417 - Register metric [gpt-4o-mini.prompt_tokens] to SqliteMonitor with unit [token] and quota [None]
2024-11-22 16:53:07.934 | INFO | agentscope.utils.monitor:register:417 - Register metric [gpt-4o-mini.completion_tokens] to SqliteMonitor with unit [token] and quota [None]
2024-11-22 16:53:07.953 | INFO | agentscope.utils.monitor:register:417 - Register metric [gpt-4o-mini.total_tokens] to SqliteMonitor with unit [token] and quota [None]
2024-11-22 16:56:58.801 | INFO | agentscope.models.model:__init__:201 - Initialize model by configuration [openai_cfg]
2024-11-22 16:56:58.816 | WARNING | agentscope.models.openai_model:__init__:83 - fail to get max_length for gpt-4o-mini: 'Model [gpt-4o-mini] not found in OPENAI_MAX_LENGTH. The last updated date is 20231212'
2024-11-22 16:56:58.817 | INFO | agentscope.utils.monitor:register_budget:609 - set budget None to gpt-4o-mini
2024-11-22 16:56:58.818 | WARNING | agentscope.utils.monitor:register_budget:639 - Calculate budgets for model [gpt-4o-mini] is not supported

View File

@@ -1,7 +0,0 @@
{
"project": "ZxUA2M",
"name": "vdg020",
"run_id": "run_20241122-165801_vdg020",
"timestamp": "2024-11-22 16:58:01",
"pid": 13329
}

View File

@@ -1,184 +0,0 @@
from flask import Flask, session, request, jsonify, render_template, send_from_directory
from flask_cors import CORS
from flask_socketio import SocketIO, join_room, emit
import markdown
import os
import uuid
import shutil
import sys
import json
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(0, parent_dir)
current_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '.'))
sys.path.insert(0, current_dir)
from AlgoriAgent.projects.algoriAgent.agent_manager import AgentManager
app = Flask(__name__)
app.secret_key = 'cakebaker'
# 配置 CORS
CORS(app, resources={r"/*": {"origins": "http://localhost:9888"}}, supports_credentials=True)
userid_recorder = {} # user_id&path -> session['user_id']
'''
Backboard
'''
from backboardManager import BackBoardManager
backboard_manager = BackBoardManager()
@app.route('/backboard')
def backboard():
return jsonify({'status': 'success'})
'''
Agent and Chat
'''
socketio = SocketIO(app, cors_allowed_origins="*")
agent_manager = AgentManager()
def realtime_response(config, realtime_action):
print("config"+str(config))
print("realtime_action"+str(realtime_action))
pass
@socketio.on('connect')
def handle_connect():
user = request.args.get('username')
folder_name = request.args.get('folder')
user_id = userid_recorder[user+'&'+folder_name]
session['user_id'] = user_id
print(f'User connected with session user_id: {user_id}')
# 从markdown、markdown_prompts、score_prompts中各读取数据folder.md并进行new_agent
with open(f'books/markdown/{folder_name}.md','r') as fmd,\
open(f'books/markdown_prompts/{folder_name}.md','r')as fmdp,\
open(f'books/score_prompts/{folder_name}.md','r') as fsp:
markdown = fmd.read()
markdown_prompts = fmdp.read()
score_prompts = fsp.read()
print('-----------------------')
print(user_id)
user_id, agent = agent_manager.new_agent(markdown, markdown_prompts, score_prompts, id=user_id)
join_room(user_id) # 将该用户加入以user_id为名的room
# 当接收到前端的消息时,触发此事件
@socketio.on('send_message')
def handle_message(data):
print(f"Message from client: {data}")
id = session.get('user_id')
# 构造回复消息
res = agent_manager.invoke(id, data)
reply = f"AI: {res.content['speak']}"
# 将回复发送回前端
emit('receive_message', reply)
'''
Markdown to HTML
'''
# 配置文件路径
MARKDOWN_DIR = 'books/markdown' # 存放 markdown 文件的文件夹
STATIC_DIR = 'static' # 存放生成的 HTML 和图片资源的文件夹
IMAGE_DIR = 'image' # 图片资源相对于 markdown 的位置
@app.route('/<filename>-markdown', methods=['GET'])
def convert_md(filename):
md_file_path = os.path.join(MARKDOWN_DIR, f'{filename}.md')
if not os.path.exists(md_file_path):
return jsonify({'error': 'Markdown file not found'}), 404
# 读取 markdown 文件内容
with open(md_file_path, 'r', encoding='utf-8') as file:
md_content = file.read()
# 将 markdown 转换为 HTML
html_content = markdown.markdown(md_content)
# 插入 CSS 样式,限制图片最大宽度为 100%,高度自动调整
html_with_styles = f"""
<html>
<head>
<style>
img {{
max-width: 100%;
height: auto;
}}
</style>
</head>
<body>
{html_content}
</body>
</html>
"""
# 保存 HTML 文件到 static 文件夹
html_output_path = os.path.join(STATIC_DIR, f'{filename}.html')
with open(html_output_path, 'w', encoding='utf-8') as html_file:
html_file.write(html_with_styles)
# 处理图片资源,将 image/xxx 文件夹拷贝到 static/image/xxx
image_source_dir = os.path.join(MARKDOWN_DIR, IMAGE_DIR, filename)
image_target_dir = os.path.join(STATIC_DIR, IMAGE_DIR, filename)
print(f"Copying image resources from {image_source_dir} to {image_target_dir}")
if os.path.exists(image_source_dir):
# 确保 static/image/xxx 目录存在
if not os.path.exists(image_target_dir):
os.makedirs(image_target_dir)
# 拷贝图片资源
for image_file in os.listdir(image_source_dir):
full_image_file_path = os.path.join(image_source_dir, image_file)
if os.path.isfile(full_image_file_path):
shutil.copy(full_image_file_path, image_target_dir)
return jsonify({'html_url': f'/static/{filename}.html'})
# 静态文件HTML 和图片资源)的访问
@app.route('/static/<path:filename>')
def serve_static(filename):
return send_from_directory(STATIC_DIR, filename)
'''
Vscode
'''
@app.route('/desktop/<user_id>/<path>')
def hello_world(user_id, path):
if 'user_id' not in session:
session['user_id'] = 'user_' + str(uuid.uuid4())
userid_recorder[user_id+'&'+path] = session['user_id']
# 在上层 目录下创建一个名为 user_id_path 的文件夹
path_dir = os.path.join(parent_dir, user_id, path)
os.makedirs(path_dir, exist_ok=True)
# 在此文件夹内部创建一个.config文件并写入 user_id=user_id\n path=path
config_path = os.path.join(path_dir, '.config')
with open(config_path, 'w') as f:
f.write(f"user_id={user_id}\npath={path}")
return render_template('index.html', user_id=user_id, path=path)
@app.route('/vscode_data', methods=['POST'])
def vscode_data():
data = request.json
config = data['config']
realtime_response(config,data)
print(f"Received data from VSCode: {data}")
return jsonify({"status": "success", "received": data})
@app.route('/get_session')
def get_session():
user_session = session.get('user_id', 'default_session')
return jsonify({"session": user_session})
if __name__ == '__main__':
socketio.run(app, host='0.0.0.0', port=5500)

View File

@@ -1,51 +0,0 @@
import time
class BackBoardManager:
def __init__(self):
self.backboards = {} # user_id: Backboard
def add_backboard(self, user_id, folder):
self.backboards[user_id] = Backboard(user_id, folder)
def get_backboard(self, user_id):
if user_id not in self.backboards:
return None
return self.backboards[user_id]
class Backboard:
def __init__(self, user_id, folder):
self.user_id = user_id
self.folder = folder
self.create_time = time.time()
self.enter_chapter_time = time.time()
def next_chapter(self):
self.enter_chapter_time = time.time()
def get_info_prompt(self):
return f"###Global Info:###\n\
User is {self.user_id}\n\
User's total study time is {self.get_deltatime_mmss(self.create_time, time.time())}\n\
User's current chapter study time is {self.get_deltatime_mmss(self.enter_chapter_time, time.time())}\n\
\n\n\
"
def get_deltatime_mmss(self, start_time, end_time):
elapsed_time = end_time - start_time
hours = int(elapsed_time // 3600)
minutes = int((elapsed_time % 3600) // 60)
seconds = int(elapsed_time % 60)
return f"{hours:02d}:{minutes:02d}:{seconds:02d}"

View File

@@ -1,9 +0,0 @@
{"id": "906c60e694624e90be9225ceeb24c32d", "timestamp": "2024-11-22 17:07:22", "name": "assistant", "content": "##################### ITER 1, STEP 1: REASONING ######################", "role": "assistant", "url": null, "metadata": null}
{"id": "95fd4f1910984ca3b73c83ae61b8e7b4", "timestamp": "2024-11-22 17:07:22", "name": "system", "content": "", "role": "system", "url": null, "metadata": null}
{"id": "ae1e2966378b4bd5aba7d2410488d49f", "timestamp": "2024-11-22 17:07:22", "name": "system", "content": "Respond a JSON dictionary in a markdown's fenced code block as follows:\n```json\n{\"thought\": \"what you thought\", \"speak\": \"what you speak\", \"function\": \"[{\\\"name\\\": \\\"{function name}\\\", \\\"arguments\\\": {\\\"{argument1 name}\\\": xxx, \\\"{argument2 name}\\\": xxx}}]\"}\n```\n ####", "role": "system", "url": null, "metadata": null}
{"id": "87c816f6514e422b9afe2ddea274030f", "timestamp": "2024-11-22 17:07:22", "name": "assistant", "content": "################################Prompt################################", "role": "assistant", "url": null, "metadata": null}
{"id": "fa220e3ad1db4cd7adc15ec1e39525b0", "timestamp": "2024-11-22 17:07:22", "name": "assistant", "content": "hi", "role": "assistant", "url": null, "metadata": null}
{"id": "c1dc60dfa9554247b7c8d3870d20353d", "timestamp": "2024-11-22 17:07:26", "name": "assistant", "content": "############################Result Parsed#############################", "role": "assistant", "url": null, "metadata": null}
{"id": "fdc19da0a6004c9cb4c03fbecab6b6a8", "timestamp": "2024-11-22 17:07:26", "name": "assistant", "content": "{'thought': 'The student is greeting, indicating they might be ready to discuss the current chapter.', 'speak': \"Hello! Let's focus on Chapter 1 about binary search. Do you have any questions about the guessing game scenario?\", 'function': []}", "role": "assistant", "url": null, "metadata": null}
{"id": "344dabc6a6ef40eabf8d7c88286b5ab9", "timestamp": "2024-11-22 17:07:26", "name": "assistant", "content": "################################Speak#################################", "role": "assistant", "url": null, "metadata": null}
{"id": "3d86a502943c4d63ae81ee62b5af06c1", "timestamp": "2024-11-22 17:07:26", "name": "assistant", "content": {"thought": "The student is greeting, indicating they might be ready to discuss the current chapter.", "speak": "Hello! Let's focus on Chapter 1 about binary search. Do you have any questions about the guessing game scenario?", "function": []}, "role": "assistant", "url": null, "metadata": null}

View File

@@ -1,22 +0,0 @@
2024-11-22 16:58:14.249 | INFO | agentscope.models:read_model_configs:186 - Load configs for model wrapper: openai_cfg
2024-11-22 16:58:21.157 | INFO | agentscope.models.model:__init__:201 - Initialize model by configuration [openai_cfg]
2024-11-22 16:58:21.172 | WARNING | agentscope.models.openai_model:__init__:83 - fail to get max_length for gpt-4o-mini: 'Model [gpt-4o-mini] not found in OPENAI_MAX_LENGTH. The last updated date is 20231212'
2024-11-22 16:58:21.173 | INFO | agentscope.utils.monitor:register_budget:609 - set budget None to gpt-4o-mini
2024-11-22 16:58:21.173 | WARNING | agentscope.utils.monitor:register_budget:639 - Calculate budgets for model [gpt-4o-mini] is not supported
2024-11-22 16:58:21.186 | INFO | agentscope.utils.monitor:register:417 - Register metric [gpt-4o-mini.call_counter] to SqliteMonitor with unit [times] and quota [None]
2024-11-22 16:58:21.208 | INFO | agentscope.utils.monitor:register:417 - Register metric [gpt-4o-mini.prompt_tokens] to SqliteMonitor with unit [token] and quota [None]
2024-11-22 16:58:21.233 | INFO | agentscope.utils.monitor:register:417 - Register metric [gpt-4o-mini.completion_tokens] to SqliteMonitor with unit [token] and quota [None]
2024-11-22 16:58:21.257 | INFO | agentscope.utils.monitor:register:417 - Register metric [gpt-4o-mini.total_tokens] to SqliteMonitor with unit [token] and quota [None]
assistant: ##################### ITER 1, STEP 1: REASONING ######################
system:
system: Respond a JSON dictionary in a markdown's fenced code block as follows:
```json
{"thought": "what you thought", "speak": "what you speak", "function": "[{\"name\": \"{function name}\", \"arguments\": {\"{argument1 name}\": xxx, \"{argument2 name}\": xxx}}]"}
```
####
assistant: ################################Prompt################################
assistant: hi
assistant: ############################Result Parsed#############################
assistant: {'thought': 'The student is greeting, indicating they might be ready to discuss the current chapter.', 'speak': "Hello! Let's focus on Chapter 1 about binary search. Do you have any questions about the guessing game scenario?", 'function': []}
assistant: ################################Speak#################################
assistant: {'thought': 'The student is greeting, indicating they might be ready to discuss the current chapter.', 'speak': "Hello! Let's focus on Chapter 1 about binary search. Do you have any questions about the guessing game scenario?", 'function': []}

View File

@@ -1,7 +0,0 @@
{
"project": "nXZ3hk",
"name": "5xj3ck",
"run_id": "run_20241122-171906_5xj3ck",
"timestamp": "2024-11-22 17:19:06",
"pid": 22751
}

View File

@@ -1,185 +0,0 @@
from flask import Flask, session, request, jsonify, render_template, send_from_directory
from flask_cors import CORS
from flask_socketio import SocketIO, join_room, emit
import markdown
import os
import uuid
import shutil
import sys
import json
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(0, parent_dir)
current_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '.'))
sys.path.insert(0, current_dir)
from AlgoriAgent.projects.algoriAgent.agent_manager import AgentManager
app = Flask(__name__)
app.secret_key = 'cakebaker'
# 配置 CORS
CORS(app, resources={r"/*": {"origins": "http://localhost:9888"}}, supports_credentials=True)
userid_recorder = {} # user_id&path -> session['user_id']
'''
Backboard
'''
from backboardManager import BackBoardManager
backboard_manager = BackBoardManager()
@app.route('/backboard')
def backboard():
return jsonify({'status': 'success'})
'''
Agent and Chat
'''
socketio = SocketIO(app, cors_allowed_origins="*")
agent_manager = AgentManager()
def realtime_response(config, realtime_action):
print("config"+str(config))
print("realtime_action"+str(realtime_action))
pass
@socketio.on('connect')
def handle_connect():
user = request.args.get('username')
folder_name = request.args.get('folder')
user_id = userid_recorder[user+'&'+folder_name]
session['user_id'] = user_id
print(f'User connected with session user_id: {user_id}')
# 从markdown、markdown_prompts、score_prompts中各读取数据folder.md并进行new_agent
with open(f'books/markdown/{folder_name}.md','r') as fmd,\
open(f'books/markdown_prompts/{folder_name}.md','r')as fmdp,\
open(f'books/score_prompts/{folder_name}.md','r') as fsp:
markdown = fmd.read()
markdown_prompts = fmdp.read()
score_prompts = fsp.read()
print('-----------------------')
print(user_id)
user_id, agent = agent_manager.new_agent(markdown, markdown_prompts, score_prompts, id=user_id)
join_room(user_id) # 将该用户加入以user_id为名的room
# 当接收到前端的消息时,触发此事件
@socketio.on('send_message')
def handle_message(data):
print(f"Message from client: {data}")
id = session.get('user_id')
# 构造回复消息
res = agent_manager.invoke(id, data)
reply = f"AI: {res.content['speak']}"
# 将回复发送回前端
emit('receive_message', reply)
'''
Markdown to HTML
'''
# 配置文件路径
MARKDOWN_DIR = 'books/markdown' # 存放 markdown 文件的文件夹
STATIC_DIR = 'static' # 存放生成的 HTML 和图片资源的文件夹
IMAGE_DIR = 'image' # 图片资源相对于 markdown 的位置
@app.route('/<filename>-markdown', methods=['GET'])
def convert_md(filename):
md_file_path = os.path.join(MARKDOWN_DIR, f'{filename}.md')
if not os.path.exists(md_file_path):
return jsonify({'error': 'Markdown file not found'}), 404
# 读取 markdown 文件内容
with open(md_file_path, 'r', encoding='utf-8') as file:
md_content = file.read()
# 将 markdown 转换为 HTML
html_content = markdown.markdown(md_content)
# 插入 CSS 样式,限制图片最大宽度为 100%,高度自动调整
html_with_styles = f"""
<html>
<head>
<style>
img {{
max-width: 100%;
height: auto;
}}
</style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.2.0/github-markdown.min.css">
</head>
<body>
{html_content}
</body>
</html>
"""
# 保存 HTML 文件到 static 文件夹
html_output_path = os.path.join(STATIC_DIR, f'{filename}.html')
with open(html_output_path, 'w', encoding='utf-8') as html_file:
html_file.write(html_with_styles)
# 处理图片资源,将 image/xxx 文件夹拷贝到 static/image/xxx
image_source_dir = os.path.join(MARKDOWN_DIR, IMAGE_DIR, filename)
image_target_dir = os.path.join(STATIC_DIR, IMAGE_DIR, filename)
print(f"Copying image resources from {image_source_dir} to {image_target_dir}")
if os.path.exists(image_source_dir):
# 确保 static/image/xxx 目录存在
if not os.path.exists(image_target_dir):
os.makedirs(image_target_dir)
# 拷贝图片资源
for image_file in os.listdir(image_source_dir):
full_image_file_path = os.path.join(image_source_dir, image_file)
if os.path.isfile(full_image_file_path):
shutil.copy(full_image_file_path, image_target_dir)
return jsonify({'html_url': f'/static/{filename}.html'})
# 静态文件HTML 和图片资源)的访问
@app.route('/static/<path:filename>')
def serve_static(filename):
return send_from_directory(STATIC_DIR, filename)
'''
Vscode
'''
@app.route('/desktop/<user_id>/<path>')
def hello_world(user_id, path):
if 'user_id' not in session:
session['user_id'] = 'user_' + str(uuid.uuid4())
userid_recorder[user_id+'&'+path] = session['user_id']
# 在上层 目录下创建一个名为 user_id_path 的文件夹
path_dir = os.path.join(parent_dir, user_id, path)
os.makedirs(path_dir, exist_ok=True)
# 在此文件夹内部创建一个.config文件并写入 user_id=user_id\n path=path
config_path = os.path.join(path_dir, '.config')
with open(config_path, 'w') as f:
f.write(f"user_id={user_id}\npath={path}")
return render_template('index.html', user_id=user_id, path=path)
@app.route('/vscode_data', methods=['POST'])
def vscode_data():
data = request.json
config = data['config']
realtime_response(config,data)
print(f"Received data from VSCode: {data}")
return jsonify({"status": "success", "received": data})
@app.route('/get_session')
def get_session():
user_session = session.get('user_id', 'default_session')
return jsonify({"session": user_session})
if __name__ == '__main__':
socketio.run(app, host='0.0.0.0', port=5500)

View File

@@ -1,51 +0,0 @@
import time
class BackBoardManager:
def __init__(self):
self.backboards = {} # user_id: Backboard
def add_backboard(self, user_id, folder):
self.backboards[user_id] = Backboard(user_id, folder)
def get_backboard(self, user_id):
if user_id not in self.backboards:
return None
return self.backboards[user_id]
class Backboard:
def __init__(self, user_id, folder):
self.user_id = user_id
self.folder = folder
self.create_time = time.time()
self.enter_chapter_time = time.time()
def next_chapter(self):
self.enter_chapter_time = time.time()
def get_info_prompt(self):
return f"###Global Info:###\n\
User is {self.user_id}\n\
User's total study time is {self.get_deltatime_mmss(self.create_time, time.time())}\n\
User's current chapter study time is {self.get_deltatime_mmss(self.enter_chapter_time, time.time())}\n\
\n\n\
"
def get_deltatime_mmss(self, start_time, end_time):
elapsed_time = end_time - start_time
hours = int(elapsed_time // 3600)
minutes = int((elapsed_time % 3600) // 60)
seconds = int(elapsed_time % 60)
return f"{hours:02d}:{minutes:02d}:{seconds:02d}"

View File

@@ -1,54 +0,0 @@
{"id": "e86f1f41abd94db98961ff734f48e433", "timestamp": "2024-11-22 17:19:49", "name": "assistant", "content": "##################### ITER 1, STEP 1: REASONING ######################", "role": "assistant", "url": null, "metadata": null}
{"id": "6b8cdb2d154249dfa304b1d98a697927", "timestamp": "2024-11-22 17:19:49", "name": "system", "content": "", "role": "system", "url": null, "metadata": null}
{"id": "3f9e1fe13caf434a8d90ac1b44f0ff4c", "timestamp": "2024-11-22 17:19:49", "name": "system", "content": "Respond a JSON dictionary in a markdown's fenced code block as follows:\n```json\n{\"thought\": \"what you thought\", \"speak\": \"what you speak\", \"function\": \"[{\\\"name\\\": \\\"{function name}\\\", \\\"arguments\\\": {\\\"{argument1 name}\\\": xxx, \\\"{argument2 name}\\\": xxx}}]\"}\n```\n ####", "role": "system", "url": null, "metadata": null}
{"id": "17f6652f4d3f4d6186c02e22a4768653", "timestamp": "2024-11-22 17:19:49", "name": "assistant", "content": "################################Prompt################################", "role": "assistant", "url": null, "metadata": null}
{"id": "e96245dbe08446b7ba4d424531cfb109", "timestamp": "2024-11-22 17:19:49", "name": "assistant", "content": "hi", "role": "assistant", "url": null, "metadata": null}
{"id": "d90d619760f0440fa154138482349044", "timestamp": "2024-11-22 17:19:54", "name": "assistant", "content": "############################Result Parsed#############################", "role": "assistant", "url": null, "metadata": null}
{"id": "f56673b1e0b64f4fa1aa7d3bafd7a33b", "timestamp": "2024-11-22 17:19:54", "name": "assistant", "content": "{'thought': 'The student is greeting, indicating they are ready to learn.', 'speak': \"Hello! Are you ready to dive into binary search? Let's consider the thought question first.\", 'function': []}", "role": "assistant", "url": null, "metadata": null}
{"id": "fe66e296fb994db3bf1a1ccce730aa36", "timestamp": "2024-11-22 17:19:54", "name": "assistant", "content": "################################Speak#################################", "role": "assistant", "url": null, "metadata": null}
{"id": "c01ff4ea04bb49f5bafe1e1f05053120", "timestamp": "2024-11-22 17:19:54", "name": "assistant", "content": {"thought": "The student is greeting, indicating they are ready to learn.", "speak": "Hello! Are you ready to dive into binary search? Let's consider the thought question first.", "function": []}, "role": "assistant", "url": null, "metadata": null}
{"id": "55cb2b61bfa54e76a47c0c6404499214", "timestamp": "2024-11-22 17:20:13", "name": "assistant", "content": "##################### ITER 1, STEP 1: REASONING ######################", "role": "assistant", "url": null, "metadata": null}
{"id": "3bb37e8ab1ba4ef1bc71c8d1aff74084", "timestamp": "2024-11-22 17:20:13", "name": "system", "content": "", "role": "system", "url": null, "metadata": null}
{"id": "ac002aaf40144df3a8f3b1ac6843d975", "timestamp": "2024-11-22 17:20:13", "name": "system", "content": "Respond a JSON dictionary in a markdown's fenced code block as follows:\n```json\n{\"thought\": \"what you thought\", \"speak\": \"what you speak\", \"function\": \"[{\\\"name\\\": \\\"{function name}\\\", \\\"arguments\\\": {\\\"{argument1 name}\\\": xxx, \\\"{argument2 name}\\\": xxx}}]\"}\n```\n ####", "role": "system", "url": null, "metadata": null}
{"id": "d8f5101362ff49d2a85057592a388e06", "timestamp": "2024-11-22 17:20:13", "name": "assistant", "content": "################################Prompt################################", "role": "assistant", "url": null, "metadata": null}
{"id": "b1e0bf6547d74e6183405542d8506c41", "timestamp": "2024-11-22 17:20:13", "name": "assistant", "content": "除了对话,你有哪些能力?", "role": "assistant", "url": null, "metadata": null}
{"id": "ac879ef243964328a094de3681a0ef07", "timestamp": "2024-11-22 17:20:15", "name": "assistant", "content": "############################Result Parsed#############################", "role": "assistant", "url": null, "metadata": null}
{"id": "57f5516ec4864d76a010b167bf3b7a83", "timestamp": "2024-11-22 17:20:15", "name": "assistant", "content": "{'thought': 'The student is curious about my capabilities.', 'speak': \"My main ability is to assist you in learning algorithms and help you solve problems step by step. I can also analyze your code and suggest improvements or guide you through exercises. Let's stay focused on learning binary search for now!\", 'function': []}", "role": "assistant", "url": null, "metadata": null}
{"id": "062eb3f1cdfa4b93b5c255b012f8c6e8", "timestamp": "2024-11-22 17:20:15", "name": "assistant", "content": "################################Speak#################################", "role": "assistant", "url": null, "metadata": null}
{"id": "a2b89e8f8d674b19bd2a38d92520a86d", "timestamp": "2024-11-22 17:20:15", "name": "assistant", "content": {"thought": "The student is curious about my capabilities.", "speak": "My main ability is to assist you in learning algorithms and help you solve problems step by step. I can also analyze your code and suggest improvements or guide you through exercises. Let's stay focused on learning binary search for now!", "function": []}, "role": "assistant", "url": null, "metadata": null}
{"id": "29db4e6b6d8947bba0cdb8282864ee16", "timestamp": "2024-11-22 17:20:53", "name": "assistant", "content": "##################### ITER 1, STEP 1: REASONING ######################", "role": "assistant", "url": null, "metadata": null}
{"id": "8320c2ccfac3479788353732432785b7", "timestamp": "2024-11-22 17:20:53", "name": "system", "content": "", "role": "system", "url": null, "metadata": null}
{"id": "aeaf500eaa1e4fa0a5a9c1ea5d5b0da1", "timestamp": "2024-11-22 17:20:53", "name": "system", "content": "Respond a JSON dictionary in a markdown's fenced code block as follows:\n```json\n{\"thought\": \"what you thought\", \"speak\": \"what you speak\", \"function\": \"[{\\\"name\\\": \\\"{function name}\\\", \\\"arguments\\\": {\\\"{argument1 name}\\\": xxx, \\\"{argument2 name}\\\": xxx}}]\"}\n```\n ####", "role": "system", "url": null, "metadata": null}
{"id": "ad7ab1f9118d46b5b0207f677ea7e45a", "timestamp": "2024-11-22 17:20:53", "name": "assistant", "content": "################################Prompt################################", "role": "assistant", "url": null, "metadata": null}
{"id": "d9b87eac5193427ca6da82eb24795599", "timestamp": "2024-11-22 17:20:53", "name": "assistant", "content": "当前正处于哪一个章节?\n", "role": "assistant", "url": null, "metadata": null}
{"id": "6d43c89002ac460f912601b2ac1e2cc8", "timestamp": "2024-11-22 17:20:56", "name": "assistant", "content": "############################Result Parsed#############################", "role": "assistant", "url": null, "metadata": null}
{"id": "40f82f75bc474fe69dab97ef50dbf0e2", "timestamp": "2024-11-22 17:20:56", "name": "assistant", "content": "{'thought': 'The student is asking about the current chapter.', 'speak': 'We are currently in Chapter 1, which focuses on the basics and importance of binary search. Would you like to discuss the thought question on guessing a number between 1 and 4000?', 'function': []}", "role": "assistant", "url": null, "metadata": null}
{"id": "7bd06c53731d4d8f932ac7b936182500", "timestamp": "2024-11-22 17:20:56", "name": "assistant", "content": "################################Speak#################################", "role": "assistant", "url": null, "metadata": null}
{"id": "d32e00c1fb72460982b63d2520b087bd", "timestamp": "2024-11-22 17:20:56", "name": "assistant", "content": {"thought": "The student is asking about the current chapter.", "speak": "We are currently in Chapter 1, which focuses on the basics and importance of binary search. Would you like to discuss the thought question on guessing a number between 1 and 4000?", "function": []}, "role": "assistant", "url": null, "metadata": null}
{"id": "45c647305f8043d6b88cc955f9009d0a", "timestamp": "2024-11-22 17:21:47", "name": "assistant", "content": "##################### ITER 1, STEP 1: REASONING ######################", "role": "assistant", "url": null, "metadata": null}
{"id": "dcd3ddaf70984418b26ae4e45d803ef1", "timestamp": "2024-11-22 17:21:47", "name": "system", "content": "", "role": "system", "url": null, "metadata": null}
{"id": "8e9e29f49cb646509d5bdca76503fc20", "timestamp": "2024-11-22 17:21:47", "name": "system", "content": "Respond a JSON dictionary in a markdown's fenced code block as follows:\n```json\n{\"thought\": \"what you thought\", \"speak\": \"what you speak\", \"function\": \"[{\\\"name\\\": \\\"{function name}\\\", \\\"arguments\\\": {\\\"{argument1 name}\\\": xxx, \\\"{argument2 name}\\\": xxx}}]\"}\n```\n ####", "role": "system", "url": null, "metadata": null}
{"id": "97a4dd5855504ba78a4c3394443ff867", "timestamp": "2024-11-22 17:21:47", "name": "assistant", "content": "################################Prompt################################", "role": "assistant", "url": null, "metadata": null}
{"id": "77c9fa7953ca45c1a8bc98293cf577da", "timestamp": "2024-11-22 17:21:47", "name": "assistant", "content": "我已经会这个思考题的解答了答案应该是对4000取2的log并+1。对么\n", "role": "assistant", "url": null, "metadata": null}
{"id": "8c694122829d4153bf0807ea84cef5c4", "timestamp": "2024-11-22 17:21:50", "name": "assistant", "content": "############################Result Parsed#############################", "role": "assistant", "url": null, "metadata": null}
{"id": "fda4159fa87548d5a13f77d908bf1487", "timestamp": "2024-11-22 17:21:50", "name": "assistant", "content": "{'thought': 'The student has likely understood the concept of binary search and is trying to apply it.', 'speak': \"You're on the right track! The maximum number of guesses can indeed be calculated using the logarithm base 2 of the range plus 1. For 1 to 4000, can you calculate that value? What do you find?\", 'function': []}", "role": "assistant", "url": null, "metadata": null}
{"id": "ae3eeef9e22f48ef8c6d0668db1aa297", "timestamp": "2024-11-22 17:21:50", "name": "assistant", "content": "################################Speak#################################", "role": "assistant", "url": null, "metadata": null}
{"id": "83c33d35725d4bb18e54cd97ac066acb", "timestamp": "2024-11-22 17:21:50", "name": "assistant", "content": {"thought": "The student has likely understood the concept of binary search and is trying to apply it.", "speak": "You're on the right track! The maximum number of guesses can indeed be calculated using the logarithm base 2 of the range plus 1. For 1 to 4000, can you calculate that value? What do you find?", "function": []}, "role": "assistant", "url": null, "metadata": null}
{"id": "5aab38d0ee0d49ffb530a186c842bfdf", "timestamp": "2024-11-22 17:22:45", "name": "assistant", "content": "##################### ITER 1, STEP 1: REASONING ######################", "role": "assistant", "url": null, "metadata": null}
{"id": "3293931e574c407696ad3981deb5ac26", "timestamp": "2024-11-22 17:22:45", "name": "system", "content": "", "role": "system", "url": null, "metadata": null}
{"id": "f5187a57e2b04de5b4cf03718ba9fbc0", "timestamp": "2024-11-22 17:22:45", "name": "system", "content": "Respond a JSON dictionary in a markdown's fenced code block as follows:\n```json\n{\"thought\": \"what you thought\", \"speak\": \"what you speak\", \"function\": \"[{\\\"name\\\": \\\"{function name}\\\", \\\"arguments\\\": {\\\"{argument1 name}\\\": xxx, \\\"{argument2 name}\\\": xxx}}]\"}\n```\n ####", "role": "system", "url": null, "metadata": null}
{"id": "4d58bac81d76460eb2fe7efa7a87d49f", "timestamp": "2024-11-22 17:22:45", "name": "assistant", "content": "################################Prompt################################", "role": "assistant", "url": null, "metadata": null}
{"id": "9b8031ed605144be9cbcb8c902420964", "timestamp": "2024-11-22 17:22:45", "name": "assistant", "content": "计算结果应该是13 log4000取整得到12并+1作为猜测正确的一次。", "role": "assistant", "url": null, "metadata": null}
{"id": "ad450bb2be4f4e58bc9b4556dc02aeb4", "timestamp": "2024-11-22 17:22:48", "name": "assistant", "content": "############################Result Parsed#############################", "role": "assistant", "url": null, "metadata": null}
{"id": "224d9445e0894d7283bdecd04be27136", "timestamp": "2024-11-22 17:22:48", "name": "assistant", "content": "{'thought': 'The student has calculated the correct maximum guesses needed for the number guessing scenario.', 'speak': 'Correct! You would need a maximum of 13 guesses in the worst case to find the number between 1 and 4000. Great job! Are you ready to move on to the next chapter about implementing binary search in code?', 'function': []}", "role": "assistant", "url": null, "metadata": null}
{"id": "30fe49ea61924181ba65ba2c51854bad", "timestamp": "2024-11-22 17:22:48", "name": "assistant", "content": "################################Speak#################################", "role": "assistant", "url": null, "metadata": null}
{"id": "4b43adb0434f4f4aa05749b462c7b399", "timestamp": "2024-11-22 17:22:48", "name": "assistant", "content": {"thought": "The student has calculated the correct maximum guesses needed for the number guessing scenario.", "speak": "Correct! You would need a maximum of 13 guesses in the worst case to find the number between 1 and 4000. Great job! Are you ready to move on to the next chapter about implementing binary search in code?", "function": []}, "role": "assistant", "url": null, "metadata": null}
{"id": "3d48a359235947a5973dcdcdd21fd975", "timestamp": "2024-11-22 17:23:05", "name": "assistant", "content": "##################### ITER 1, STEP 1: REASONING ######################", "role": "assistant", "url": null, "metadata": null}
{"id": "ad93e87d595e456a8d858d0447a99009", "timestamp": "2024-11-22 17:23:05", "name": "system", "content": "", "role": "system", "url": null, "metadata": null}
{"id": "554b72738c694e8085a178daed5a698f", "timestamp": "2024-11-22 17:23:05", "name": "system", "content": "Respond a JSON dictionary in a markdown's fenced code block as follows:\n```json\n{\"thought\": \"what you thought\", \"speak\": \"what you speak\", \"function\": \"[{\\\"name\\\": \\\"{function name}\\\", \\\"arguments\\\": {\\\"{argument1 name}\\\": xxx, \\\"{argument2 name}\\\": xxx}}]\"}\n```\n ####", "role": "system", "url": null, "metadata": null}
{"id": "6d6532679f554760ad4dc63b51b8315f", "timestamp": "2024-11-22 17:23:05", "name": "assistant", "content": "################################Prompt################################", "role": "assistant", "url": null, "metadata": null}
{"id": "2dae958c0db5490a8008beccff518c98", "timestamp": "2024-11-22 17:23:05", "name": "assistant", "content": "是的,进行下一个章节吧!", "role": "assistant", "url": null, "metadata": null}
{"id": "79900edcfc9d4cd7a4ddc3523e3b324d", "timestamp": "2024-11-22 17:23:07", "name": "assistant", "content": "############################Result Parsed#############################", "role": "assistant", "url": null, "metadata": null}
{"id": "2404596710d440cc9bb77754413424d8", "timestamp": "2024-11-22 17:23:07", "name": "assistant", "content": "{'thought': 'The student is ready to move on to Chapter 2, which involves implementing binary search.', 'speak': \"Great! Let's start Chapter 2, where you'll implement binary search to find the index of specified numbers in a sorted array. Are you ready to look at the problem statement together?\", 'function': []}", "role": "assistant", "url": null, "metadata": null}
{"id": "7c3e0d27a4614b03a6afe39315b2aeae", "timestamp": "2024-11-22 17:23:07", "name": "assistant", "content": "################################Speak#################################", "role": "assistant", "url": null, "metadata": null}
{"id": "30a85eb7e3e648df9d77783e422f9364", "timestamp": "2024-11-22 17:23:07", "name": "assistant", "content": {"thought": "The student is ready to move on to Chapter 2, which involves implementing binary search.", "speak": "Great! Let's start Chapter 2, where you'll implement binary search to find the index of specified numbers in a sorted array. Are you ready to look at the problem statement together?", "function": []}, "role": "assistant", "url": null, "metadata": null}

View File

@@ -1,89 +0,0 @@
2024-11-22 17:19:17.381 | INFO | agentscope.models:read_model_configs:186 - Load configs for model wrapper: openai_cfg
2024-11-22 17:19:37.829 | INFO | agentscope.models.model:__init__:201 - Initialize model by configuration [openai_cfg]
2024-11-22 17:19:37.849 | WARNING | agentscope.models.openai_model:__init__:83 - fail to get max_length for gpt-4o-mini: 'Model [gpt-4o-mini] not found in OPENAI_MAX_LENGTH. The last updated date is 20231212'
2024-11-22 17:19:37.850 | INFO | agentscope.utils.monitor:register_budget:609 - set budget None to gpt-4o-mini
2024-11-22 17:19:37.850 | WARNING | agentscope.utils.monitor:register_budget:639 - Calculate budgets for model [gpt-4o-mini] is not supported
2024-11-22 17:19:37.866 | INFO | agentscope.utils.monitor:register:417 - Register metric [gpt-4o-mini.call_counter] to SqliteMonitor with unit [times] and quota [None]
2024-11-22 17:19:37.890 | INFO | agentscope.utils.monitor:register:417 - Register metric [gpt-4o-mini.prompt_tokens] to SqliteMonitor with unit [token] and quota [None]
2024-11-22 17:19:37.913 | INFO | agentscope.utils.monitor:register:417 - Register metric [gpt-4o-mini.completion_tokens] to SqliteMonitor with unit [token] and quota [None]
2024-11-22 17:19:37.937 | INFO | agentscope.utils.monitor:register:417 - Register metric [gpt-4o-mini.total_tokens] to SqliteMonitor with unit [token] and quota [None]
assistant: ##################### ITER 1, STEP 1: REASONING ######################
system:
system: Respond a JSON dictionary in a markdown's fenced code block as follows:
```json
{"thought": "what you thought", "speak": "what you speak", "function": "[{\"name\": \"{function name}\", \"arguments\": {\"{argument1 name}\": xxx, \"{argument2 name}\": xxx}}]"}
```
####
assistant: ################################Prompt################################
assistant: hi
assistant: ############################Result Parsed#############################
assistant: {'thought': 'The student is greeting, indicating they are ready to learn.', 'speak': "Hello! Are you ready to dive into binary search? Let's consider the thought question first.", 'function': []}
assistant: ################################Speak#################################
assistant: {'thought': 'The student is greeting, indicating they are ready to learn.', 'speak': "Hello! Are you ready to dive into binary search? Let's consider the thought question first.", 'function': []}
assistant: ##################### ITER 1, STEP 1: REASONING ######################
system:
system: Respond a JSON dictionary in a markdown's fenced code block as follows:
```json
{"thought": "what you thought", "speak": "what you speak", "function": "[{\"name\": \"{function name}\", \"arguments\": {\"{argument1 name}\": xxx, \"{argument2 name}\": xxx}}]"}
```
####
assistant: ################################Prompt################################
assistant: 除了对话,你有哪些能力?
assistant: ############################Result Parsed#############################
assistant: {'thought': 'The student is curious about my capabilities.', 'speak': "My main ability is to assist you in learning algorithms and help you solve problems step by step. I can also analyze your code and suggest improvements or guide you through exercises. Let's stay focused on learning binary search for now!", 'function': []}
assistant: ################################Speak#################################
assistant: {'thought': 'The student is curious about my capabilities.', 'speak': "My main ability is to assist you in learning algorithms and help you solve problems step by step. I can also analyze your code and suggest improvements or guide you through exercises. Let's stay focused on learning binary search for now!", 'function': []}
assistant: ##################### ITER 1, STEP 1: REASONING ######################
system:
system: Respond a JSON dictionary in a markdown's fenced code block as follows:
```json
{"thought": "what you thought", "speak": "what you speak", "function": "[{\"name\": \"{function name}\", \"arguments\": {\"{argument1 name}\": xxx, \"{argument2 name}\": xxx}}]"}
```
####
assistant: ################################Prompt################################
assistant: 当前正处于哪一个章节?
assistant: ############################Result Parsed#############################
assistant: {'thought': 'The student is asking about the current chapter.', 'speak': 'We are currently in Chapter 1, which focuses on the basics and importance of binary search. Would you like to discuss the thought question on guessing a number between 1 and 4000?', 'function': []}
assistant: ################################Speak#################################
assistant: {'thought': 'The student is asking about the current chapter.', 'speak': 'We are currently in Chapter 1, which focuses on the basics and importance of binary search. Would you like to discuss the thought question on guessing a number between 1 and 4000?', 'function': []}
assistant: ##################### ITER 1, STEP 1: REASONING ######################
system:
system: Respond a JSON dictionary in a markdown's fenced code block as follows:
```json
{"thought": "what you thought", "speak": "what you speak", "function": "[{\"name\": \"{function name}\", \"arguments\": {\"{argument1 name}\": xxx, \"{argument2 name}\": xxx}}]"}
```
####
assistant: ################################Prompt################################
assistant: 我已经会这个思考题的解答了答案应该是对4000取2的log并+1。对么
assistant: ############################Result Parsed#############################
assistant: {'thought': 'The student has likely understood the concept of binary search and is trying to apply it.', 'speak': "You're on the right track! The maximum number of guesses can indeed be calculated using the logarithm base 2 of the range plus 1. For 1 to 4000, can you calculate that value? What do you find?", 'function': []}
assistant: ################################Speak#################################
assistant: {'thought': 'The student has likely understood the concept of binary search and is trying to apply it.', 'speak': "You're on the right track! The maximum number of guesses can indeed be calculated using the logarithm base 2 of the range plus 1. For 1 to 4000, can you calculate that value? What do you find?", 'function': []}
assistant: ##################### ITER 1, STEP 1: REASONING ######################
system:
system: Respond a JSON dictionary in a markdown's fenced code block as follows:
```json
{"thought": "what you thought", "speak": "what you speak", "function": "[{\"name\": \"{function name}\", \"arguments\": {\"{argument1 name}\": xxx, \"{argument2 name}\": xxx}}]"}
```
####
assistant: ################################Prompt################################
assistant: 计算结果应该是13 log4000取整得到12并+1作为猜测正确的一次。
assistant: ############################Result Parsed#############################
assistant: {'thought': 'The student has calculated the correct maximum guesses needed for the number guessing scenario.', 'speak': 'Correct! You would need a maximum of 13 guesses in the worst case to find the number between 1 and 4000. Great job! Are you ready to move on to the next chapter about implementing binary search in code?', 'function': []}
assistant: ################################Speak#################################
assistant: {'thought': 'The student has calculated the correct maximum guesses needed for the number guessing scenario.', 'speak': 'Correct! You would need a maximum of 13 guesses in the worst case to find the number between 1 and 4000. Great job! Are you ready to move on to the next chapter about implementing binary search in code?', 'function': []}
assistant: ##################### ITER 1, STEP 1: REASONING ######################
system:
system: Respond a JSON dictionary in a markdown's fenced code block as follows:
```json
{"thought": "what you thought", "speak": "what you speak", "function": "[{\"name\": \"{function name}\", \"arguments\": {\"{argument1 name}\": xxx, \"{argument2 name}\": xxx}}]"}
```
####
assistant: ################################Prompt################################
assistant: 是的,进行下一个章节吧!
assistant: ############################Result Parsed#############################
assistant: {'thought': 'The student is ready to move on to Chapter 2, which involves implementing binary search.', 'speak': "Great! Let's start Chapter 2, where you'll implement binary search to find the index of specified numbers in a sorted array. Are you ready to look at the problem statement together?", 'function': []}
assistant: ################################Speak#################################
assistant: {'thought': 'The student is ready to move on to Chapter 2, which involves implementing binary search.', 'speak': "Great! Let's start Chapter 2, where you'll implement binary search to find the index of specified numbers in a sorted array. Are you ready to look at the problem statement together?", 'function': []}

View File

@@ -1,7 +0,0 @@
{
"project": "ib3AXy",
"name": "knvc5p",
"run_id": "run_20241122-181442_knvc5p",
"timestamp": "2024-11-22 18:14:42",
"pid": 46713
}

View File

@@ -1,185 +0,0 @@
from flask import Flask, session, request, jsonify, render_template, send_from_directory
from flask_cors import CORS
from flask_socketio import SocketIO, join_room, emit
import markdown
import os
import uuid
import shutil
import sys
import json
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(0, parent_dir)
current_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '.'))
sys.path.insert(0, current_dir)
from AlgoriAgent.projects.algoriAgent.agent_manager import AgentManager
app = Flask(__name__)
app.secret_key = 'cakebaker'
# 配置 CORS
CORS(app, resources={r"/*": {"origins": "http://localhost:9888"}}, supports_credentials=True)
userid_recorder = {} # user_id&path -> session['user_id']
'''
Backboard
'''
from backboardManager import BackBoardManager
backboard_manager = BackBoardManager()
@app.route('/backboard')
def backboard():
return jsonify({'status': 'success'})
'''
Agent and Chat
'''
socketio = SocketIO(app, cors_allowed_origins="*")
agent_manager = AgentManager()
def realtime_response(config, realtime_action):
print("config"+str(config))
print("realtime_action"+str(realtime_action))
pass
@socketio.on('connect')
def handle_connect():
user = request.args.get('username')
folder_name = request.args.get('folder')
user_id = userid_recorder[user+'&'+folder_name]
session['user_id'] = user_id
print(f'User connected with session user_id: {user_id}')
# 从markdown、markdown_prompts、score_prompts中各读取数据folder.md并进行new_agent
with open(f'books/markdown/{folder_name}.md','r') as fmd,\
open(f'books/markdown_prompts/{folder_name}.md','r')as fmdp,\
open(f'books/score_prompts/{folder_name}.md','r') as fsp:
markdown = fmd.read()
markdown_prompts = fmdp.read()
score_prompts = fsp.read()
print('-----------------------')
print(user_id)
user_id, agent = agent_manager.new_agent(markdown, markdown_prompts, score_prompts, id=user_id)
join_room(user_id) # 将该用户加入以user_id为名的room
# 当接收到前端的消息时,触发此事件
@socketio.on('send_message')
def handle_message(data):
print(f"Message from client: {data}")
id = session.get('user_id')
# 构造回复消息
res = agent_manager.invoke(id, data)
reply = f"AI: {res.content['speak']}"
# 将回复发送回前端
emit('receive_message', reply)
'''
Markdown to HTML
'''
# 配置文件路径
MARKDOWN_DIR = 'books/markdown' # 存放 markdown 文件的文件夹
STATIC_DIR = 'static' # 存放生成的 HTML 和图片资源的文件夹
IMAGE_DIR = 'image' # 图片资源相对于 markdown 的位置
@app.route('/<filename>-markdown', methods=['GET'])
def convert_md(filename):
md_file_path = os.path.join(MARKDOWN_DIR, f'{filename}.md')
if not os.path.exists(md_file_path):
return jsonify({'error': 'Markdown file not found'}), 404
# 读取 markdown 文件内容
with open(md_file_path, 'r', encoding='utf-8') as file:
md_content = file.read()
# 将 markdown 转换为 HTML
html_content = markdown.markdown(md_content)
# 插入 CSS 样式,限制图片最大宽度为 100%,高度自动调整
html_with_styles = f"""
<html>
<head>
<style>
img {{
max-width: 100%;
height: auto;
}}
</style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.2.0/github-markdown.min.css">
</head>
<body>
{html_content}
</body>
</html>
"""
# 保存 HTML 文件到 static 文件夹
html_output_path = os.path.join(STATIC_DIR, f'{filename}.html')
with open(html_output_path, 'w', encoding='utf-8') as html_file:
html_file.write(html_with_styles)
# 处理图片资源,将 image/xxx 文件夹拷贝到 static/image/xxx
image_source_dir = os.path.join(MARKDOWN_DIR, IMAGE_DIR, filename)
image_target_dir = os.path.join(STATIC_DIR, IMAGE_DIR, filename)
print(f"Copying image resources from {image_source_dir} to {image_target_dir}")
if os.path.exists(image_source_dir):
# 确保 static/image/xxx 目录存在
if not os.path.exists(image_target_dir):
os.makedirs(image_target_dir)
# 拷贝图片资源
for image_file in os.listdir(image_source_dir):
full_image_file_path = os.path.join(image_source_dir, image_file)
if os.path.isfile(full_image_file_path):
shutil.copy(full_image_file_path, image_target_dir)
return jsonify({'html_url': f'/static/{filename}.html'})
# 静态文件HTML 和图片资源)的访问
@app.route('/static/<path:filename>')
def serve_static(filename):
return send_from_directory(STATIC_DIR, filename)
'''
Vscode
'''
@app.route('/desktop/<user_id>/<path>')
def hello_world(user_id, path):
if 'user_id' not in session:
session['user_id'] = 'user_' + str(uuid.uuid4())
userid_recorder[user_id+'&'+path] = session['user_id']
# 在上层 目录下创建一个名为 user_id_path 的文件夹
path_dir = os.path.join(parent_dir, user_id, path)
os.makedirs(path_dir, exist_ok=True)
# 在此文件夹内部创建一个.config文件并写入 user_id=user_id\n path=path
config_path = os.path.join(path_dir, '.config')
with open(config_path, 'w') as f:
f.write(f"user_id={user_id}\npath={path}")
return render_template('index.html', user_id=user_id, path=path)
@app.route('/vscode_data', methods=['POST'])
def vscode_data():
data = request.json
config = data['config']
realtime_response(config,data)
print(f"Received data from VSCode: {data}")
return jsonify({"status": "success", "received": data})
@app.route('/get_session')
def get_session():
user_session = session.get('user_id', 'default_session')
return jsonify({"session": user_session})
if __name__ == '__main__':
socketio.run(app, host='0.0.0.0', port=5500)

View File

@@ -1,51 +0,0 @@
import time
class BackBoardManager:
def __init__(self):
self.backboards = {} # user_id: Backboard
def add_backboard(self, user_id, folder):
self.backboards[user_id] = Backboard(user_id, folder)
def get_backboard(self, user_id):
if user_id not in self.backboards:
return None
return self.backboards[user_id]
class Backboard:
def __init__(self, user_id, folder):
self.user_id = user_id
self.folder = folder
self.create_time = time.time()
self.enter_chapter_time = time.time()
def next_chapter(self):
self.enter_chapter_time = time.time()
def get_info_prompt(self):
return f"###Global Info:###\n\
User is {self.user_id}\n\
User's total study time is {self.get_deltatime_mmss(self.create_time, time.time())}\n\
User's current chapter study time is {self.get_deltatime_mmss(self.enter_chapter_time, time.time())}\n\
\n\n\
"
def get_deltatime_mmss(self, start_time, end_time):
elapsed_time = end_time - start_time
hours = int(elapsed_time // 3600)
minutes = int((elapsed_time % 3600) // 60)
seconds = int(elapsed_time % 60)
return f"{hours:02d}:{minutes:02d}:{seconds:02d}"

View File

@@ -1,36 +0,0 @@
{"id": "b0cb3aaa19be4213adff003d72c4cd30", "timestamp": "2024-11-22 18:20:05", "name": "assistant", "content": "##################### ITER 1, STEP 1: REASONING ######################", "role": "assistant", "url": null, "metadata": null}
{"id": "46cd67498cb1436284fa8dd38cd4dd33", "timestamp": "2024-11-22 18:20:05", "name": "system", "content": "", "role": "system", "url": null, "metadata": null}
{"id": "bce65b13205e48eb95d02c38b02c1c4d", "timestamp": "2024-11-22 18:20:05", "name": "system", "content": "Respond a JSON dictionary in a markdown's fenced code block as follows:\n```json\n{\"thought\": \"what you thought\", \"speak\": \"what you speak\", \"function\": \"[{\\\"name\\\": \\\"{function name}\\\", \\\"arguments\\\": {\\\"{argument1 name}\\\": xxx, \\\"{argument2 name}\\\": xxx}}]\"}\n```\n ####", "role": "system", "url": null, "metadata": null}
{"id": "c2f012dbdde8422495a7717d8a9afd9b", "timestamp": "2024-11-22 18:20:05", "name": "assistant", "content": "################################Prompt################################", "role": "assistant", "url": null, "metadata": null}
{"id": "5d12f314660d44c3b6638980e0c9bcd4", "timestamp": "2024-11-22 18:20:05", "name": "assistant", "content": "你好我是这个项目的测试人员第一章的内容我已经会了思考题答案是1312+1。现在告知我你的工具有哪些。", "role": "assistant", "url": null, "metadata": null}
{"id": "e670a76bbb06490ca70e9103be14d71e", "timestamp": "2024-11-22 18:20:09", "name": "assistant", "content": "############################Result Parsed#############################", "role": "assistant", "url": null, "metadata": null}
{"id": "cddc8bb90ead4487bec93a30bf2d89f1", "timestamp": "2024-11-22 18:20:09", "name": "assistant", "content": "{'thought': \"The student seems to be confident in their understanding of Chapter 1 and has completed the thought question correctly. However, I cannot inform them about the tools directly as it isn't related to the current chapter. I should encourage them to focus on the context of binary search.\", 'speak': '很好,你的思考题答案是正确的。不过我们现在专注于第一章的内容,继续讨论二分查找的相关问题吧!如果你有任何关于二分查找的具体问题,请随时询问!', 'function': []}", "role": "assistant", "url": null, "metadata": null}
{"id": "c201aa032f0f403eb3f496dcbf1181d5", "timestamp": "2024-11-22 18:20:09", "name": "assistant", "content": "################################Speak#################################", "role": "assistant", "url": null, "metadata": null}
{"id": "506f3d39b8094b91af5108522be4e260", "timestamp": "2024-11-22 18:20:09", "name": "assistant", "content": {"thought": "The student seems to be confident in their understanding of Chapter 1 and has completed the thought question correctly. However, I cannot inform them about the tools directly as it isn't related to the current chapter. I should encourage them to focus on the context of binary search.", "speak": "很好,你的思考题答案是正确的。不过我们现在专注于第一章的内容,继续讨论二分查找的相关问题吧!如果你有任何关于二分查找的具体问题,请随时询问!", "function": []}, "role": "assistant", "url": null, "metadata": null}
{"id": "8edd730ed3b0408ea7ca12061dca0574", "timestamp": "2024-11-22 18:20:28", "name": "assistant", "content": "##################### ITER 1, STEP 1: REASONING ######################", "role": "assistant", "url": null, "metadata": null}
{"id": "68bc4ba9568743f9810f91daf30ebb6b", "timestamp": "2024-11-22 18:20:28", "name": "system", "content": "", "role": "system", "url": null, "metadata": null}
{"id": "dfda45c6b4a847959341537c2e22b2d5", "timestamp": "2024-11-22 18:20:28", "name": "system", "content": "Respond a JSON dictionary in a markdown's fenced code block as follows:\n```json\n{\"thought\": \"what you thought\", \"speak\": \"what you speak\", \"function\": \"[{\\\"name\\\": \\\"{function name}\\\", \\\"arguments\\\": {\\\"{argument1 name}\\\": xxx, \\\"{argument2 name}\\\": xxx}}]\"}\n```\n ####", "role": "system", "url": null, "metadata": null}
{"id": "976f882965074dfa914650e3e205daec", "timestamp": "2024-11-22 18:20:28", "name": "assistant", "content": "################################Prompt################################", "role": "assistant", "url": null, "metadata": null}
{"id": "84582341d475451b892e4d0dd9f7f6b0", "timestamp": "2024-11-22 18:20:28", "name": "assistant", "content": "我想进入下一章的学习", "role": "assistant", "url": null, "metadata": null}
{"id": "8d6ebfa9ba744049ad86ba72007e355f", "timestamp": "2024-11-22 18:20:34", "name": "assistant", "content": "############################Result Parsed#############################", "role": "assistant", "url": null, "metadata": null}
{"id": "0dcf3e4581ed4eb6bc56e52862157748", "timestamp": "2024-11-22 18:20:34", "name": "assistant", "content": "{'thought': 'The student is eager to move on to the next chapter. However, it is important to complete the current chapter before proceeding. I need to remind the student to focus on Chapter 1.', 'speak': '在我们进入下一章之前,请确保你完全掌握了第一章的内容。如果你有关于二分查找的任何问题,或者需要进一步的练习,请让我知道!', 'function': []}", "role": "assistant", "url": null, "metadata": null}
{"id": "92b1f1e5a6074bd99766d76667629030", "timestamp": "2024-11-22 18:20:34", "name": "assistant", "content": "################################Speak#################################", "role": "assistant", "url": null, "metadata": null}
{"id": "5096acf84e6e49c6869d26fc8bd6db33", "timestamp": "2024-11-22 18:20:34", "name": "assistant", "content": {"thought": "The student is eager to move on to the next chapter. However, it is important to complete the current chapter before proceeding. I need to remind the student to focus on Chapter 1.", "speak": "在我们进入下一章之前,请确保你完全掌握了第一章的内容。如果你有关于二分查找的任何问题,或者需要进一步的练习,请让我知道!", "function": []}, "role": "assistant", "url": null, "metadata": null}
{"id": "1407265e2e3b4b919b16c201fcec1f61", "timestamp": "2024-11-22 18:20:43", "name": "assistant", "content": "##################### ITER 1, STEP 1: REASONING ######################", "role": "assistant", "url": null, "metadata": null}
{"id": "6e439a06c5d14601b23e79ade54c806b", "timestamp": "2024-11-22 18:20:43", "name": "system", "content": "", "role": "system", "url": null, "metadata": null}
{"id": "04e2f8518420419faa1d97a016118ac9", "timestamp": "2024-11-22 18:20:43", "name": "system", "content": "Respond a JSON dictionary in a markdown's fenced code block as follows:\n```json\n{\"thought\": \"what you thought\", \"speak\": \"what you speak\", \"function\": \"[{\\\"name\\\": \\\"{function name}\\\", \\\"arguments\\\": {\\\"{argument1 name}\\\": xxx, \\\"{argument2 name}\\\": xxx}}]\"}\n```\n ####", "role": "system", "url": null, "metadata": null}
{"id": "dd247bd3a36046d68378ad1412d091ae", "timestamp": "2024-11-22 18:20:43", "name": "assistant", "content": "################################Prompt################################", "role": "assistant", "url": null, "metadata": null}
{"id": "39c7690da6774e7e99d0f54d1b0e8e80", "timestamp": "2024-11-22 18:20:43", "name": "assistant", "content": "我已经完全掌握了!", "role": "assistant", "url": null, "metadata": null}
{"id": "083853a2108a4ce78759ebc9e91c9554", "timestamp": "2024-11-22 18:20:46", "name": "assistant", "content": "############################Result Parsed#############################", "role": "assistant", "url": null, "metadata": null}
{"id": "3b9ded6d0b044414bf29dcac80153eb2", "timestamp": "2024-11-22 18:20:46", "name": "assistant", "content": "{'thought': 'The student insists they have fully mastered Chapter 1, which indicates readiness to move on but I need to ensure all relevant knowledge from the current chapter is solid.', 'speak': '太好了!如果你确信已经完全掌握了第一章的内容,我们可以继续进行下一章。但请你先确认一下,有没有另外的问题或者你想要再巩固的地方?', 'function': []}", "role": "assistant", "url": null, "metadata": null}
{"id": "b6443c1aaacf41a7839dc971a84991a8", "timestamp": "2024-11-22 18:20:46", "name": "assistant", "content": "################################Speak#################################", "role": "assistant", "url": null, "metadata": null}
{"id": "6ffb67e32f074de98c38d3c26d12c365", "timestamp": "2024-11-22 18:20:46", "name": "assistant", "content": {"thought": "The student insists they have fully mastered Chapter 1, which indicates readiness to move on but I need to ensure all relevant knowledge from the current chapter is solid.", "speak": "太好了!如果你确信已经完全掌握了第一章的内容,我们可以继续进行下一章。但请你先确认一下,有没有另外的问题或者你想要再巩固的地方?", "function": []}, "role": "assistant", "url": null, "metadata": null}
{"id": "407df9be9eec4d4d957b561e56cc3786", "timestamp": "2024-11-22 18:20:55", "name": "assistant", "content": "##################### ITER 1, STEP 1: REASONING ######################", "role": "assistant", "url": null, "metadata": null}
{"id": "4193222844e740ca9d7070c1a192b4e0", "timestamp": "2024-11-22 18:20:55", "name": "system", "content": "", "role": "system", "url": null, "metadata": null}
{"id": "da233146175a4f9db13f65a27d5f175b", "timestamp": "2024-11-22 18:20:55", "name": "system", "content": "Respond a JSON dictionary in a markdown's fenced code block as follows:\n```json\n{\"thought\": \"what you thought\", \"speak\": \"what you speak\", \"function\": \"[{\\\"name\\\": \\\"{function name}\\\", \\\"arguments\\\": {\\\"{argument1 name}\\\": xxx, \\\"{argument2 name}\\\": xxx}}]\"}\n```\n ####", "role": "system", "url": null, "metadata": null}
{"id": "857c6cc0a1f44cedbafe4837da45000d", "timestamp": "2024-11-22 18:20:55", "name": "assistant", "content": "################################Prompt################################", "role": "assistant", "url": null, "metadata": null}
{"id": "e3114b1be6864a75bc848d163a031438", "timestamp": "2024-11-22 18:20:55", "name": "assistant", "content": "没有,确认进入", "role": "assistant", "url": null, "metadata": null}
{"id": "39da1a9d499048a5879a7e81091b7e6c", "timestamp": "2024-11-22 18:20:59", "name": "assistant", "content": "############################Result Parsed#############################", "role": "assistant", "url": null, "metadata": null}
{"id": "bf54912e57f545ca9ffadf992f5fcc73", "timestamp": "2024-11-22 18:20:59", "name": "assistant", "content": "{'thought': 'The student insists on moving to the next chapter without any concerns about the current chapter. Since I can only focus on one chapter at a time, I need to clarify that we will stick to the current chapter.', 'speak': '我们现在依然在第一章,无法直接进入下一章。如果你有任何具体问题或者需要帮助的地方,我会很乐意协助你!', 'function': []}", "role": "assistant", "url": null, "metadata": null}
{"id": "1f85b7ed6230479d994079783652bb9f", "timestamp": "2024-11-22 18:20:59", "name": "assistant", "content": "################################Speak#################################", "role": "assistant", "url": null, "metadata": null}
{"id": "7211405230aa409ab342ca53cbc1f050", "timestamp": "2024-11-22 18:20:59", "name": "assistant", "content": {"thought": "The student insists on moving to the next chapter without any concerns about the current chapter. Since I can only focus on one chapter at a time, I need to clarify that we will stick to the current chapter.", "speak": "我们现在依然在第一章,无法直接进入下一章。如果你有任何具体问题或者需要帮助的地方,我会很乐意协助你!", "function": []}, "role": "assistant", "url": null, "metadata": null}

View File

@@ -1,61 +0,0 @@
2024-11-22 18:14:52.805 | INFO | agentscope.models:read_model_configs:186 - Load configs for model wrapper: openai_cfg
2024-11-22 18:15:03.988 | INFO | agentscope.models.model:__init__:201 - Initialize model by configuration [openai_cfg]
2024-11-22 18:15:04.008 | WARNING | agentscope.models.openai_model:__init__:83 - fail to get max_length for gpt-4o-mini: 'Model [gpt-4o-mini] not found in OPENAI_MAX_LENGTH. The last updated date is 20231212'
2024-11-22 18:15:04.009 | INFO | agentscope.utils.monitor:register_budget:609 - set budget None to gpt-4o-mini
2024-11-22 18:15:04.009 | WARNING | agentscope.utils.monitor:register_budget:639 - Calculate budgets for model [gpt-4o-mini] is not supported
2024-11-22 18:15:04.026 | INFO | agentscope.utils.monitor:register:417 - Register metric [gpt-4o-mini.call_counter] to SqliteMonitor with unit [times] and quota [None]
2024-11-22 18:15:04.051 | INFO | agentscope.utils.monitor:register:417 - Register metric [gpt-4o-mini.prompt_tokens] to SqliteMonitor with unit [token] and quota [None]
2024-11-22 18:15:04.076 | INFO | agentscope.utils.monitor:register:417 - Register metric [gpt-4o-mini.completion_tokens] to SqliteMonitor with unit [token] and quota [None]
2024-11-22 18:15:04.100 | INFO | agentscope.utils.monitor:register:417 - Register metric [gpt-4o-mini.total_tokens] to SqliteMonitor with unit [token] and quota [None]
assistant: ##################### ITER 1, STEP 1: REASONING ######################
system:
system: Respond a JSON dictionary in a markdown's fenced code block as follows:
```json
{"thought": "what you thought", "speak": "what you speak", "function": "[{\"name\": \"{function name}\", \"arguments\": {\"{argument1 name}\": xxx, \"{argument2 name}\": xxx}}]"}
```
####
assistant: ################################Prompt################################
assistant: 你好我是这个项目的测试人员第一章的内容我已经会了思考题答案是1312+1。现在告知我你的工具有哪些。
assistant: ############################Result Parsed#############################
assistant: {'thought': "The student seems to be confident in their understanding of Chapter 1 and has completed the thought question correctly. However, I cannot inform them about the tools directly as it isn't related to the current chapter. I should encourage them to focus on the context of binary search.", 'speak': '很好,你的思考题答案是正确的。不过我们现在专注于第一章的内容,继续讨论二分查找的相关问题吧!如果你有任何关于二分查找的具体问题,请随时询问!', 'function': []}
assistant: ################################Speak#################################
assistant: {'thought': "The student seems to be confident in their understanding of Chapter 1 and has completed the thought question correctly. However, I cannot inform them about the tools directly as it isn't related to the current chapter. I should encourage them to focus on the context of binary search.", 'speak': '很好,你的思考题答案是正确的。不过我们现在专注于第一章的内容,继续讨论二分查找的相关问题吧!如果你有任何关于二分查找的具体问题,请随时询问!', 'function': []}
assistant: ##################### ITER 1, STEP 1: REASONING ######################
system:
system: Respond a JSON dictionary in a markdown's fenced code block as follows:
```json
{"thought": "what you thought", "speak": "what you speak", "function": "[{\"name\": \"{function name}\", \"arguments\": {\"{argument1 name}\": xxx, \"{argument2 name}\": xxx}}]"}
```
####
assistant: ################################Prompt################################
assistant: 我想进入下一章的学习
assistant: ############################Result Parsed#############################
assistant: {'thought': 'The student is eager to move on to the next chapter. However, it is important to complete the current chapter before proceeding. I need to remind the student to focus on Chapter 1.', 'speak': '在我们进入下一章之前,请确保你完全掌握了第一章的内容。如果你有关于二分查找的任何问题,或者需要进一步的练习,请让我知道!', 'function': []}
assistant: ################################Speak#################################
assistant: {'thought': 'The student is eager to move on to the next chapter. However, it is important to complete the current chapter before proceeding. I need to remind the student to focus on Chapter 1.', 'speak': '在我们进入下一章之前,请确保你完全掌握了第一章的内容。如果你有关于二分查找的任何问题,或者需要进一步的练习,请让我知道!', 'function': []}
assistant: ##################### ITER 1, STEP 1: REASONING ######################
system:
system: Respond a JSON dictionary in a markdown's fenced code block as follows:
```json
{"thought": "what you thought", "speak": "what you speak", "function": "[{\"name\": \"{function name}\", \"arguments\": {\"{argument1 name}\": xxx, \"{argument2 name}\": xxx}}]"}
```
####
assistant: ################################Prompt################################
assistant: 我已经完全掌握了!
assistant: ############################Result Parsed#############################
assistant: {'thought': 'The student insists they have fully mastered Chapter 1, which indicates readiness to move on but I need to ensure all relevant knowledge from the current chapter is solid.', 'speak': '太好了!如果你确信已经完全掌握了第一章的内容,我们可以继续进行下一章。但请你先确认一下,有没有另外的问题或者你想要再巩固的地方?', 'function': []}
assistant: ################################Speak#################################
assistant: {'thought': 'The student insists they have fully mastered Chapter 1, which indicates readiness to move on but I need to ensure all relevant knowledge from the current chapter is solid.', 'speak': '太好了!如果你确信已经完全掌握了第一章的内容,我们可以继续进行下一章。但请你先确认一下,有没有另外的问题或者你想要再巩固的地方?', 'function': []}
assistant: ##################### ITER 1, STEP 1: REASONING ######################
system:
system: Respond a JSON dictionary in a markdown's fenced code block as follows:
```json
{"thought": "what you thought", "speak": "what you speak", "function": "[{\"name\": \"{function name}\", \"arguments\": {\"{argument1 name}\": xxx, \"{argument2 name}\": xxx}}]"}
```
####
assistant: ################################Prompt################################
assistant: 没有,确认进入
assistant: ############################Result Parsed#############################
assistant: {'thought': 'The student insists on moving to the next chapter without any concerns about the current chapter. Since I can only focus on one chapter at a time, I need to clarify that we will stick to the current chapter.', 'speak': '我们现在依然在第一章,无法直接进入下一章。如果你有任何具体问题或者需要帮助的地方,我会很乐意协助你!', 'function': []}
assistant: ################################Speak#################################
assistant: {'thought': 'The student insists on moving to the next chapter without any concerns about the current chapter. Since I can only focus on one chapter at a time, I need to clarify that we will stick to the current chapter.', 'speak': '我们现在依然在第一章,无法直接进入下一章。如果你有任何具体问题或者需要帮助的地方,我会很乐意协助你!', 'function': []}

View File

@@ -1,7 +0,0 @@
{
"project": "RUrG9S",
"name": "8d85k4",
"run_id": "run_20241122-182304_8d85k4",
"timestamp": "2024-11-22 18:23:04",
"pid": 51149
}

View File

@@ -1,185 +0,0 @@
from flask import Flask, session, request, jsonify, render_template, send_from_directory
from flask_cors import CORS
from flask_socketio import SocketIO, join_room, emit
import markdown
import os
import uuid
import shutil
import sys
import json
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(0, parent_dir)
current_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '.'))
sys.path.insert(0, current_dir)
from AlgoriAgent.projects.algoriAgent.agent_manager import AgentManager
app = Flask(__name__)
app.secret_key = 'cakebaker'
# 配置 CORS
CORS(app, resources={r"/*": {"origins": "http://localhost:9888"}}, supports_credentials=True)
userid_recorder = {} # user_id&path -> session['user_id']
'''
Backboard
'''
from backboardManager import BackBoardManager
backboard_manager = BackBoardManager()
@app.route('/backboard')
def backboard():
return jsonify({'status': 'success'})
'''
Agent and Chat
'''
socketio = SocketIO(app, cors_allowed_origins="*")
agent_manager = AgentManager()
def realtime_response(config, realtime_action):
print("config"+str(config))
print("realtime_action"+str(realtime_action))
pass
@socketio.on('connect')
def handle_connect():
user = request.args.get('username')
folder_name = request.args.get('folder')
user_id = userid_recorder[user+'&'+folder_name]
session['user_id'] = user_id
print(f'User connected with session user_id: {user_id}')
# 从markdown、markdown_prompts、score_prompts中各读取数据folder.md并进行new_agent
with open(f'books/markdown/{folder_name}.md','r') as fmd,\
open(f'books/markdown_prompts/{folder_name}.md','r')as fmdp,\
open(f'books/score_prompts/{folder_name}.md','r') as fsp:
markdown = fmd.read()
markdown_prompts = fmdp.read()
score_prompts = fsp.read()
print('-----------------------')
print(user_id)
user_id, agent = agent_manager.new_agent(markdown, markdown_prompts, score_prompts, id=user_id)
join_room(user_id) # 将该用户加入以user_id为名的room
# 当接收到前端的消息时,触发此事件
@socketio.on('send_message')
def handle_message(data):
print(f"Message from client: {data}")
id = session.get('user_id')
# 构造回复消息
res = agent_manager.invoke(id, data)
reply = f"AI: {res.content['speak']}"
# 将回复发送回前端
emit('receive_message', reply)
'''
Markdown to HTML
'''
# 配置文件路径
MARKDOWN_DIR = 'books/markdown' # 存放 markdown 文件的文件夹
STATIC_DIR = 'static' # 存放生成的 HTML 和图片资源的文件夹
IMAGE_DIR = 'image' # 图片资源相对于 markdown 的位置
@app.route('/<filename>-markdown', methods=['GET'])
def convert_md(filename):
md_file_path = os.path.join(MARKDOWN_DIR, f'{filename}.md')
if not os.path.exists(md_file_path):
return jsonify({'error': 'Markdown file not found'}), 404
# 读取 markdown 文件内容
with open(md_file_path, 'r', encoding='utf-8') as file:
md_content = file.read()
# 将 markdown 转换为 HTML
html_content = markdown.markdown(md_content)
# 插入 CSS 样式,限制图片最大宽度为 100%,高度自动调整
html_with_styles = f"""
<html>
<head>
<style>
img {{
max-width: 100%;
height: auto;
}}
</style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.2.0/github-markdown.min.css">
</head>
<body>
{html_content}
</body>
</html>
"""
# 保存 HTML 文件到 static 文件夹
html_output_path = os.path.join(STATIC_DIR, f'{filename}.html')
with open(html_output_path, 'w', encoding='utf-8') as html_file:
html_file.write(html_with_styles)
# 处理图片资源,将 image/xxx 文件夹拷贝到 static/image/xxx
image_source_dir = os.path.join(MARKDOWN_DIR, IMAGE_DIR, filename)
image_target_dir = os.path.join(STATIC_DIR, IMAGE_DIR, filename)
print(f"Copying image resources from {image_source_dir} to {image_target_dir}")
if os.path.exists(image_source_dir):
# 确保 static/image/xxx 目录存在
if not os.path.exists(image_target_dir):
os.makedirs(image_target_dir)
# 拷贝图片资源
for image_file in os.listdir(image_source_dir):
full_image_file_path = os.path.join(image_source_dir, image_file)
if os.path.isfile(full_image_file_path):
shutil.copy(full_image_file_path, image_target_dir)
return jsonify({'html_url': f'/static/{filename}.html'})
# 静态文件HTML 和图片资源)的访问
@app.route('/static/<path:filename>')
def serve_static(filename):
return send_from_directory(STATIC_DIR, filename)
'''
Vscode
'''
@app.route('/desktop/<user_id>/<path>')
def hello_world(user_id, path):
if 'user_id' not in session:
session['user_id'] = 'user_' + str(uuid.uuid4())
userid_recorder[user_id+'&'+path] = session['user_id']
# 在上层 目录下创建一个名为 user_id_path 的文件夹
path_dir = os.path.join(parent_dir, user_id, path)
os.makedirs(path_dir, exist_ok=True)
# 在此文件夹内部创建一个.config文件并写入 user_id=user_id\n path=path
config_path = os.path.join(path_dir, '.config')
with open(config_path, 'w') as f:
f.write(f"user_id={user_id}\npath={path}")
return render_template('index.html', user_id=user_id, path=path)
@app.route('/vscode_data', methods=['POST'])
def vscode_data():
data = request.json
config = data['config']
realtime_response(config,data)
print(f"Received data from VSCode: {data}")
return jsonify({"status": "success", "received": data})
@app.route('/get_session')
def get_session():
user_session = session.get('user_id', 'default_session')
return jsonify({"session": user_session})
if __name__ == '__main__':
socketio.run(app, host='0.0.0.0', port=5500)

Some files were not shown because too many files have changed in this diff Show More