cnhkmcp 2.1.9__py3-none-any.whl → 2.3.0__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 (142) hide show
  1. cnhkmcp/__init__.py +1 -1
  2. cnhkmcp/untracked/AI/321/206/320/231/320/243/321/205/342/225/226/320/265/321/204/342/225/221/342/225/221/BRAIN_AI/321/206/320/231/320/243/321/205/342/225/226/320/265/321/204/342/225/221/342/225/221Mac_Linux/321/207/320/231/320/230/321/206/320/254/320/274.zip +0 -0
  3. cnhkmcp/untracked/AI/321/206/320/231/320/243/321/205/342/225/226/320/265/321/204/342/225/221/342/225/221//321/205/320/237/320/234/321/205/320/227/342/225/227/321/205/320/276/320/231/321/210/320/263/320/225AI/321/206/320/231/320/243/321/205/342/225/226/320/265/321/204/342/225/221/342/225/221_Windows/321/207/320/231/320/230/321/206/320/254/320/274.exe +0 -0
  4. 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 +1 -1
  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/config.json +2 -2
  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/main.py +1 -1
  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/vector_db/chroma.sqlite3 +0 -0
  8. cnhkmcp/untracked/APP/Tranformer/Transformer.py +2 -2
  9. cnhkmcp/untracked/APP/Tranformer/transformer_config.json +1 -1
  10. cnhkmcp/untracked/APP/blueprints/feature_engineering.py +2 -2
  11. cnhkmcp/untracked/APP/blueprints/inspiration_house.py +4 -4
  12. cnhkmcp/untracked/APP/blueprints/paper_analysis.py +3 -3
  13. cnhkmcp/untracked/APP/give_me_idea/BRAIN_Alpha_Template_Expert_SystemPrompt.md +34 -73
  14. cnhkmcp/untracked/APP/give_me_idea/alpha_data_specific_template_master.py +2 -2
  15. cnhkmcp/untracked/APP/give_me_idea/what_is_Alpha_template.md +366 -1
  16. cnhkmcp/untracked/APP/static/inspiration.js +345 -13
  17. cnhkmcp/untracked/APP/templates/index.html +11 -3
  18. cnhkmcp/untracked/APP/templates/transformer_web.html +1 -1
  19. cnhkmcp/untracked/APP/trailSomeAlphas/README.md +38 -0
  20. cnhkmcp/untracked/APP/trailSomeAlphas/ace.log +66 -0
  21. cnhkmcp/untracked/APP/trailSomeAlphas/enhance_template.py +588 -0
  22. cnhkmcp/untracked/APP/trailSomeAlphas/requirements.txt +3 -0
  23. cnhkmcp/untracked/APP/trailSomeAlphas/run_pipeline.py +1001 -0
  24. cnhkmcp/untracked/APP/trailSomeAlphas/run_pipeline_step_by_step.ipynb +5258 -0
  25. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-data-feature-engineering/OUTPUT_TEMPLATE.md +325 -0
  26. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-data-feature-engineering/SKILL.md +503 -0
  27. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-data-feature-engineering/examples.md +244 -0
  28. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-data-feature-engineering/output_report/ASI_delay1_analyst11_ideas.md +285 -0
  29. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-data-feature-engineering/reference.md +399 -0
  30. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/SKILL.md +40 -0
  31. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/config.json +6 -0
  32. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769709385783386000.json +388 -0
  33. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769709386274840400.json +131 -0
  34. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769709386838244700.json +1926 -0
  35. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769709387369198500.json +31 -0
  36. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769709387908905800.json +1926 -0
  37. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769709388486243600.json +240 -0
  38. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769709389024058600.json +1926 -0
  39. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769709389549608700.json +41 -0
  40. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769709390068714000.json +110 -0
  41. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769709390591996900.json +36 -0
  42. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769709391129137100.json +31 -0
  43. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769709391691643500.json +41 -0
  44. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769709392192099200.json +31 -0
  45. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769709392703423500.json +46 -0
  46. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769709393213729400.json +246 -0
  47. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769710186683932500.json +388 -0
  48. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769710187165414300.json +131 -0
  49. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769710187665211700.json +1926 -0
  50. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769710188149193400.json +31 -0
  51. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769710188667627400.json +1926 -0
  52. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769710189220822000.json +240 -0
  53. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769710189726189500.json +1926 -0
  54. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769710190248066100.json +41 -0
  55. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769710190768298700.json +110 -0
  56. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769710191282588100.json +36 -0
  57. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769710191838960900.json +31 -0
  58. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769710192396688000.json +41 -0
  59. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769710192941922400.json +31 -0
  60. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769710193473524600.json +46 -0
  61. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769710194001961200.json +246 -0
  62. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769710420975888800.json +46 -0
  63. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769710421647590100.json +196 -0
  64. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769710422131378500.json +5 -0
  65. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769710422644184400.json +196 -0
  66. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769710423702350600.json +196 -0
  67. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_1_idea_1769710424244661800.json +5 -0
  68. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/analyst11_ASI_delay1.csv +211 -0
  69. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/data/analyst11_ASI_delay1/final_expressions.json +7062 -0
  70. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/scripts/ace.log +3 -0
  71. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/scripts/ace_lib.py +1514 -0
  72. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/scripts/fetch_dataset.py +113 -0
  73. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/scripts/helpful_functions.py +180 -0
  74. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/scripts/implement_idea.py +236 -0
  75. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/scripts/merge_expression_list.py +90 -0
  76. cnhkmcp/untracked/APP/trailSomeAlphas/skills/brain-feature-implementation/scripts/parsetab.py +60 -0
  77. cnhkmcp/untracked/APP/trailSomeAlphas/skills/template_final_enhance/op/321/206/320/220/342/225/227/321/207/342/225/227/320/243.md +434 -0
  78. cnhkmcp/untracked/APP/trailSomeAlphas/skills/template_final_enhance/sample_prompt.md +62 -0
  79. cnhkmcp/untracked/APP/trailSomeAlphas/skills/template_final_enhance//321/205/320/235/320/245/321/205/320/253/320/260/321/205/320/275/320/240/321/206/320/220/320/255/321/210/320/220/320/223/321/211/320/220/342/225/227/321/210/342/225/233/320/241/321/211/320/243/342/225/233.md +354 -0
  80. cnhkmcp/untracked/APP/usage.md +2 -2
  81. 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 +388 -8
  82. cnhkmcp/untracked/skills/alpha-expression-verifier/scripts/validator.py +889 -0
  83. cnhkmcp/untracked/skills/brain-data-feature-engineering/OUTPUT_TEMPLATE.md +325 -0
  84. cnhkmcp/untracked/skills/brain-data-feature-engineering/SKILL.md +263 -0
  85. cnhkmcp/untracked/skills/brain-data-feature-engineering/examples.md +244 -0
  86. cnhkmcp/untracked/skills/brain-data-feature-engineering/reference.md +493 -0
  87. cnhkmcp/untracked/skills/brain-feature-implementation/SKILL.md +87 -0
  88. cnhkmcp/untracked/skills/brain-feature-implementation/config.json +6 -0
  89. cnhkmcp/untracked/skills/brain-feature-implementation/data/analyst15_GLB_delay1/analyst15_GLB_delay1.csv +289 -0
  90. cnhkmcp/untracked/skills/brain-feature-implementation/data/analyst15_GLB_delay1/final_expressions.json +410 -0
  91. cnhkmcp/untracked/skills/brain-feature-implementation/data/analyst15_GLB_delay1/idea_1768588244.json +4 -0
  92. cnhkmcp/untracked/skills/brain-feature-implementation/data/analyst15_GLB_delay1/idea_1768588251.json +20 -0
  93. cnhkmcp/untracked/skills/brain-feature-implementation/data/analyst15_GLB_delay1/idea_1768588273.json +23 -0
  94. cnhkmcp/untracked/skills/brain-feature-implementation/data/analyst15_GLB_delay1/idea_1768588293.json +23 -0
  95. cnhkmcp/untracked/skills/brain-feature-implementation/data/analyst15_GLB_delay1/idea_1768588319.json +23 -0
  96. cnhkmcp/untracked/skills/brain-feature-implementation/data/analyst15_GLB_delay1/idea_1768588322.json +14 -0
  97. cnhkmcp/untracked/skills/brain-feature-implementation/data/analyst15_GLB_delay1/idea_1768588325.json +20 -0
  98. cnhkmcp/untracked/skills/brain-feature-implementation/data/analyst15_GLB_delay1/idea_1768588328.json +23 -0
  99. cnhkmcp/untracked/skills/brain-feature-implementation/data/analyst15_GLB_delay1/idea_1768588354.json +23 -0
  100. cnhkmcp/untracked/skills/brain-feature-implementation/data/analyst15_GLB_delay1/idea_1768588357.json +23 -0
  101. cnhkmcp/untracked/skills/brain-feature-implementation/data/analyst15_GLB_delay1/idea_1768588361.json +23 -0
  102. cnhkmcp/untracked/skills/brain-feature-implementation/data/analyst15_GLB_delay1/idea_1768588364.json +23 -0
  103. cnhkmcp/untracked/skills/brain-feature-implementation/data/analyst15_GLB_delay1/idea_1768588368.json +23 -0
  104. cnhkmcp/untracked/skills/brain-feature-implementation/data/analyst15_GLB_delay1/idea_1768588391.json +14 -0
  105. cnhkmcp/untracked/skills/brain-feature-implementation/data/analyst15_GLB_delay1/idea_1768588394.json +23 -0
  106. cnhkmcp/untracked/skills/brain-feature-implementation/data/analyst15_GLB_delay1/idea_1768588397.json +59 -0
  107. cnhkmcp/untracked/skills/brain-feature-implementation/data/analyst15_GLB_delay1/idea_1768588400.json +35 -0
  108. cnhkmcp/untracked/skills/brain-feature-implementation/data/analyst15_GLB_delay1/idea_1768588403.json +20 -0
  109. cnhkmcp/untracked/skills/brain-feature-implementation/data/analyst15_GLB_delay1/idea_1768588428.json +23 -0
  110. cnhkmcp/untracked/skills/brain-feature-implementation/data/analyst15_GLB_delay1/idea_1768588431.json +32 -0
  111. cnhkmcp/untracked/skills/brain-feature-implementation/data/analyst15_GLB_delay1/idea_1768588434.json +20 -0
  112. cnhkmcp/untracked/skills/brain-feature-implementation/data/analyst15_GLB_delay1/idea_1768588438.json +20 -0
  113. cnhkmcp/untracked/skills/brain-feature-implementation/data/analyst15_GLB_delay1/idea_1768588441.json +14 -0
  114. cnhkmcp/untracked/skills/brain-feature-implementation/data/analyst15_GLB_delay1/idea_1768588468.json +20 -0
  115. cnhkmcp/untracked/skills/brain-feature-implementation/scripts/ace_lib.py +1514 -0
  116. cnhkmcp/untracked/skills/brain-feature-implementation/scripts/fetch_dataset.py +107 -0
  117. cnhkmcp/untracked/skills/brain-feature-implementation/scripts/helpful_functions.py +180 -0
  118. cnhkmcp/untracked/skills/brain-feature-implementation/scripts/implement_idea.py +165 -0
  119. cnhkmcp/untracked/skills/brain-feature-implementation/scripts/merge_expression_list.py +88 -0
  120. cnhkmcp/untracked/skills/brain-improve-alpha-performance/arXiv_API_Tool_Manual.md +490 -0
  121. cnhkmcp/untracked/skills/brain-improve-alpha-performance/reference.md +1 -1
  122. cnhkmcp/untracked/skills/brain-improve-alpha-performance/scripts/arxiv_api.py +229 -0
  123. cnhkmcp/untracked/skills/planning-with-files/SKILL.md +211 -0
  124. cnhkmcp/untracked/skills/planning-with-files/examples.md +202 -0
  125. cnhkmcp/untracked/skills/planning-with-files/reference.md +218 -0
  126. cnhkmcp/untracked/skills/planning-with-files/scripts/check-complete.sh +44 -0
  127. cnhkmcp/untracked/skills/planning-with-files/scripts/init-session.sh +120 -0
  128. cnhkmcp/untracked/skills/planning-with-files/templates/findings.md +95 -0
  129. cnhkmcp/untracked/skills/planning-with-files/templates/progress.md +114 -0
  130. cnhkmcp/untracked/skills/planning-with-files/templates/task_plan.md +132 -0
  131. 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 +35 -11
  132. cnhkmcp/vector_db/_manifest.json +1 -0
  133. cnhkmcp/vector_db/_meta.json +1 -0
  134. {cnhkmcp-2.1.9.dist-info → cnhkmcp-2.3.0.dist-info}/METADATA +1 -1
  135. {cnhkmcp-2.1.9.dist-info → cnhkmcp-2.3.0.dist-info}/RECORD +142 -31
  136. /cnhkmcp/untracked/{skills/expression_verifier → APP/trailSomeAlphas/skills/brain-feature-implementation}/scripts/validator.py +0 -0
  137. /cnhkmcp/untracked/skills/{expression_verifier → alpha-expression-verifier}/SKILL.md +0 -0
  138. /cnhkmcp/untracked/skills/{expression_verifier → alpha-expression-verifier}/scripts/verify_expr.py +0 -0
  139. {cnhkmcp-2.1.9.dist-info → cnhkmcp-2.3.0.dist-info}/WHEEL +0 -0
  140. {cnhkmcp-2.1.9.dist-info → cnhkmcp-2.3.0.dist-info}/entry_points.txt +0 -0
  141. {cnhkmcp-2.1.9.dist-info → cnhkmcp-2.3.0.dist-info}/licenses/LICENSE +0 -0
  142. {cnhkmcp-2.1.9.dist-info → cnhkmcp-2.3.0.dist-info}/top_level.txt +0 -0
