This commit is contained in:
CakeCN
2024-12-03 16:21:19 +08:00
commit 4198ca63b1
975 changed files with 333413 additions and 0 deletions

Binary file not shown.

218
Html/app.py Normal file
View File

@@ -0,0 +1,218 @@
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
backboard_manager = BackBoardManager()
uuid2user_id = {}
user_id2uuid = {}
@app.route('/backboard')
def backboard():
return jsonify({'status': 'success'})
def realtime_response(config, realtime_action):
user_id = config['user_id']
folder_path = config['path']
useruuid = user_id2uuid[user_id]
if backboard_manager.get_backboard(useruuid) == None:
backboard_manager.add_backboard(useruuid, folder_path)
bb = backboard_manager.get_backboard(useruuid)
assert type(bb) == Backboard
bb.add_history(realtime_action)
if realtime_action['type'] == 'workspaceFolders':
bb.file_tree = realtime_action['fileTree']
if realtime_action['type'] == 'activeFile':
file_path = realtime_action['filePath']
assert type(file_path) == str
file_path = "".join(file_path.split(f'/{user_id}/{folder_path}/')[1:])
bb.active_file_path = file_path
with open(f"../{user_id}/{folder_path}/{file_path}") as f:
bb.active_file_content = f.read()
if realtime_action['type'] == 'paste':
file_path = realtime_action['filePath']
file_path = "".join(file_path.split(f'/{user_id}/{folder_path}/')[1:])
bb.pasted_file_path = file_path
bb.pasted_content = realtime_action['content']
print("config"+str(config))
print("realtime_action"+str(realtime_action))
pass
'''
Agent and Chat
'''
socketio = SocketIO(app, cors_allowed_origins="*")
agent_manager = AgentManager()
@socketio.on('connect')
def handle_connect():
user = request.args.get('username')
folder_name = request.args.get('folder')
user_uuid = user_id2uuid[user]
session['user_id'] = user_uuid
print(f'User connected with session user_id: {user_uuid}')
# 从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()
user_uuid, agent = agent_manager.new_agent(markdown, markdown_prompts, score_prompts, id=user_uuid)
join_room(user_uuid) # 将该用户加入以user_id为名的room
# 当接收到前端的消息时,触发此事件
@socketio.on('send_message')
def handle_message(data):
print(f"Message from client: {data}")
id = session.get('user_id')
print(id)
# 构造回复消息
res = agent_manager.invoke(id, data, backboard_manager.get_backboard(id).get_info_prompt())
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())
print("user "+ user_id + "uuid is"+ session['user_id'])
user_id2uuid[user_id] = session['user_id']
uuid2user_id[session['user_id']] = user_id
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)

72
Html/backboardManager.py Normal file
View File

@@ -0,0 +1,72 @@
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()
self.history = []
self.file_tree = "[]"
self.active_file_path = ""
self.active_file_content = ""
self.pasted_file_path = ""
self.pasted_content = ""
def next_chapter(self):
self.enter_chapter_time = time.time()
def get_info_prompt(self):
five_history = ""
for h in self.history[-5:]:
five_history += h['type'] + "\n" + h.get('filePath', '') + "\n\n"
return (f"###Global Info:###"
f"- User is {self.user_id}"
f"- User's total study time is {self.get_deltatime_mmss(self.create_time, time.time())}"
f"- User's current chapter study time is {self.get_deltatime_mmss(self.enter_chapter_time, time.time())}"
f"- Activated file path: {self.active_file_path}"
f"- Activated file content (current editing 10 lines): "
f"```"
f"{self.active_file_content[-10:]}"
f"```"
f"- Last five action:{five_history}"
f"- File tree: {self.file_tree}")
def add_history(self, realtime_action):
if(realtime_action['type']=='config'):return
if len(self.history)!=0:
if (self.history[-1]['type']=='edit'):
if(self.history[-1]['filepath'] == realtime_action['filepath']):
self.history[-1]['content'] = realtime_action['content']
return
self.history.append(realtime_action)
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

