mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-08-02 18:07:43 +00:00
d1019cb568
* fix model input shape bug and costeer_model bug * fix a bug * fix a bug in docker result extraction * a system-level optimization * add a filter of stdout * update * add stdout to model * model training_hyperparameters update * quant scenario * update some quant settings * llm choose action * Thompson Sampling Bandit for action choosing * refine both scens * add trace messages for quant scen * fix some bugs * fix some bugs * update * update * update * fix * fix * fix * update for merge * fix ci * fix some bugs * fix ci * fix ci * fix ci * fix ci * refactor * default qlib4rdagent local env downloading * fix ci * fix ci * fix a bug * fix ci * fix: align all prompts on template (#908) * use template to render all prompts * fix CI --------- Co-authored-by: Xu Yang <xuyang1@microsoft.com> * add fin_quant in cli * fix a bug * fix ci * fix some bugs * refactor * remove the columns in hypothesis if no value generated in this column * fix a bug * fix ci * fix conda env * add qlib gitignore * remove existed qlib folder & install torch in qlib conda * fix workspace ui in feedback * align model config in coder and runner in docker or conda * fix CI * fix CI --------- Co-authored-by: Xu Yang <peteryang@vip.qq.com> Co-authored-by: Xu Yang <xuyang1@microsoft.com>
65 lines
2.1 KiB
Python
65 lines
2.1 KiB
Python
import json
|
|
from pathlib import Path
|
|
|
|
from rdagent.oai.llm_utils import APIBackend
|
|
from rdagent.utils.agent.tpl import T
|
|
|
|
|
|
def extract_knowledge_from_high_score_answers(content: str):
|
|
sys_prompt = T(".prompts:extract_kaggle_knowledge_prompts.system").r()
|
|
user_prompt = T(".prompts:extract_kaggle_knowledge_prompts.user").r(file_content=content)
|
|
|
|
response_analysis = APIBackend().build_messages_and_create_chat_completion(
|
|
user_prompt=user_prompt,
|
|
system_prompt=sys_prompt,
|
|
json_mode=True,
|
|
)
|
|
|
|
try:
|
|
response_json_analysis = json.loads(response_analysis)
|
|
except json.JSONDecodeError:
|
|
response_json_analysis = {"error": "Failed to parse LLM's response as JSON"}
|
|
|
|
return response_json_analysis
|
|
|
|
|
|
def extract_knowledge_from_feedback(feedback_response: dict) -> dict:
|
|
"""
|
|
Extracts knowledge from LLM-generated feedback and structures it.
|
|
"""
|
|
sys_prompt = T(".prompts:extract_kaggle_knowledge_from_feedback_prompts.system").r()
|
|
user_prompt = T(".prompts:extract_kaggle_knowledge_from_feedback_prompts.user").r(
|
|
experiment_strategy=feedback_response
|
|
)
|
|
|
|
response_analysis = APIBackend().build_messages_and_create_chat_completion(
|
|
user_prompt=user_prompt,
|
|
system_prompt=sys_prompt,
|
|
json_mode=True,
|
|
)
|
|
|
|
try:
|
|
response_json_analysis = json.loads(response_analysis)
|
|
except json.JSONDecodeError:
|
|
response_json_analysis = {"error": "Failed to parse LLM's response as JSON"}
|
|
|
|
return response_json_analysis
|
|
|
|
|
|
def process_all_case_files(directory_path: str):
|
|
output_file = Path(directory_path) / "kaggle_experience_results.json"
|
|
json_output = []
|
|
|
|
for file_path in Path(directory_path).rglob("*.case"):
|
|
with open(file_path, "r", encoding="utf-8") as file:
|
|
content = file.read()
|
|
knowledge = extract_knowledge_from_high_score_answers(content)
|
|
json_output.append(knowledge)
|
|
|
|
with open(output_file, "w", encoding="utf-8") as json_file:
|
|
json.dump(json_output, json_file, ensure_ascii=False)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
process_all_case_files(directory_path="git_ignore_folder/data/kaggle")
|