@@ -115,12 +115,15 @@ if not check_and_install_dependencies():
115
115
 
116
116
  # Now import the packages
117
117
  try:
118
- from flask import Flask, render_template, request, jsonify, session as flask_session, Response, stream_with_context, send_from_directory
118
+ from flask import Flask, render_template, request, jsonify, session as flask_session, Response, stream_with_context, send_from_directory, send_file, after_this_request
119
+ from werkzeug.utils import secure_filename
119
120
  from flask_cors import CORS
120
121
  import requests
121
122
  import json
122
123
  import time
123
124
  import os
125
+ import zipfile
126
+ import tempfile
124
127
  import threading
125
128
  import queue
126
129
  import uuid
@@ -660,6 +663,7 @@ def authenticate():
660
663
  brain_sessions[session_id] = {
661
664
  'session': brain_session,
662
665
  'username': username,
666
+ 'password': password,
663
667
  'timestamp': time.time(),
664
668
  'options': valid_options
665
669
  }
@@ -748,6 +752,7 @@ def complete_biometric():
748
752
  brain_sessions[new_session_id] = {
749
753
  'session': brain_session,
750
754
  'username': session_info['username'],
755
+ 'password': session_info.get('password'),
751
756
  'timestamp': time.time()
752
757
  }
753
758
 