@@ -0,0 +1,80 @@
3
2166 9133 9705
77
2166
9133
9705
9705
9705
9133
9705
2414
9133
9133
9133
2166
2166
2166
9705
9705
9133
9705
9133
2166
9133
9705
7742
9133
2166
2166
9133
9133
9133
9705
9705
2166
9705
5718
2166
9705
9705
2166
2166
9705
9133
4154
9705
9133
2166
4098
9705
9133
9705
9705
3893
9705
2166
9705
2166
9705
9705
9705
2166
2565
9133
9133
9705
2166
2166
2450
2166
2166
9705
2166
8961
6674
9705
9705
2166
9133
8667

View File

@@ -0,0 +1,77 @@
0
1
2
2
2
1
2
-1
1
1
1
0
0
0
2
2
1
2
1
0
1
2
-1
1
0
0
1
1
1
2
2
0
2
-1
0
2
2
0
0
2
1
-1
2
1
0
-1
2
1
2
2
-1
2
0
2
0
2
2
2
0
-1
1
1
2
0
0
-1
0
0
2
0
-1
-1
2
2
0
1
-1

View File

@@ -0,0 +1,75 @@
30
581 603 793 1313 2185 2257 2556 2572 2804 2938 3253 3687 4057 4124 4348 4889 5010 5406 5586 5604 5615 5680 6057 6076 6342 6613 7120 7756 8662 9557
72
7756
8662
1431
5615
5615
8662
2572
6235
581
5586
2752
793
5604
6057
4348
2556
4124
6057
6397
1313
5680
2804
3687
7120
7756
793
6613
6076
5604
2556
6076
9983
3253
7120
7120
4348
581
2257
793
5680
5010
2257
5406
4348
7120
1313
8662
793
4348
5615
7756
7756
6613
9557
5010
3253
2938
6076
581
6342
6076
6342
1313
4057
160
5604
2938
6057
3253
4057
7826
7120

View File

@@ -0,0 +1,72 @@
27
28
-1
20
20
28
7
-1
0
18
-1
2
19
22
14
6
13
22
-1
3
21
8
11
26
27
2
25
23
19
6
23
-1
10
26
26
14
0
5
2
21
16
5
17
14
26
3
28
2
14
20
27
27
25
29
16
10
9
23
0
24
23
24
3
12
-1
19
9
22
10
12
-1
26

View File

@@ -0,0 +1,70 @@
63
617 657 668 728 989 1075 1461 1577 1731 2677 2688 2880 2901 3009 3086 3200 3445 3466 3491 3555 3567 3602 3617 3633 3885 3894 4135 4314 4669 4831 4835 4883 5009 5031 5041 5076 5097 5327 5451 5698 5720 6147 6176 6411 6614 6732 6803 6865 7092 7510 7925 8211 8523 8584 8588 9105 9418 9543 9585 9822 9870 9894 9909
67
6865
5009
5042
617
9870
9822
7510
3609
3555
5451
2880
9894
9870
657
7925
9822
728
3086
9585
5720
1577
6803
5009
5327
3555
4472
3602
8523
3466
6803
9894
989
3602
6614
9870
8211
5720
3086
3567
9894
9909
5009
3491
9105
617
3864
5076
6147
5720
6176
6176
7092
3617
2688
2473
6147
580
3894
3086
3633
8584
5698
3491
6614
6176
668
7888

View File

@@ -0,0 +1,67 @@
47
32
-1
0
60
59
49
-1
19
38
11
61
60
1
50
59
3
14
58
40
7
46
32
37
19
-1
21
52
17
46
61
4
21
44
60
51
40
14
20
61
62
32
18
55
0
-1
35
41
40
42
42
48
22
10
-1
41
-1
25
14
23
53
39
18
44
42
2
-1

View File

