cnhkmcp 2.1.2__py3-none-any.whl → 2.1.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. {cnhkmcp-2.1.2.dist-info → cnhkmcp-2.1.3.dist-info}/METADATA +1 -1
  2. cnhkmcp-2.1.3.dist-info/RECORD +6 -0
  3. cnhkmcp-2.1.3.dist-info/top_level.txt +1 -0
  4. cnhkmcp/__init__.py +0 -125
  5. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/README.md +0 -38
  6. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/ace.log +0 -0
  7. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/config.json +0 -6
  8. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/get_knowledgeBase_tool/ace_lib.py +0 -1510
  9. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/get_knowledgeBase_tool/fetch_all_datasets.py +0 -157
  10. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/get_knowledgeBase_tool/fetch_all_documentation.py +0 -132
  11. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/get_knowledgeBase_tool/fetch_all_operators.py +0 -99
  12. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/get_knowledgeBase_tool/helpful_functions.py +0 -180
  13. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/icon.ico +0 -0
  14. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/icon.png +0 -0
  15. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/test.txt +0 -1
  16. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/main.py +0 -576
  17. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/process_knowledge_base.py +0 -281
  18. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/rag_engine.py +0 -408
  19. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/requirements.txt +0 -7
  20. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/run.bat +0 -3
  21. cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242//321/211/320/266/320/246/321/206/320/274/320/261/321/210/342/224/220/320/240/321/210/320/261/320/234/321/206/320/231/320/243/321/205/342/225/235/320/220/321/206/320/230/320/241.py +0 -265
  22. cnhkmcp/untracked/APP/.gitignore +0 -32
  23. cnhkmcp/untracked/APP/MODULAR_STRUCTURE.md +0 -112
  24. cnhkmcp/untracked/APP/README.md +0 -309
  25. cnhkmcp/untracked/APP/Tranformer/Transformer.py +0 -4985
  26. cnhkmcp/untracked/APP/Tranformer/ace.log +0 -0
  27. cnhkmcp/untracked/APP/Tranformer/ace_lib.py +0 -1510
  28. cnhkmcp/untracked/APP/Tranformer/helpful_functions.py +0 -180
  29. cnhkmcp/untracked/APP/Tranformer/output/Alpha_candidates.json +0 -2421
  30. cnhkmcp/untracked/APP/Tranformer/output/Alpha_candidates_/321/207/320/264/342/225/221/321/204/342/225/233/320/233.json +0 -654
  31. cnhkmcp/untracked/APP/Tranformer/output/Alpha_generated_expressions_error.json +0 -1034
  32. cnhkmcp/untracked/APP/Tranformer/output/Alpha_generated_expressions_success.json +0 -444
  33. cnhkmcp/untracked/APP/Tranformer/output/Alpha_generated_expressions_/321/207/320/264/342/225/221/321/204/342/225/233/320/233/321/205/320/237/320/277/321/207/320/253/342/224/244/321/206/320/236/320/265/321/210/342/225/234/342/225/234/321/205/320/225/320/265Machine_lib.json +0 -22
  34. cnhkmcp/untracked/APP/Tranformer/parsetab.py +0 -60
  35. cnhkmcp/untracked/APP/Tranformer/template_summary.txt +0 -3182
  36. cnhkmcp/untracked/APP/Tranformer/transformer_config.json +0 -7
  37. cnhkmcp/untracked/APP/Tranformer/validator.py +0 -889
  38. cnhkmcp/untracked/APP/ace.log +0 -69
  39. cnhkmcp/untracked/APP/ace_lib.py +0 -1510
  40. cnhkmcp/untracked/APP/blueprints/__init__.py +0 -6
  41. cnhkmcp/untracked/APP/blueprints/feature_engineering.py +0 -347
  42. cnhkmcp/untracked/APP/blueprints/idea_house.py +0 -221
  43. cnhkmcp/untracked/APP/blueprints/inspiration_house.py +0 -432
  44. cnhkmcp/untracked/APP/blueprints/paper_analysis.py +0 -570
  45. cnhkmcp/untracked/APP/custom_templates/templates.json +0 -1257
  46. cnhkmcp/untracked/APP/give_me_idea/BRAIN_Alpha_Template_Expert_SystemPrompt.md +0 -400
  47. cnhkmcp/untracked/APP/give_me_idea/ace_lib.py +0 -1510
  48. cnhkmcp/untracked/APP/give_me_idea/alpha_data_specific_template_master.py +0 -252
  49. cnhkmcp/untracked/APP/give_me_idea/fetch_all_datasets.py +0 -157
  50. cnhkmcp/untracked/APP/give_me_idea/fetch_all_operators.py +0 -99
  51. cnhkmcp/untracked/APP/give_me_idea/helpful_functions.py +0 -180
  52. cnhkmcp/untracked/APP/give_me_idea/what_is_Alpha_template.md +0 -11
  53. cnhkmcp/untracked/APP/helpful_functions.py +0 -180
  54. cnhkmcp/untracked/APP/hkSimulator/ace_lib.py +0 -1497
  55. cnhkmcp/untracked/APP/hkSimulator/autosimulator.py +0 -447
  56. cnhkmcp/untracked/APP/hkSimulator/helpful_functions.py +0 -180
  57. cnhkmcp/untracked/APP/mirror_config.txt +0 -20
  58. cnhkmcp/untracked/APP/operaters.csv +0 -129
  59. cnhkmcp/untracked/APP/requirements.txt +0 -53
  60. cnhkmcp/untracked/APP/run_app.bat +0 -28
  61. cnhkmcp/untracked/APP/run_app.sh +0 -34
  62. cnhkmcp/untracked/APP/setup_tsinghua.bat +0 -39
  63. cnhkmcp/untracked/APP/setup_tsinghua.sh +0 -43
  64. cnhkmcp/untracked/APP/simulator/alpha_submitter.py +0 -404
  65. cnhkmcp/untracked/APP/simulator/simulator_wqb.py +0 -618
  66. cnhkmcp/untracked/APP/ssrn-3332513.pdf +6 -109201
  67. cnhkmcp/untracked/APP/static/brain.js +0 -589
  68. cnhkmcp/untracked/APP/static/decoder.js +0 -1540
  69. cnhkmcp/untracked/APP/static/feature_engineering.js +0 -1729
  70. cnhkmcp/untracked/APP/static/idea_house.js +0 -937
  71. cnhkmcp/untracked/APP/static/inspiration.js +0 -465
  72. cnhkmcp/untracked/APP/static/inspiration_house.js +0 -868
  73. cnhkmcp/untracked/APP/static/paper_analysis.js +0 -390
  74. cnhkmcp/untracked/APP/static/script.js +0 -3082
  75. cnhkmcp/untracked/APP/static/simulator.js +0 -597
  76. cnhkmcp/untracked/APP/static/styles.css +0 -3127
  77. cnhkmcp/untracked/APP/static/usage_widget.js +0 -508
  78. cnhkmcp/untracked/APP/templates/alpha_inspector.html +0 -511
  79. cnhkmcp/untracked/APP/templates/feature_engineering.html +0 -960
  80. cnhkmcp/untracked/APP/templates/idea_house.html +0 -564
  81. cnhkmcp/untracked/APP/templates/index.html +0 -932
  82. cnhkmcp/untracked/APP/templates/inspiration_house.html +0 -861
  83. cnhkmcp/untracked/APP/templates/paper_analysis.html +0 -91
  84. cnhkmcp/untracked/APP/templates/simulator.html +0 -343
  85. cnhkmcp/untracked/APP/templates/transformer_web.html +0 -580
  86. cnhkmcp/untracked/APP/usage.md +0 -351
  87. cnhkmcp/untracked/APP//321/207/342/225/235/320/250/321/205/320/230/320/226/321/204/342/225/225/320/220/321/211/320/221/320/243/321/206/320/261/320/265/ace_lib.py +0 -1510
  88. cnhkmcp/untracked/APP//321/207/342/225/235/320/250/321/205/320/230/320/226/321/204/342/225/225/320/220/321/211/320/221/320/243/321/206/320/261/320/265/brain_alpha_inspector.py +0 -712
  89. cnhkmcp/untracked/APP//321/207/342/225/235/320/250/321/205/320/230/320/226/321/204/342/225/225/320/220/321/211/320/221/320/243/321/206/320/261/320/265/helpful_functions.py +0 -180
  90. cnhkmcp/untracked/APP//321/210/342/224/220/320/240/321/210/320/261/320/234/321/206/320/231/320/243/321/205/342/225/235/320/220/321/206/320/230/320/241.py +0 -2456
  91. cnhkmcp/untracked/arXiv_API_Tool_Manual.md +0 -490
  92. cnhkmcp/untracked/arxiv_api.py +0 -229
  93. cnhkmcp/untracked/forum_functions.py +0 -998
  94. cnhkmcp/untracked/mcp/321/206/320/246/320/227/321/204/342/225/227/342/225/242/321/210/320/276/342/225/221/321/205/320/255/320/253/321/207/320/231/320/2302_/321/205/320/266/320/222/321/206/320/256/320/254/321/205/320/236/320/257/321/207/320/231/320/230/321/205/320/240/320/277/321/205/320/232/320/270/321/204/342/225/225/320/235/321/204/342/225/221/320/226/321/206/342/225/241/320/237/321/210/320/267/320/230/321/205/320/251/320/270/321/205/342/226/221/342/226/222/321/210/320/277/320/245/321/210/342/224/220/320/251/321/204/342/225/225/320/272/forum_functions.py +0 -407
  95. cnhkmcp/untracked/mcp/321/206/320/246/320/227/321/204/342/225/227/342/225/242/321/210/320/276/342/225/221/321/205/320/255/320/253/321/207/320/231/320/2302_/321/205/320/266/320/222/321/206/320/256/320/254/321/205/320/236/320/257/321/207/320/231/320/230/321/205/320/240/320/277/321/205/320/232/320/270/321/204/342/225/225/320/235/321/204/342/225/221/320/226/321/206/342/225/241/320/237/321/210/320/267/320/230/321/205/320/251/320/270/321/205/342/226/221/342/226/222/321/210/320/277/320/245/321/210/342/224/220/320/251/321/204/342/225/225/320/272/platform_functions.py +0 -2415
  96. cnhkmcp/untracked/mcp/321/206/320/246/320/227/321/204/342/225/227/342/225/242/321/210/320/276/342/225/221/321/205/320/255/320/253/321/207/320/231/320/2302_/321/205/320/266/320/222/321/206/320/256/320/254/321/205/320/236/320/257/321/207/320/231/320/230/321/205/320/240/320/277/321/205/320/232/320/270/321/204/342/225/225/320/235/321/204/342/225/221/320/226/321/206/342/225/241/320/237/321/210/320/267/320/230/321/205/320/251/320/270/321/205/342/226/221/342/226/222/321/210/320/277/320/245/321/210/342/224/220/320/251/321/204/342/225/225/320/272/user_config.json +0 -31
  97. cnhkmcp/untracked/mcp/321/206/320/246/320/227/321/204/342/225/227/342/225/242/321/210/320/276/342/225/221/321/205/320/255/320/253/321/207/320/231/320/2302_/321/205/320/266/320/222/321/206/320/256/320/254/321/205/320/236/320/257/321/207/320/231/320/230/321/205/320/240/320/277/321/205/320/232/320/270/321/204/342/225/225/320/235/321/204/342/225/221/320/226/321/206/342/225/241/320/237/321/210/320/267/320/230/321/205/320/251/320/270/321/205/342/226/221/342/226/222/321/210/320/277/320/245/321/210/342/224/220/320/251/321/204/342/225/225/320/272//321/210/320/276/320/271AI/321/210/320/277/342/225/227/321/210/342/224/220/320/251/321/204/342/225/225/320/272/321/206/320/246/320/227/321/206/320/261/320/263/321/206/320/255/320/265/321/205/320/275/320/266/321/204/342/225/235/320/252/321/204/342/225/225/320/233/321/210/342/225/234/342/225/234/321/206/342/225/241/320/237/321/210/320/267/320/230/321/205/320/251/320/270.md +0 -101
  98. cnhkmcp/untracked/mcp/321/206/320/246/320/227/321/204/342/225/227/342/225/242/321/210/320/276/342/225/221/321/205/320/255/320/253/321/207/320/231/320/2302_/321/205/320/266/320/222/321/206/320/256/320/254/321/205/320/236/320/257/321/207/320/231/320/230/321/205/320/240/320/277/321/205/320/232/320/270/321/204/342/225/225/320/235/321/204/342/225/221/320/226/321/206/342/225/241/320/237/321/210/320/267/320/230/321/205/320/251/320/270/321/205/342/226/221/342/226/222/321/210/320/277/320/245/321/210/342/224/220/320/251/321/204/342/225/225/320/272//321/211/320/225/320/235/321/207/342/225/234/320/276/321/205/320/231/320/235/321/210/342/224/220/320/240/321/210/320/261/320/234/321/206/320/230/320/241_/321/205/320/276/320/231/321/210/320/263/320/225/321/205/342/224/220/320/225/321/210/320/266/320/221/321/204/342/225/233/320/255/321/210/342/225/241/320/246/321/205/320/234/320/225.py +0 -190
  99. cnhkmcp/untracked/platform_functions.py +0 -2886
  100. cnhkmcp/untracked/sample_mcp_config.json +0 -11
  101. cnhkmcp/untracked/user_config.json +0 -31
  102. cnhkmcp/untracked//321/207/320/264/342/225/221/321/204/342/225/233/320/233/321/205/320/237/320/222/321/210/320/220/320/223/321/206/320/246/320/227/321/206/320/261/320/263_BRAIN_Alpha_Test_Requirements_and_Tips.md +0 -202
  103. cnhkmcp/untracked//321/207/320/264/342/225/221/321/204/342/225/233/320/233/321/205/342/225/226/320/265/321/204/342/225/234/320/254/321/206/342/225/241/320/221_Alpha_explaination_workflow.md +0 -56
  104. cnhkmcp/untracked//321/207/320/264/342/225/221/321/204/342/225/233/320/233/321/205/342/225/226/320/265/321/204/342/225/234/320/254/321/206/342/225/241/320/221_BRAIN_6_Tips_Datafield_Exploration_Guide.md +0 -194
  105. cnhkmcp/untracked//321/207/320/264/342/225/221/321/204/342/225/233/320/233/321/205/342/225/226/320/265/321/204/342/225/234/320/254/321/206/342/225/241/320/221_BRAIN_Alpha_Improvement_Workflow.md +0 -101
  106. cnhkmcp/untracked//321/207/320/264/342/225/221/321/204/342/225/233/320/233/321/205/342/225/226/320/265/321/204/342/225/234/320/254/321/206/342/225/241/320/221_Dataset_Exploration_Expert_Manual.md +0 -436
  107. cnhkmcp/untracked//321/207/320/264/342/225/221/321/204/342/225/233/320/233/321/205/342/225/226/320/265/321/204/342/225/234/320/254/321/206/342/225/241/320/221_daily_report_workflow.md +0 -128
  108. cnhkmcp/untracked//321/211/320/225/320/235/321/207/342/225/234/320/276/321/205/320/231/320/235/321/210/342/224/220/320/240/321/210/320/261/320/234/321/206/320/230/320/241_/321/205/320/276/320/231/321/210/320/263/320/225/321/205/342/224/220/320/225/321/210/320/266/320/221/321/204/342/225/233/320/255/321/210/342/225/241/320/246/321/205/320/234/320/225.py +0 -190
  109. cnhkmcp-2.1.2.dist-info/RECORD +0 -111
  110. cnhkmcp-2.1.2.dist-info/top_level.txt +0 -1
  111. {cnhkmcp-2.1.2.dist-info → cnhkmcp-2.1.3.dist-info}/WHEEL +0 -0
  112. {cnhkmcp-2.1.2.dist-info → cnhkmcp-2.1.3.dist-info}/entry_points.txt +0 -0
  113. {cnhkmcp-2.1.2.dist-info → cnhkmcp-2.1.3.dist-info}/licenses/LICENSE +0 -0