@@ -1754,6 +1759,12 @@ def get_usage_doc():
1754
1759
  # Global task manager for Transformer Web
1755
1760
  transformer_tasks = {}
1756
1761
 
1762
+ # Global task manager for Inspiration direct pipeline
1763
+ inspiration_pipeline_tasks = {}
1764
+
1765
+ # Global task manager for template enhancement
1766
+ inspiration_enhance_tasks = {}
1767
+
1757
1768
  @app.route('/transformer-web')
1758
1769
  def transformer_web():
1759
1770
  return render_template('transformer_web.html')
@@ -2385,6 +2396,16 @@ def inspiration_generate():
2385
2396
 
2386
2397
  datafields_df = get_datafields(s, region=region, delay=int(delay), universe=universe, dataset_id=dataset_id, data_type="ALL")
2387
2398
 
2399
+ # count the datatype of the datafields_df, if most of them are VECTOR, then we keep the VECTOR category operators in the operators_df, otherwise we remove them
2400
+ datatype_counts = datafields_df['type'].value_counts().to_dict()
2401
+ vector_count = datatype_counts.get('VECTOR', 0)
2402
+ total_fields = sum(datatype_counts.values())
2403
+ if total_fields > 0 and vector_count > (total_fields / 2):
2404
+ # keep VECTOR operators
2405
+ pass
2406
+ print("Keeping VECTOR operators because majority of datafields are VECTOR type")
2407
+ operators_df = operators_df[operators_df['category'] != 'Vector']
2408
+
2388
2409
  script_dir = os.path.dirname(os.path.abspath(__file__))