@@ -0,0 +1,66 @@
8
488 1515 2200 4293 5232 5698 5935 6032
63
488
6032
1110
5935
488
5698
1515
2200
488
6032
5193
1515
5935
5935
1515
488
2200
6032
5232
1515
6032
2200
488
1515
5698
5935
5698
6032
1515
5698
5935
2200
5935
5232
6032
2200
2200
5232
5232
5698
488
2200
1515
2200
5698
5232
488
4293
5232
4672
6032
1515
488
5232
4293
488
1515
5935
6032
2200
5935
2640
5935

View File

@@ -0,0 +1,63 @@
0
7
-1
6
0
5
1
2
0
7
-1
1
6
6
1
0
2
7
4
1
7
2
0
1
5
6
5
7
1
5
6
2
6
4
7
2
2
4
4
5
0
2
1
2
5
4
0
3
4
-1
7
1
0
4
3
0
1
6
7
2
6
-1
6

View File

@@ -0,0 +1,47 @@
19
50 316 497 2917 3296 3720 3916 5160 5841 6514 7195 7366 7621 7985 7997 8083 8273 9783 9990
44
7985
5160
7195
3916
7985
7366
2229
2917
7621
7985
2030
5160
6105
6514
9783
3720
8273
316
7621
8083
8273
3916
316
9060
5160
5160
7621
3916
7985
9783
3296
3132
7985
7997
50
7621
7985
3296
497
8083
5841
316
7985
3916

View File

@@ -0,0 +1,44 @@
13
7
10
6
13
11
-1
3
12
13
-1
7
-1
9
17
5
16
1
12
15
16
6
1
-1
7
7
12
6
13
17
4
-1
13
14
0
12
13
4
2
15
8
1
13
6

View File

@@ -0,0 +1,98 @@
83
301 548 597 641 690 961 972 1275 1713 1859 1930 2202 2231 2264 2379 2495 2531 2767 2804 2840 2896 3115 3207 3282 3507 3552 3866 3895 4017 4071 4298 4357 4635 4726 4867 5014 5080 5100 5116 5271 5325 5339 5544 5555 5593 5612 5642 5659 5914 6164 6398 6480 6773 6869 6976 7097 7109 7139 7180 7341 7664 7910 7924 8071 8107 8160 8351 8742 8773 8828 8840 9095 9120 9170 9229 9248 9401 9403 9536 9608 9638 9651 9912
95
8160
9401
548
3895
8840
8828
9608
8840
6869
9651
7447
8925
6773
3207
972
9403
548
5612
5325
6480
5659
4357
9401
9473
5544
3840
8742
6164
5555
5014
1823
5325
9748
4357
9474
7097
7274
2264
9248
7097
9608
1930
5612
3282
961
4867
2896
5339
5116
2767
6719
4017
972
8742
3552
9479
8828
690
8071
641
548
2379
4017
7664
9638
641
5914
8828
2202
9912
1930
301
8071
6398
5271
4192
690
9608
548
5271
5271
5642
972
6976
1859
5271
2767
970
3507
8742
2264
5612
9651
548
7097

View File

@@ -0,0 +1,95 @@
65
76
1
27
70
69
79
70
53
81
-1
-1
52
22
6
77
1
45
40
51
47
31
76
-1
42
-1
67
49
43
35
-1
40
-1
31
-1
55
-1
13
75
55
79
10
45
23
5
34
20
41
38
17
-1
28
6
67
25
-1
69
4
63
3
1
14
28
60
80
3
48
69
11
82
10
0
63
50
39
-1
4
79
1
39
39
46
6
54
9
39
17
-1
24
67
13
45
81
1
55

View File

@@ -0,0 +1,72 @@
25
173 495 669 1183 1730 1979 2147 3005 3249 3336 3551 4039 4081 4728 4766 5066 5767 6458 7516 7776 7785 8199 8222 8245 9680
69
4728
173
3249
9565
1979
3249
1183
4081
7884
1730
4081
8115
3249
4766
3249
9680
7516
495
4728
3734
8425
4728
6458
9680
4039
3912
7785
1183
173
2147
9680
2147
7785
2147
4728
669
3264
3551
3249
4039
5066
6779
3249
3005
173
4081
7776
5767
4039
5767
5066
4728
173
1730
9680
8199
3005
7516
9680
8199
8222
8245
1979
3551
2147
5767
8222
8222
2147