@@ -1,6 +0,0 @@
1
- # Blueprints package
2
- from .idea_house import idea_house_bp
3
- from .paper_analysis import paper_analysis_bp
4
- from .feature_engineering import feature_engineering_bp
5
- from .inspiration_house import inspiration_house_bp
6
-
@@ -1,347 +0,0 @@
1
- from flask import Blueprint, render_template, request, jsonify
2
- import requests
3
- import json
4
- import logging
5
-
6
- feature_engineering_bp = Blueprint('feature_engineering', __name__)
7
-
8
- # Configure logging
9
- logging.basicConfig(level=logging.INFO)
10
- logger = logging.getLogger(__name__)
11
-
12
- @feature_engineering_bp.route('/')
13
- def feature_engineering():
14
- """Main feature engineering page"""
15
- return render_template('feature_engineering.html')
16
-
17
- @feature_engineering_bp.route('/api/test-deepseek', methods=['POST'])
18
- def test_deepseek_api():
19
- """Test API connection for both Deepseek and Kimi"""
20
- try:
21
- api_key = request.headers.get('X-API-Key')
22
- if not api_key:
23
- return jsonify({'success': False, 'error': 'API key is required'}), 400
24
-
25
- data = request.get_json() or {}
26
- provider = data.get('provider', 'deepseek')
27
- model_name = data.get('model_name', 'deepseek-chat')
28
-
29
- # Set up API endpoint and headers based on provider
30
- if provider == 'kimi':
31
- api_url = 'https://api.moonshot.cn/v1/chat/completions'
32
- headers = {
33
- 'Authorization': f'Bearer {api_key}',
34
- 'Content-Type': 'application/json'
35
- }
36
- else: # deepseek
37
- api_url = 'https://api.deepseek.com/chat/completions'
38
- headers = {
39
- 'Authorization': f'Bearer {api_key}',
40
- 'Content-Type': 'application/json'
41
- }
42
-
43
- test_data = {
44
- 'model': model_name,
45
- 'messages': [
46
- {'role': 'user', 'content': 'Hello, this is a test message.'}
47
- ],
48
- 'max_tokens': 10
49
- }
50
-
51
- response = requests.post(
52
- api_url,
53
- headers=headers,
54
- json=test_data,
55
- timeout=10
56
- )
57
-
58
- if response.status_code == 200:
59
- return jsonify({'success': True, 'message': f'{provider.capitalize()} API connection successful'})
60
- else:
61
- error_detail = response.text
62
- return jsonify({'success': False, 'error': f'API returned status {response.status_code}: {error_detail}'}), 400
63
-
64
- except requests.exceptions.RequestException as e:
65
- logger.error(f"API test error: {str(e)}")
66
- return jsonify({'success': False, 'error': f'Network error: {str(e)}'}), 500
67
- except Exception as e:
68
- logger.error(f"Unexpected error in API test: {str(e)}")
69
- return jsonify({'success': False, 'error': f'Unexpected error: {str(e)}'}), 500
70
-
71
- @feature_engineering_bp.route('/api/get-recommendations', methods=['POST'])
72
- def get_feature_engineering_recommendations():
73
- """Get feature engineering recommendations from API"""
74
- try:
75
- api_key = request.headers.get('X-API-Key')
76
- if not api_key:
77
- return jsonify({'success': False, 'error': 'API key is required'}), 400
78
-
79
- data = request.get_json()
80
- current_step = data.get('current_step', 1)
81
- data_field = data.get('data_field', '')
82
- previous_steps = data.get('previous_steps', [])
83
- current_data_state = data.get('current_data_state', 'raw data')
84
- provider = data.get('provider', 'deepseek')
85
- model_name = data.get('model_name', 'deepseek-chat')
86
-
87
- if not data_field:
88
- return jsonify({'success': False, 'error': 'Data field description is required'}), 400
89
-
90
- # Build the system prompt
91
- system_prompt = get_default_system_prompt_text()
92
-
93
- # Build the user prompt
94
- previous_steps_text = "None" if not previous_steps else ", ".join([f"Step {i+1}: {step}" for i, step in enumerate(previous_steps)])
95
-
96
- user_prompt = f"""Context:
97
- Current step: {current_step}
98
- Current data field: {data_field}
99
- Previous steps and categories used: {previous_steps_text}
100
- Current data state: {current_data_state}"""
101
-
102
- # Set up API endpoint and headers based on provider
103
- if provider == 'kimi':
104
- api_url = 'https://api.moonshot.cn/v1/chat/completions'
105
- headers = {
106
- 'Authorization': f'Bearer {api_key}',
107
- 'Content-Type': 'application/json'
108
- }
109
- else: # deepseek
110
- api_url = 'https://api.deepseek.com/chat/completions'
111
- headers = {
112
- 'Authorization': f'Bearer {api_key}',
113
- 'Content-Type': 'application/json'
114
- }
115
-
116
- api_data = {
117
- 'model': model_name,
118
- 'messages': [
119
- {'role': 'system', 'content': system_prompt},
120
- {'role': 'user', 'content': user_prompt}
121
- ],
122
- 'max_tokens': 8192,
123
- 'temperature': 0.7
124
- }
125
-
126
- response = requests.post(
127
- api_url,
128
- headers=headers,
129
- json=api_data,
130
- timeout=120
131
- )
132
-
133
- if response.status_code == 200:
134
- response_data = response.json()
135
- recommendations = response_data['choices'][0]['message']['content']
136
-
137
- return jsonify({
138
- 'success': True,
139
- 'recommendations': recommendations,
140
- 'current_step': current_step,
141
- 'data_field': data_field,
142
- 'previous_steps': previous_steps,
143
- 'current_data_state': current_data_state
144
- })
145
- else:
146
- error_detail = response.text
147
- logger.error(f"{provider.capitalize()} API error: {response.status_code} - {error_detail}")
148
- return jsonify({'success': False, 'error': f'API returned status {response.status_code}: {error_detail}'}), 400
149
-
150
- except requests.exceptions.RequestException as e:
151
- logger.error(f"API request error: {str(e)}")
152
- return jsonify({'success': False, 'error': f'Network error: {str(e)}'}), 500
153
- except Exception as e:
154
- logger.error(f"Unexpected error in get recommendations: {str(e)}")
155
- return jsonify({'success': False, 'error': f'Unexpected error: {str(e)}'}), 500
156
-
157
- @feature_engineering_bp.route('/api/continue-conversation', methods=['POST'])
158
- def continue_conversation():
159
- """Continue the conversation with follow-up questions"""
160
- try:
161
- api_key = request.headers.get('X-API-Key')
162
- if not api_key:
163
- return jsonify({'success': False, 'error': 'API key is required'}), 400
164
-
165
- data = request.get_json()
166
- conversation_history = data.get('conversation_history', [])
167
- user_message = data.get('user_message', '')
168
- custom_system_prompt = data.get('custom_system_prompt', None)
169
- provider = data.get('provider', 'deepseek')
170
- model_name = data.get('model_name', 'deepseek-chat')
171
-
172
- if not user_message:
173
- return jsonify({'success': False, 'error': 'User message is required'}), 400
174
-
175
- # Build conversation messages
176
- messages = []
177
-
178
- # Use custom system prompt if provided, otherwise use default
179
- if custom_system_prompt:
180
- system_prompt = custom_system_prompt
181
- else:
182
- system_prompt = get_default_system_prompt_text()
183
-
184
- messages.append({'role': 'system', 'content': system_prompt})
185
-
186
- # Add conversation history
187
- for msg in conversation_history:
188
- messages.append(msg)
189
-
190
- # Add new user message
191
- messages.append({'role': 'user', 'content': user_message})
192
- print(user_message)
193
-
194
- # Set up API endpoint and headers based on provider
195
- if provider == 'kimi':
196
- api_url = 'https://api.moonshot.cn/v1/chat/completions'
197
- headers = {
198
- 'Authorization': f'Bearer {api_key}',
199
- 'Content-Type': 'application/json'
200
- }
201
- else: # deepseek
202
- api_url = 'https://api.deepseek.com/chat/completions'
203
- headers = {
204
- 'Authorization': f'Bearer {api_key}',
205
- 'Content-Type': 'application/json'
206
- }
207
-
208
- api_data = {
209
- 'model': model_name,
210
- 'messages': messages,
211
- 'max_tokens': 8192,
212
- 'temperature': 0.7
213
- }
214
-
215
- response = requests.post(
216
- api_url,
217
- headers=headers,
218
- json=api_data,
219
- timeout=120
220
- )
221
-
222
- if response.status_code == 200:
223
- response_data = response.json()
224
- assistant_response = response_data['choices'][0]['message']['content']
225
-
226
- return jsonify({
227
- 'success': True,
228
- 'response': assistant_response
229
- })
230
- else:
231
- error_detail = response.text
232
- logger.error(f"{provider.capitalize()} API error: {response.status_code} - {error_detail}")
233
- return jsonify({'success': False, 'error': f'API returned status {response.status_code}: {error_detail}'}), 400
234
-
235
- except requests.exceptions.RequestException as e:
236
- logger.error(f"API request error: {str(e)}")
237
- return jsonify({'success': False, 'error': f'Network error: {str(e)}'}), 500
238
- except Exception as e:
239
- logger.error(f"Unexpected error in continue conversation: {str(e)}")
240
- return jsonify({'success': False, 'error': f'Unexpected error: {str(e)}'}), 500
241
-
242
- def get_default_system_prompt_text():
243
- """Get the default system prompt text"""
244
- return """You are an expert feature engineering assistant. Your job is to help design a multi-step feature engineering pipeline, with up to 6 steps, for a given data field. At each step, you will recommend the most viable feature engineering category (from a set of 15 categories) based on the current data state, the previous steps, and the high-level goal.
245
-
246
- Instructions:
247
-
248
- At each step, you will be given:
249
-
250
- The current step number.
251
-
252
- The current data field and its description.
253
-
254
- The previous steps and categories used (if any).
255
-
256
- The current data state (e.g., normalized, filtered, etc.).
257
-
258
- Your task is to:
259
-
260
- List the most viable feature engineering categories for the next step, choosing from the following 15 categories:
261
-
262
- Basic Arithmetic & Mathematical Operations
263
-
264
- Logical & Conditional Operations
265
-
266
- Time Series: Change Detection & Value Comparison
267
-
268
- Time Series: Statistical Feature Engineering
269
-
270
- Time Series: Ranking, Scaling, and Normalization
271
-
272
- Time Series: Decay, Smoothing, and Turnover Control
273
-
274
- Time Series: Extremes & Position Identification
275
-
276
- Cross-Sectional: Ranking, Scaling, and Normalization
277
-
278
- Cross-Sectional: Regression & Neutralization
279
-
280
- Cross-Sectional: Distributional Transformation & Truncation
281
-
282
- Transformational & Filtering Operations
283
-
284
- Group Aggregation & Statistical Summary
285
-
286
- Group Ranking, Scaling, and Normalization
287
-
288
- Group Regression & Neutralization
289
-
290
- Group Imputation & Backfilling
291
-
292
- For each recommended category, present your answer in the following format:
293
-
294
- Repeat the full context for each option.
295
-
296
- Explicitly state the chosen next step category.
297
-
298
- Give a concise reason for the choice.
299
-
300
- Output Format:
301
-
302
- Viable categories for Step X:
303
-
304
- option 1 for Step X: Context: Current step: [number] Current data field: [description] Previous steps and categories used: [list] Current data state: [description in very detail of how the data is transformed to the current state by the previous steps and its logic] Choose next step: [Category Name] Reason: [explanation]
305
-
306
- option 2 for Step X: Context: Current step: [number] Current data field: [description] Previous steps and categories used: [list] Current data state: [description in very detail of how the data is transformed to the current state by the previous steps and its logic] Choose next step: [Category Name] Reason: [explanation]
307
-
308
- ... (continue for all viable options, Only recommend categories that are logical and meaningful given the current data state and previous steps.)
309
-
310
- Additional Instructions:
311
-
312
-
313
- If certain categories are not appropriate at this step, do not list them.
314
-
315
- Be concise and clear in your explanations.
316
-
317
- Do not suggest operators unless specifically requested.
318
-
319
- You will receive the following input at each step:
320
-
321
- Context:
322
-
323
- Current step:
324
-
325
- Current data field:
326
-
327
- Previous steps and categories used:
328
-
329
- Current data state:
330
-
331
- When you receive the input, respond in the format above.
332
- IMPORTANT: Do NOT include any summary, recommendations, rationale, or additional explanations after the options. Only provide the options in the exact format above. Do NOT add sections like "Most recommended choice", "Rationale", "Best Choice", or "Would you like to proceed". Stop immediately after listing all options.
333
-
334
- """
335
-
336
- @feature_engineering_bp.route('/api/get-default-system-prompt', methods=['GET'])
337
- def get_default_system_prompt():
338
- """Get the default system prompt"""
339
- try:
340
- return jsonify({
341
- 'success': True,
342
- 'default_system_prompt': get_default_system_prompt_text()
343
- })
344
-
345
- except Exception as e:
346
- logger.error(f"Error getting default system prompt: {str(e)}")
347
- return jsonify({'success': False, 'error': f'Unexpected error: {str(e)}'}), 500
@@ -1,221 +0,0 @@
1
- """
2
- Idea House Blueprint - Flask Blueprint for analyzing data fields using Coze API
3
- """
4
-
5
- from flask import Blueprint, render_template, request, jsonify, session as flask_session
6
- import os
7
- import sys
8
- from cozepy import Coze, TokenAuth, Message, ChatStatus, MessageContentType
9
- from cozepy import COZE_CN_BASE_URL
10
- import json
11
-
12
- # Create blueprint
13
- idea_house_bp = Blueprint('idea_house', __name__, url_prefix='/idea-house')
14
-
15
- @idea_house_bp.route('/')
16
- def idea_house():
17
- """Idea house page"""
18
- return render_template('idea_house.html')
19
-
20
- @idea_house_bp.route('/api/process-fields', methods=['POST'])
21
- def process_fields():
22
- """Process selected data fields using Coze API"""
23
- try:
24
- # Get the selected fields from request
25
- data = request.get_json()
26
- selected_fields = data.get('selected_fields', {})
27
- coze_api_token = data.get('coze_api_token')
28
- workflow_id = data.get('workflow_id')
29
- dataset_description = data.get('dataset_description', '')
30
-
31
- print("=" * 60)
32
- print("🚀 COZE API REQUEST INITIATED")
33
- print("=" * 60)
34
- print(f"📋 Selected Fields Count: {len(selected_fields)}")
35
- print(f"🔑 API Token (last 10 chars): ...{coze_api_token[-10:] if coze_api_token else 'None'}")
36
- print(f"⚙️ Workflow ID: {workflow_id}")
37
- print("=" * 60)
38
-
39
- if not selected_fields:
40
- print("❌ ERROR: No fields selected")
41
- return jsonify({'error': 'No fields selected'}), 400
42
-
43
- if not coze_api_token:
44
- print("❌ ERROR: Coze API token is required")
45
- return jsonify({'error': 'Coze API token is required'}), 400
46
-
47
- if not workflow_id:
48
- print("❌ ERROR: Workflow ID is required")
49
- return jsonify({'error': 'Workflow ID is required'}), 400
50
-
51
- # Prepare the input string from selected fields
52
- # Format: "field_id (description, unit)"
53
- input_lines = []
54
- for field_id, description in selected_fields.items():
55
- input_lines.append(f"{field_id} ({description})")
56
-
57
- input_string = "\n".join(input_lines)
58
-
59
- # Append dataset description if available
60
- if dataset_description:
61
- input_string = f"Dataset Description: {dataset_description}\n\nSelected Fields:\n{input_string}"
62
-
63
- print("📤 PREPARING COZE API REQUEST:")
64
- print(f" Input String: {input_string[:100]}..." if len(input_string) > 100 else f" Input String: {input_string}")
65
-
66
- # Setup Coze API
67
- coze_api_base = COZE_CN_BASE_URL
68
- print(f"🌐 Using Coze API Base URL: {coze_api_base}")
69
-
70
- # Initialize Coze client
71
- print("🔧 Initializing Coze client...")
72
- coze = Coze(auth=TokenAuth(token=coze_api_token), base_url=coze_api_base)
73
-
74
- # Prepare parameters
75
- parameters = {
76
- "input": input_string
77
- }
78
-
79
- print("📊 Request Parameters:")
80
- print(f" {json.dumps(parameters, indent=2)}")
81
-
82
- # Call the workflow with retries
83
- workflow_result = None
84
- error_message = None
85
-
86
- print("🔄 Starting workflow execution with retries...")
87
- for attempt in range(3):
88
- try:
89
- print(f" Attempt {attempt + 1}/3: Calling Coze workflow...")
90
- workflow = coze.workflows.runs.create(
91
- workflow_id=workflow_id,
92
- parameters=parameters
93
- )
94
- workflow_result = workflow
95
- print(f" ✅ Attempt {attempt + 1} succeeded!")
96
- print(f" 📥 Workflow Response Type: {type(workflow_result)}")
97
- if hasattr(workflow_result, 'data'):
98
- print(f" 📥 Response Data Length: {len(str(workflow_result.data)) if workflow_result.data else 0}")
99
- break
100
- except Exception as e:
101
- error_message = f"Attempt {attempt + 1} failed with error: {str(e)}"
102
- print(f" ❌ {error_message}")
103
- continue
104
-
105
- if workflow_result is None:
106
- print("💥 WORKFLOW EXECUTION FAILED AFTER ALL RETRIES")
107
- print(f" Last Error: {error_message}")
108
- return jsonify({
109
- 'error': 'Failed to run workflow after 3 attempts',
110
- 'details': error_message
111
- }), 500
112
-
113
- print("✅ WORKFLOW EXECUTION SUCCESSFUL")
114
- print("🔍 Processing workflow result...")
115
-
116
- # Process the result
117
- try:
118
- # Try to extract output from workflow data
119
- if hasattr(workflow_result, 'data') and workflow_result.data:
120
- print(" 📊 Workflow data found, processing...")
121
- # Try to evaluate the data if it's a string
122
- try:
123
- result_data = eval(workflow_result.data) if isinstance(workflow_result.data, str) else workflow_result.data
124
- output = result_data.get('output', '')
125
- print(f" 📄 Extracted output length: {len(str(output))}")
126
- except:
127
- # If eval fails, use the data as is
128
- output = str(workflow_result.data)
129
- print(f" 📄 Using raw data as output (length: {len(output)})")
130
- else:
131
- output = "No data returned from the workflow"
132
- print(" ⚠️ No data returned from workflow")
133
-
134
- print("=" * 60)
135
- print("🎉 COZE API REQUEST COMPLETED SUCCESSFULLY")
136
- print(f"📊 Final Output Preview: {str(output)[:150]}..." if len(str(output)) > 150 else f"📊 Final Output: {str(output)}")
137
- print("=" * 60)
138
-
139
- return jsonify({
140
- 'success': True,
141
- 'output': output,
142
- 'parameters': parameters,
143
- 'selected_fields': selected_fields
144
- })
145
-
146
- except Exception as parse_error:
147
- print(f"💥 ERROR PARSING WORKFLOW RESULT: {str(parse_error)}")
148
- print(f" Raw workflow.data: {workflow_result.data if hasattr(workflow_result, 'data') else 'No data attribute'}")
149
-
150
- return jsonify({
151
- 'error': 'Error parsing workflow result',
152
- 'details': str(parse_error),
153
- 'raw_data': str(workflow_result.data) if hasattr(workflow_result, 'data') else None
154
- }), 500
155
-
156
- except Exception as e:
157
- print(f"💥 PROCESS FIELDS ERROR: {str(e)}")
158
- print("=" * 60)
159
- return jsonify({'error': str(e)}), 500
160
-
161
- @idea_house_bp.route('/api/get-datafields-proxy', methods=['GET'])
162
- def get_datafields_proxy():
163
- """Proxy endpoint to get data fields from main app's BRAIN API endpoint"""
164
- try:
165
- from flask import current_app
166
-
167
- # Use the test client to make an internal request
168
- with current_app.test_client() as client:
169
- # Copy headers from the original request
170
- headers = {
171
- 'Session-ID': request.headers.get('Session-ID') or flask_session.get('brain_session_id')
172
- }
173
-
174
- # Copy query parameters
175
- params = request.args.to_dict()
176
-
177
- # Make internal request to the main app's datafields endpoint
178
- response = client.get('/api/datafields', headers=headers, query_string=params)
179
-
180
- # Return the response data and status
181
- return response.get_json(), response.status_code
182
-
183
- except Exception as e:
184
- print(f"Datafields proxy error: {str(e)}")
185
- return jsonify({'error': str(e)}), 500
186
-
187
- @idea_house_bp.route('/api/get-dataset-description', methods=['GET'])
188
- def get_dataset_description():
189
- """Proxy endpoint to get dataset description from main app's BRAIN API endpoint"""
190
- print("\n" + "="*60)
191
- print("🔍 DATASET DESCRIPTION PROXY ENDPOINT CALLED")
192
- print("="*60)
193
-
194
- try:
195
- from flask import current_app
196
-
197
- # Use the test client to make an internal request
198
- with current_app.test_client() as client:
199
- # Copy headers from the original request
200
- headers = {
201
- 'Session-ID': request.headers.get('Session-ID') or flask_session.get('brain_session_id')
202
- }
203
-
204
- # Copy query parameters
205
- params = request.args.to_dict()
206
-
207
- print(f"📊 Proxying request with params: {params}")
208
- print(f"📌 Session ID: {headers.get('Session-ID')}")
209
-
210
- # Make internal request to the main app's dataset description endpoint
211
- response = client.get('/api/dataset-description', headers=headers, query_string=params)
212
-
213
- print(f"📥 Proxy response status: {response.status_code}")
214
-
215
- # Return the response data and status
216
- return response.get_json(), response.status_code
217
-
218
- except Exception as e:
219
- print(f"💥 Dataset description proxy error: {str(e)}")
220
- print("="*60 + "\n")
221
- return jsonify({'error': str(e)}), 500