2389
2410
  prompt_path = os.path.join(script_dir, "give_me_idea", "what_is_Alpha_template.md")
2390
2411
  try:
@@ -2392,7 +2413,7 @@ def inspiration_generate():
2392
2413
  system_prompt = f.read()
2393
2414
  except:
2394
2415
  system_prompt = "You are a helpful assistant for generating Alpha templates."
2395
-
2416
+
2396
2417
  client = openai.OpenAI(api_key=api_key, base_url=base_url)
2397
2418
 
2398
2419
  max_retries = 5
@@ -2405,9 +2426,35 @@ def inspiration_generate():
2405
2426
  ops_subset = operators_df.head(n_ops)
2406
2427
  fields_subset = datafields_df.head(n_fields)
2407
2428
 
2408
- operators_info = ops_subset[['name', 'category', 'description']].to_string()
2409
- datafields_info = fields_subset[['id', 'description', 'subcategory']].to_string()
2410
-
2429
+ # Render subsets as Markdown tables (with robust fallbacks)
2430
+ try:
2431
+ operators_info = ops_subset[['name', 'category', 'description']].to_markdown(index=False)
2432
+ except Exception:
2433
+ try:
2434
+ from tabulate import tabulate
2435
+ operators_info = tabulate(
2436
+ ops_subset[['name', 'category', 'description']].fillna(''),
2437
+ headers='keys',
2438
+ tablefmt='github',
2439
+ showindex=False
2440
+ )
2441
+ except Exception:
2442
+ operators_info = ops_subset[['name', 'category', 'description']].to_string(index=False)
2443
+
2444
+ try:
2445
+ datafields_info = fields_subset[['id', 'description', 'subcategory']].to_markdown(index=False)
2446
+ except Exception:
2447
+ try:
2448
+ from tabulate import tabulate
2449
+ datafields_info = tabulate(
2450
+ fields_subset[['id', 'description', 'subcategory']].fillna(''),
2451
+ headers='keys',
2452
+ tablefmt='github',
2453
+ showindex=False
2454
+ )
2455
+ except Exception:
2456
+ datafields_info = fields_subset[['id', 'description', 'subcategory']].to_string(index=False)
2457
+
2411
2458
  user_prompt = f"""
2412
2459
  Here is the information about available operators (first {n_ops} rows):
2413
2460
  {operators_info}
@@ -2415,8 +2462,8 @@ Here is the information about available operators (first {n_ops} rows):
2415
2462
  Here is the information about the dataset '{dataset_id}' (first {n_fields} rows):
2416
2463
  {datafields_info}
2417
2464
 
2418
- Please come up with several Alpha templates based on this information.
2419
- Specify the AI answer in Chinese.
2465
+ Please come up with as much diverse Alpha templates as you can based on above information. And do remember to make some innovation of the templates.
2466
+ Answer in Chinese.
2420
2467
  """