View File

@@ -0,0 +1,69 @@
13
0
8
-1
5
8
3
12
-1
4
12
-1
8
14
8
24
18
1
13
-1
-1
13
17
24
11
-1
20
3
0
6
24
6
20
6
13
2
-1
10
8
11
15
-1
8
7
0
12
19
16
11
16
15
13
0
4
24
21
7
18
24
21
22
23
5
10
6
16
22
22
6

View File

@@ -0,0 +1,67 @@
39
9 518 886 1485 1585 1829 1971 2271 2371 2427 2528 2932 3066 3476 3527 3806 4203 4215 4430 4519 4786 4897 4938 5151 5733 6870 7008 7127 7238 7415 8011 8347 8441 8701 9034 9050 9453 9910 9931
64
3527
2427
1971
1829
2932
2932
8114
7415
1585
3476
8347
9453
6870
3066
2427
9910
3066
8011
8701
9453
4897
5733
1829
3806
4786
1485
2528
9910
7415
9931
518
518
3476
2932
5733
2271
9050
9
4430
886
3476
7238
4519
7054
1829
2271
3066
9050
2371
9034
8011
2932
4519
7415
3066
9050
9050
1485
8441
9093
4938
9453
8347
2371

View File

@@ -0,0 +1,64 @@
14
9
6
5
11
11
-1
29
4
13
31
36
25
12
9
37
12
30
33
36
21
24
5
15
20
3
10
37
29
38
1
1
13
11
24
7
35
0
18
2
13
28
19
-1
5
7
12
35
8
34
30
11
19
29
12
35
35
3
32
-1
22
36
31
8

View File

@@ -0,0 +1,27 @@
56
208 213 1004 1459 1480 1705 1753 1866 1900 2029 2116 2603 2679 2913 3272 3312 3492 3805 3896 3938 4089 4270 4293 4531 4589 4707 4746 4821 4835 4853 4870 4939 4996 5013 5036 5339 5659 6143 6182 6248 6406 6652 7017 7154 7702 7740 8065 8309 8330 8353 9075 9260 9409 9430 9477 9534
24
3938
4270
1705
3312
6406
8309
2029
1705
213
5952
3312
1480
4821
208
3938
4293
9430
4589
5013
4707
2029
4531
5659
1004

View File

@@ -0,0 +1,24 @@
19
21
5
15
40
47
9
5
1
-1
15
4
27
0
19
22
53
24
33
25
9
23
36
2

View File

@@ -0,0 +1,76 @@
54
132 345 359 430 534 561 691 971 1070 1251 1586 1681 1954 2300 2482 2635 2690 2810 2883 2967 3018 3123 3418 4425 4840 4990 5007 5069 5359 5825 5892 6034 6471 6472 6668 6868 6996 7023 7284 7427 7445 7459 7562 7631 7662 8144 8407 8516 8611 8710 8964 8966 9206 9577
73
7427
8003
7445
2810
7562
8516
7459
6472
4425
7631
8710
7445
1954
1586
7631
8964
7284
3418
4990
8611
2967
7459
8407
971
8611
7671
1681
3018
1586
4814
6034
359
67
2810
971
122
8964
4840
971
4776
2967
6034
569
561
561
8964
8966
3418
2883
6472
4840
8390
6472
8516
6471
2635
691
9577
1892
3018
2810
534
6472
1160
7562
6471
8964
2178
5825
8964
5825
6996
132

View File

@@ -0,0 +1,73 @@
39
-1
40
17
42
47
41
33
23
43
49
40
12
10
43
50
38
22
25
48
19
41
46
7
48
-1
11
20
10
-1
31
2
-1
17
7
-1
50
24
7
-1
19
31
-1
5
5
50
51
22
18
33
24
-1
33
47
32
15
6
53
-1
20
17
4
33
-1
42
32
50
-1
29
50
29
36
0

View File

@@ -0,0 +1,39 @@
71
219 273 1138 1185 1292 1537 1580 1619 1659 1766 1975 2236 2291 2340 2374 2601 2615 2761 2849 2916 3021 3127 3350 3440 3829 4021 4081 4111 4179 4525 4621 4777 5137 5270 5515 6122 6173 6477 6762 6784 6848 6856 6900 7164 7187 7220 7236 7267 7379 7519 7555 7798 7909 7968 8278 8283 8554 8681 8729 9065 9376 9464 9478 9478 9569 9615 9835 9888 9893 9935 9970
36
2374
3127
7220
6762
8681
6274
9970
2291
9065
9376
9888
273
2291
1185
9935
4858
3440
2236
3440
9478
7187
4242
7164
9893
2615
9376
8043
219
8278
9478
7555
4777
7968
6477
4081
8283

View File

@@ -0,0 +1,36 @@
14
21
45
38
57
-1
70
12
59
60
67
1
12
3
69
-1
23
11
23
62
44
-1
43
68
16
60
-1
0
54
62
50
31
53
37
26
55

View File

@@ -0,0 +1,94 @@
72
399 471 474 815 982 1101 1186 1210 1392 1840 1921 2023 2088 2180 2187 2229 2638 2905 2942 3041 3420 3541 3671 4075 4254 4437 4542 4833 4844 4921 5062 5541 5593 5648 5718 5824 6017 6210 6220 6257 6664 6668 6783 6787 6969 7098 7338 7409 7471 7472 7523 7673 7725 7733 7804 7862 7864 8132 8152 8169 8219 8360 8650 8797 8938 9028 9039 9316 9356 9489 9535 9744
91
6257
4542
4921
7804
9039
2187
2180
82
9356
6210
5718
3408
4542
982
3420
2905
7409
4254
1101
7725
8650
3420
8797
6043
2088
9028
1375
7733
1840
2942
474
6017
9299
5089
8152
6783
399
982
5718
8152
5062
815
7098
7338
2942
3671
1392
7725
3541
8169
9535
1840
7864
6787
815
8938
6210
2905
982
8132
7862
8797
2088
7472
399
9039
2088
7409
9744
8650
2180
5718
1101
399
1840
4075
7098
7725
7101
4833
6969
2023
4844
4542
9535
1210
815
399
982
7472
1706

View File

@@ -0,0 +1,91 @@
39
26
29
54
66
14
13
-1
68
37
34
-1
26
4
20
17
47
24
5
52
62
20
63
-1
12
65
-1
53
9
18
2
36
-1
-1
58
42
0
4
34
58
30
3
45
46
18
22
8
52
21
59
70
9
56
43
3
64
37
17
4
57
55
63
12
49
0
66
12
47
71
62
13
34
5
0
9
23
45
52
-1
27
44
11
28
26
70
7
3
0
4
49
-1

View File

@@ -0,0 +1,22 @@
98
172 293 327 394 398 403 403 726 993 1480 1495 1561 1721 1722 1758 1923 1954 1967 1991 2296 2718 2794 2809 2858 2956 3001 3076 3188 3207 3232 3244 3328 3352 4066 4390 4515 4536 4966 4973 4981 5150 5175 5266 5381 5432 5542 5573 5900 5929 5959 5966 6075 6082 6170 6415 6467 6553 6558 6582 6642 6661 6668 6703 6817 6851 6875 6972 7045 7337 7356 7462 7507 7522 7748 7960 8036 8040 8187 8223 8230 8256 8487 8533 8755 8994 9098 9100 9211 9239 9327 9359 9366 9608 9654 9705 9710 9968 9988
19
5573
8922
8230
1059
172
7960
6703
6553
993
3188
2809
9968
6875
2794
9098
5900
9327
5929
7462

View File