2421
2468
  try:
2422
2469
  completion = client.chat.completions.create(
@@ -2425,7 +2472,7 @@ Specify the AI answer in Chinese.
2425
2472
  {"role": "system", "content": system_prompt},
2426
2473
  {"role": "user", "content": user_prompt}
2427
2474
  ],
2428
- temperature=0.3,
2475
+ temperature=1,
2429
2476
  )
2430
2477
  return jsonify({'result': completion.choices[0].message.content})
2431
2478
 
@@ -2445,6 +2492,339 @@ Specify the AI answer in Chinese.
2445
2492
  except Exception as e:
2446
2493
  return jsonify({'error': str(e)}), 500
2447
2494
 
2495
+
2496
+ def _safe_dataset_id(dataset_id: str) -> str:
2497
+ return "".join([c for c in str(dataset_id) if c.isalnum() or c in ("-", "_")])
2498
+
2499
+
2500
+ def _get_pipeline_paths(dataset_id: str, region: str, delay: int):
2501
+ script_dir = os.path.dirname(os.path.abspath(__file__))
2502
+ trail_dir = os.path.join(script_dir, 'trailSomeAlphas')
2503
+ run_pipeline_path = os.path.join(trail_dir, 'run_pipeline.py')
2504
+ data_dir = os.path.join(trail_dir, 'skills', 'brain-feature-implementation', 'data')
2505
+ dataset_folder = f"{_safe_dataset_id(dataset_id)}_{region}_delay{delay}"
2506
+ output_folder = os.path.join(data_dir, dataset_folder)
2507
+ return run_pipeline_path, trail_dir, output_folder, dataset_folder
2508
+
2509
+
2510
+ @app.route('/api/inspiration/run-pipeline', methods=['POST'])
2511
+ def inspiration_run_pipeline():
2512
+ try:
2513
+ data = request.get_json() or {}
2514
+ dataset_id = data.get('datasetId')
2515
+ data_category = data.get('dataCategory')
2516
+ region = data.get('region')
2517
+ delay = data.get('delay')
2518
+ universe = data.get('universe')
2519
+ api_key = data.get('apiKey')
2520
+ base_url = data.get('baseUrl')
2521
+ model = data.get('model')
2522
+
2523
+ if not dataset_id or not data_category or not region or delay is None or not universe:
2524
+ return jsonify({'success': False, 'error': 'Missing required parameters'}), 400
2525
+
2526
+ run_pipeline_path, trail_dir, output_folder, dataset_folder = _get_pipeline_paths(dataset_id, region, int(delay))
2527
+ if not os.path.exists(run_pipeline_path):
2528
+ return jsonify({'success': False, 'error': f'run_pipeline.py not found: {run_pipeline_path}'}), 404
2529
+
2530
+ task_id = str(uuid.uuid4())
2531
+ log_queue = queue.Queue()
2532
+ inspiration_pipeline_tasks[task_id] = {
2533
+ 'queue': log_queue,
2534
+ 'status': 'running',
2535
+ 'output_folder': output_folder,
2536
+ 'dataset_folder': dataset_folder
2537
+ }
2538
+
2539
+ session_id = request.headers.get('Session-ID') or flask_session.get('brain_session_id')
2540
+ session_info = brain_sessions.get(session_id) if session_id else None
2541
+
2542
+ def run_process():
2543
+ try:
2544
+ cmd = [
2545
+ sys.executable,
2546
+ run_pipeline_path,
2547
+ '--data-category', str(data_category),
2548
+ '--region', str(region),
2549
+ '--delay', str(delay),
2550
+ '--dataset-id', str(dataset_id),
2551
+ '--universe', str(universe)
2552
+ ]
2553
+
2554
+ if api_key:
2555
+ cmd.extend(['--moonshot-api-key', str(api_key)])
2556
+ if model:
2557
+ cmd.extend(['--moonshot-model', str(model)])
2558
+
2559
+ env = os.environ.copy()
2560
+ if api_key:
2561
+ env['MOONSHOT_API_KEY'] = str(api_key)
2562
+ if base_url:
2563
+ env['MOONSHOT_BASE_URL'] = str(base_url)
2564
+ if model:
2565
+ env['MOONSHOT_MODEL'] = str(model)
2566
+ if session_info and session_info.get('username') and session_info.get('password'):
2567
+ env['BRAIN_USERNAME'] = session_info['username']
2568
+ env['BRAIN_PASSWORD'] = session_info['password']
2569
+
2570
+ proc = subprocess.Popen(
2571
+ cmd,
2572
+ cwd=trail_dir,
2573
+ stdout=subprocess.PIPE,
2574
+ stderr=subprocess.STDOUT,
2575
+ text=True,
2576
+ encoding='utf-8',
2577
+ errors='replace',
2578
+ bufsize=1,
2579
+ env=env
2580
+ )
2581
+
2582
+ if proc.stdout:
2583
+ for line in proc.stdout:
2584
+ log_queue.put(line.rstrip('\n'))
2585
+
2586
+ exit_code = proc.wait()
2587
+ success = exit_code == 0
2588
+ inspiration_pipeline_tasks[task_id]['status'] = 'completed' if success else 'failed'
2589
+ log_queue.put({
2590
+ '__event__': 'done',
2591
+ 'success': success,
2592
+ 'exit_code': exit_code,
2593
+ 'dataset_folder': dataset_folder
2594
+ })
2595
+ except Exception as e:
2596
+ inspiration_pipeline_tasks[task_id]['status'] = 'failed'
2597
+ log_queue.put({
2598
+ '__event__': 'done',
2599
+ 'success': False,
2600
+ 'error': str(e),
2601
+ 'dataset_folder': dataset_folder
2602
+ })
2603
+
2604
+ thread = threading.Thread(target=run_process)
2605
+ thread.daemon = True
2606
+ thread.start()
2607
+
2608
+ return jsonify({'success': True, 'taskId': task_id})
2609
+
2610
+ except Exception as e:
2611
+ return jsonify({'success': False, 'error': str(e)}), 500
2612
+
2613
+
2614
+ @app.route('/api/inspiration/stream-pipeline/<task_id>')
2615
+ def inspiration_stream_pipeline(task_id):
2616
+ task = inspiration_pipeline_tasks.get(task_id)
2617
+ if not task:
2618
+ return jsonify({'success': False, 'error': 'Task not found'}), 404
2619
+
2620
+ def generate():
2621
+ q = task['queue']
2622
+ while True:
2623
+ item = q.get()
2624
+ if isinstance(item, dict) and item.get('__event__') == 'done':
2625
+ yield f"event: done\ndata: {json.dumps(item, ensure_ascii=False)}\n\n"
2626
+ break
2627
+
2628
+ payload = {'line': item}
2629
+ yield f"data: {json.dumps(payload, ensure_ascii=False)}\n\n"
2630
+
2631
+ return Response(stream_with_context(generate()), mimetype='text/event-stream')
2632
+
2633
+
2634
+ @app.route('/api/inspiration/download-pipeline/<task_id>')
2635
+ def inspiration_download_pipeline(task_id):
2636
+ task = inspiration_pipeline_tasks.get(task_id)
2637
+ if not task:
2638
+ return jsonify({'success': False, 'error': 'Task not found'}), 404
2639
+
2640
+ output_folder = task.get('output_folder')
2641
+ if not output_folder or not os.path.isdir(output_folder):
2642
+ return jsonify({'success': False, 'error': 'Output folder not found'}), 404
2643
+
2644
+ temp = tempfile.NamedTemporaryFile(delete=False, suffix='.zip')
2645
+ temp.close()
2646
+
2647
+ with zipfile.ZipFile(temp.name, 'w', zipfile.ZIP_DEFLATED) as zf:
2648
+ base_name = os.path.basename(output_folder.rstrip(os.sep))
2649
+ for root, _, files in os.walk(output_folder):
2650
+ for filename in files:
2651
+ abs_path = os.path.join(root, filename)
2652
+ rel_path = os.path.relpath(abs_path, output_folder)
2653
+ arcname = os.path.join(base_name, rel_path)
2654
+ zf.write(abs_path, arcname=arcname)
2655
+
2656
+ @after_this_request
2657
+ def _cleanup_zip(response):
2658
+ try:
2659
+ os.remove(temp.name)
2660
+ except Exception:
2661
+ pass
2662
+ return response
2663
+
2664
+ download_name = f"{os.path.basename(output_folder)}.zip"
2665
+ return send_file(temp.name, as_attachment=True, download_name=download_name)
2666
+
2667
+
2668
+ @app.route('/api/inspiration/enhance-template', methods=['POST'])
2669
+ def inspiration_enhance_template():
2670
+ try:
2671
+ idea_files = request.files.getlist('ideaFiles')
2672
+ api_key = request.form.get('apiKey')
2673
+ base_url = request.form.get('baseUrl')
2674
+ model = request.form.get('model')
2675
+
2676
+ if not idea_files or not api_key:
2677
+ return jsonify({'success': False, 'error': 'Missing ideaFiles or apiKey'}), 400
2678
+
2679
+ script_dir = os.path.dirname(os.path.abspath(__file__))
2680
+ trail_dir = os.path.join(script_dir, 'trailSomeAlphas')
2681
+ enhance_script = os.path.join(trail_dir, 'enhance_template.py')
2682
+ if not os.path.exists(enhance_script):
2683
+ return jsonify({'success': False, 'error': f'enhance_template.py not found: {enhance_script}'}), 404
2684
+
2685
+ task_id = str(uuid.uuid4())
2686
+ log_queue = queue.Queue()
2687
+ task_root = tempfile.mkdtemp(prefix='enhance_batch_')
2688
+
2689
+ saved_files = []
2690
+ for idx, idea_file in enumerate(idea_files, start=1):
2691
+ name = secure_filename(idea_file.filename or f'idea_{idx}.json')
2692
+ file_dir = os.path.join(task_root, f"{idx:02d}_{os.path.splitext(name)[0]}")
2693
+ os.makedirs(file_dir, exist_ok=True)
2694
+ idea_path = os.path.join(file_dir, name)
2695
+ idea_file.save(idea_path)
2696
+ saved_files.append((name, idea_path))
2697
+
2698
+ inspiration_enhance_tasks[task_id] = {
2699
+ 'queue': log_queue,
2700
+ 'status': 'running',
2701
+ 'task_root': task_root,
2702
+ 'saved_files': saved_files
2703
+ }
2704
+
2705
+ def run_process():
2706
+ try:
2707
+ total = len(saved_files)
2708
+ completed_ok = True
2709
+
2710
+ for idx, (name, idea_path) in enumerate(saved_files, start=1):
2711
+ env = os.environ.copy()
2712
+ env['IDEA_JSON'] = idea_path
2713
+ env['MOONSHOT_API_KEY'] = api_key
2714
+ if base_url:
2715
+ env['MOONSHOT_BASE_URL'] = base_url
2716
+ if model:
2717
+ env['MOONSHOT_MODEL'] = model
2718
+ env['PYTHONIOENCODING'] = 'utf-8'
2719
+
2720
+ log_queue.put(f"=== 开始处理: {name} ({idx}/{total}) ===")
2721
+ proc = subprocess.Popen(
2722
+ [sys.executable, enhance_script],
2723
+ cwd=trail_dir,
2724
+ stdout=subprocess.PIPE,
2725
+ stderr=subprocess.STDOUT,
2726
+ text=True,
2727
+ encoding='utf-8',
2728
+ errors='replace',
2729
+ bufsize=1,
2730
+ env=env
2731
+ )
2732
+
2733
+ if proc.stdout:
2734
+ for line in proc.stdout:
2735
+ log_queue.put({'line': line.rstrip('\n'), 'file': name})
2736
+
2737
+ exit_code = proc.wait()
2738
+ success = exit_code == 0
2739
+ if not success:
2740
+ completed_ok = False
2741
+ log_queue.put({'__event__': 'file_done', 'type': 'file_done', 'file': name, 'success': success})
2742
+
2743
+ inspiration_enhance_tasks[task_id]['status'] = 'completed' if completed_ok else 'failed'
2744
+ log_queue.put({
2745
+ '__event__': 'done',
2746
+ 'success': completed_ok,
2747
+ 'total': total
2748
+ })
2749
+ except Exception as e:
2750
+ inspiration_enhance_tasks[task_id]['status'] = 'failed'
2751
+ log_queue.put({
2752
+ '__event__': 'done',
2753
+ 'success': False,
2754
+ 'error': str(e)
2755
+ })
2756
+
2757
+ thread = threading.Thread(target=run_process)
2758
+ thread.daemon = True
2759
+ thread.start()
2760
+
2761
+ return jsonify({'success': True, 'taskId': task_id})
2762
+
2763
+ except Exception as e:
2764
+ return jsonify({'success': False, 'error': str(e)}), 500
2765
+
2766
+
2767
+ @app.route('/api/inspiration/stream-enhance/<task_id>')
2768
+ def inspiration_stream_enhance(task_id):
2769
+ task = inspiration_enhance_tasks.get(task_id)
2770
+ if not task:
2771
+ return jsonify({'success': False, 'error': 'Task not found'}), 404
2772
+
2773
+ def generate():
2774
+ q = task['queue']
2775
+ while True:
2776
+ item = q.get()
2777
+ if isinstance(item, dict) and item.get('__event__') == 'done':
2778
+ yield f"event: done\ndata: {json.dumps(item, ensure_ascii=False)}\n\n"
2779
+ break
2780
+
2781
+ if isinstance(item, dict) and item.get('__event__') == 'file_done':
2782
+ payload = {'type': 'file_done', 'file': item.get('file'), 'success': item.get('success')}
2783
+ yield f"data: {json.dumps(payload, ensure_ascii=False)}\n\n"
2784
+ continue
2785
+
2786
+ if isinstance(item, dict):
2787
+ payload = item
2788
+ else:
2789
+ payload = {'line': item}
2790
+ yield f"data: {json.dumps(payload, ensure_ascii=False)}\n\n"
2791
+
2792
+ return Response(stream_with_context(generate()), mimetype='text/event-stream')
2793
+
2794
+
2795
+ @app.route('/api/inspiration/download-enhance/<task_id>')
2796
+ def inspiration_download_enhance(task_id):
2797
+ task = inspiration_enhance_tasks.get(task_id)
2798
+ if not task:
2799
+ return jsonify({'success': False, 'error': 'Task not found'}), 404
2800
+
2801
+ task_root = task.get('task_root')
2802
+ if not task_root or not os.path.isdir(task_root):
2803
+ return jsonify({'success': False, 'error': 'Task output not found'}), 404
2804
+
2805
+ temp = tempfile.NamedTemporaryFile(delete=False, suffix='.zip')
2806
+ temp.close()
2807
+
2808
+ with zipfile.ZipFile(temp.name, 'w', zipfile.ZIP_DEFLATED) as zf:
2809
+ base_name = os.path.basename(task_root.rstrip(os.sep))
2810
+ for root, _, files in os.walk(task_root):
2811
+ for filename in files:
2812
+ abs_path = os.path.join(root, filename)
2813
+ rel_path = os.path.relpath(abs_path, task_root)
2814
+ arcname = os.path.join(base_name, rel_path)
2815
+ zf.write(abs_path, arcname=arcname)
2816
+
2817
+ @after_this_request
2818
+ def _cleanup_zip(response):
2819
+ try:
2820
+ os.remove(temp.name)
2821
+ except Exception:
2822
+ pass
2823
+ return response
2824
+
2825
+ download_name = f"{os.path.basename(task_root)}.zip"
2826
+ return send_file(temp.name, as_attachment=True, download_name=download_name)
2827
+
2448
2828
  if __name__ == '__main__':
2449
2829
  print("Starting BRAIN Expression Template Decoder Web Application...")
2450
2830
  print("Starting in safe mode: binding only to localhost (127.0.0.1)")