@@ -0,0 +1,19 @@
46
-1
79
-1
0
74
62
56
8
27
22
96
65
21
85
47
89
48
70

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,76 @@
57
74 100 149 263 556 586 663 743 914 1046 1207 1217 1466 1712 2254 2334 2464 2898 2951 3046 3106 3227 3242 3261 3412 3548 3673 3737 3815 4028 4268 4663 5045 5054 5125 5298 5395 5636 5802 5973 6046 6437 6644 6844 6911 7121 7524 7594 7830 8257 8465 8749 8771 8812 9313 9759 9995
73
1275
663
1046
5298
2898
7830
7594
2464
556
5167
4977
6844
1669
4028
4268
7524
7830
4268
4663
556
7830
1217
3412
9313
5045
263
6046
3227
7594
3242
4663
556
8771
7594
7594
263
2464
7478
3227
1217
1712
9342
5125
6911
4663
6911
7524
2898
3815
5054
9997
9995
3261
743
3261
3815
6437
3261
6046
3815
2254
3261
743
586
743
3227
8812
3673
5973
3815
5125
3227
6911

View File

@@ -0,0 +1,73 @@
-1
6
9
35
17
48
47
16
4
-1
-1
43
-1
29
30
46
48
30
31
4
48
11
24
54
32
3
40
21
47
22
31
4
52
47
47
3
16
-1
21
11
13
-1
34
44
31
44
46
17
28
33
-1
56
23
7
23
28
41
23
40
28
14
23
7
5
7
21
53
26
39
28
34
21
44

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,41 @@
43
112 739 875 876 973 991 1161 1283 1542 1786 2023 2070 2205 2301 2584 2737 2769 3112 3210 3298 3649 3651 3903 3999 4116 4667 4746 5101 5447 5453 5803 5911 6262 6356 7303 7401 7728 8821 9082 9180 9644 9656 9796
38
875
739
9796
5803
5453
991
7401
4667
3999
875
5424
2205
2205
1283
7401
739
4746
9656
2584
2769
8821
876
3112
3210
4746
3651
3651
2070
2584
1786
2301
2737
9656
9656
2769
1161
1542
3298

View File

@@ -0,0 +1,38 @@
2
1
42
30
29
5
35
25
23
2
-1
12
12
7
35
1
26
41
14
16
37
3
17
18
26
21
21
11
14
9
13
15
41
41
16
6
8
19

View File

@@ -0,0 +1,52 @@
62
271 588 775 1229 1454 1487 1606 1935 1958 2025 2156 2275 2310 2397 2724 2795 2902 2938 2981 2992 3305 3699 3708 4009 4221 4374 4540 4595 4601 4615 4907 5102 5322 5573 5634 5811 6107 6429 6660 6692 6732 6842 6880 7524 7916 7920 8034 8042 8044 8072 8190 8421 8426 8430 8909 8929 8945 9062 9085 9560 9867 9964
49
2992
4221
6429
9964
9964
2025
8034
4176
2902
8909
1606
1218
8190
2981
5102
8421
6880
8426
9867
9677
8945
8426
5573
2902
1935
5634
8421
8190
775
8945
1454
6880
5811
5573
3305
8945
9085
37
8762
5708
8909
1958
2902
2397
8034
2025
9964
4595
1606

View File

@@ -0,0 +1,49 @@
19
24
37
61
61
9
46
-1
16
54
6
-1
50
18
31
51
42
52
60
-1
56
52
33
16
7
34
51
50
2
56
4
42
35
33
20
56
58
-1
-1
-1
54
8
16
13
46
9
61
27
6

View File

@@ -0,0 +1,9 @@
38
444 741 1013 1045 1394 1733 1966 2575 3446 3903 4179 4226 4235 4339 4457 4797 5081 5245 5882 6041 6204 6285 6325 6398 7107 7147 7191 7197 7617 7949 8190 8231 8675 8808 8997 9312 9406 9712
6
4235
1733
7107
1045
8675
6398

View File

@@ -0,0 +1,6 @@
12
5
24
3
32
23

View File

@@ -0,0 +1,44 @@
74
247 423 613 822 1091 1096 1135 1247 1251 1665 1856 1960 1987 2047 2892 2974 3185 3281 3333 3384 3592 3683 3786 3808 3819 4055 4177 4233 4239 4264 4291 4342 4417 4625 4824 4873 4935 5030 5178 5190 5237 5326 5622 5658 5824 5927 5946 5976 6172 6595 6601 6787 7254 7519 7627 7813 7905 7973 8023 8040 8104 8115 8194 8265 8291 8529 8601 8650 9251 9441 9802 9875 9900 9997
41
1960
5237
7813
4264
6595
5946
6787
8023
6172
1247
5658
1987
3252
2974
4417
2047
5190
4239
4935
4975
3333
3365
4824
8115
1251
7519
3281
7615
7254
6601
4342
8115
6601
8529
9997
423
7905
1705
5622
5237
247

View File

@@ -0,0 +1,41 @@
11
40
55
29
49
46
51
58
48
7
43
12
-1
15
32
13
39
28
36
-1
18
-1
34
61
8
53
17
-1
52
50
31
61
50
65
73
1
56
-1
42
40
0

View File

@@ -0,0 +1,15 @@
39
454 1197 1395 1576 2510 2543 2606 2686 2782 3147 3458 3853 3991 4444 4805 6119 6190 6549 6626 6982 7036 7086 7100 7447 7646 8301 8449 8480 8675 8676 8741 9305 9427 9465 9519 9524 9695 9766 9802
12
2782
9802
9305
6190
9695
454
3458
8449
4805
3991
6549
6982

View File

@@ -0,0 +1,12 @@
8
38
31
16
36
0
10
26
14
12
17
19

View File

@@ -0,0 +1,42 @@
73
1 40 189 789 817 1157 1315 1388 1507 1748 1893 1929 1999 2169 2453 2718 2975 2989 3064 3487 3596 3744 3921 4065 4240 4304 4424 4439 4529 4687 4865 5210 5301 5305 5409 5468 5471 5495 5602 5605 6113 6116 6202 6276 6280 6686 6770 6865 7142 7192 7217 7610 7661 7746 7973 8047 8079 8182 8233 8288 8296 8342 8435 8527 8615 8781 8822 8881 9225 9339 9543 9768 9951
39
5210
5210
6865
1507
4240
9543
2975
6113
789
8079
8615
3417
4240
1507
5301
1507
6865
5605
7217
8881
7399
1999
7142
3921
7746
9052
5495
5495
8615
7810
7192
6113
6113
7973
9951
4065
1157
8233
4065

View File

@@ -0,0 +1,39 @@
31
31
47
8
24
70
16
40
3
56
64
-1
24
8
32
8
47
39
50
67
-1
12
48
22
53
-1
37
37
64
-1
49
40
40
54
72
23
5
58
23

View File

@@ -0,0 +1,61 @@
# 二分查找与二分答案
## 二分查找
### 引入
二分是一个很简单基础,但很重要的知识点,为以后许多高级的数据结构与算法铺垫。
下面是一个用二分的简单场景:
假设小明从0到1000之间选择了一个数字但不告诉你你可以不断猜测这个数每次猜测小明会告知你的猜测得过大还是过小问最多几次就一定能猜中
答案是利用二分查找的原理猜测11次即可。
1. 对于0到1000的答案备选区猜测中位数500假设过小
2. 则对于501到1000的答案备选区猜测750假设过大
3. 则对于501到749的答案备选区猜测625假设过小
4. 则对于626到749区间......
5. 688-749
6. 718-749
7. 734-749
8. 742-749
9. 746-749
10. 748-749
11. 749-749
在最差的情况下第11次的答案备选区就一定长度为1了也就是必然是答案。
因此如果序列是有序的,就可以通过二分查找快速定位所需要的数据。
#### 思考题询问Agent以学习计算方法或验证你的答案
对于上面那个题目如果问题区间是1到4000最差情况下需要猜测几次
### 练习:二分查找
试试对于下面的题目,用代码实现一下二分查找。
#### 题目:有序数组寻址
给出一个长度为n的有序数组从小到大有q次询问对于每次询问输出指定数在数组中的下标。如果不存在则输出-1。
##### 输入
第一行一个整数n。(1<=n<=10^5)
第二行n个用空格分开的整数ai。(0<=ai<=10^8)
第三行一个整数q表示询问的次数。(1<=q<=10^4)
后q行每行一个整数b表示询问的数。(0<=b<=10^8)
##### 输出
q行每行一个整数对应每次询问的返回结果。
##### 提示:
完成代码后通知Agent进行评测。
如果你还不完全会这个算法询问Agent获取提示并进行学习。

View File

@@ -0,0 +1,13 @@
## 这是一个Makedown文件
### 教学目标
### 第一章:什么是计算机
#### 例1-1计算机的组成部分是
### 第二章:什么是算法
![图片](./image/example/p1.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 MiB

View File

@@ -0,0 +1,33 @@
# 二分查找与二分答案
## 二分查找
### 引入
本小节进行二分查找的引入,首先帮助学生理解教案引入章节的故事。
确保学生理解了引入后,在进行思考题。
如果不进行思考题,则询问一下是否不进行思考题,确认后进入下一节。
如果进行思考题告知学生计算方法并验证答案答案是13次
计算方法:
4000是初始答案区间长度每次询问能够排除一半的区间当区间长度小于等于1时再进行一次猜测就一定是答案。
4000不断除以2除12次就小于等于1了再加一次就一定是答案。最后是12+1=13次。
比4000大的最小2的次方数4096就是2的12次方这里的12就是答案中的12或者写作"上取整(log2(4000))")
询问学生,当学生告知理解后,进入下一节。
### 练习:二分查找
如果学生在实现的过程中遇到问题,不要直接告知完整代码如何编写,询问其当前遇到的是什么问题,并帮助学生一步步完成题目。
实现代码后,全部通过测试数据后才可以进入下一节。
本体测试点文件夹名 `twice_split。`
_require_tools=judge

View File

@@ -0,0 +1,3 @@
# 二分查找与二分答案
## 二分查找

View File

@@ -0,0 +1,12 @@
# 二分查找与二分答案
## 二分查找
### 引入
1. 学生独立给出了思考题的答案10分 或者 学生在Agent指导下学会思考题10分
### 练习:二分查找
1. 学生最终代码通过所有测试点30分
2. 学生独立在10分钟内完成题目10分 或者 学生在Agent指导下10分钟内完成题目5分

16
Html/config.ini Normal file
View File

@@ -0,0 +1,16 @@
[Global]
base_chat_url1 = http://58.198.177.26:8000/v1
base_chat_url = https://api.zyai.online/v1
api_key1 = ollama
api_key = sk-B31NVWeWuvbkEnUgA5913e4c63Ac40E7A1B084742299E57f
target_path = C:/CAKE/Game/Unity/Repositorys/auto-ucg-game
project_name = auto-ucg-game
writeable_file_folder = Assets/HotUpdate/Gurouce/
terminal_name = Windows PowerShell
[WebSocket]
listen_port = 3001
server_address = ws://localhost:3000/myService
agent_process_provider_host = localhost
agent_process_provider_port = 3002

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

9
Html/readme.md Normal file
View File

@@ -0,0 +1,9 @@
## 开发Tips
1. Vscode需要设置cookie后才可以正确访问这可以用来作为用户登录凭证
2. 为了将vscode的无必要控制入口删掉将对应的服务器上的settings.json进行修改
![1728381936172](image/readme/1728381936172.png)
2. 打开指定的文件夹的方式:`http://localhost:9888/?workspace=/mnt/c/CAKE/vscode/example_folder&folder=/mnt/c/CAKE/vscode/example_folder`

View File

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

Binary file not shown.

View File

@@ -0,0 +1,171 @@
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

@@ -0,0 +1,51 @@
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

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

View File

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

Binary file not shown.

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