mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-07-28 16:07:46 +00:00
805f337fc4
* change_log_object * lint code * delete comments * change_log_object * change_log_object * fix import test error * update code * update code * fix bugs * skip mypy error * skip mypy error * skip mypy error * Start the flask server before running the demo. * achieve front and back interaction * fix github-advanced-security comments * fix github-advanced-security comments * tmp ignore * fix CI * move some logic * change format * adjust logic * log2json changes * tmp * fix * fix bug * refine log2json between 5 scenarios * fix * refine codes * fix logic * use localhost * add loop & all_duration param for old scenario startup * merge control logic * add README for server ui api * update README * reuse code in logger * add loop_n and all_duration param * fix upload * ui server now use port in setting * fix port setting * fix port setting * fix mypy check * refine logger and log storage * fix ruff error * fix CI * refine logger, loop, storage * bind one FileStorage with one logger * not truncate log storage * refine LoopBase.load(), use `checkout` instead of `output_path` and `do_truncate` * clear session folder when loading loop to run * move component info init step to ExpGen Class * Update rdagent/utils/workflow.py * move truncate_session function to LoopBase class * add checkout param for other scenarios * fix bug * move WebStorage to UI * change web_storage name * add randomname to requirements * add typer * fix requirements --------- Co-authored-by: WinstonLiyte <1957922024@qq.com> Co-authored-by: Bowen Xian <xianbowen@outlook.com> Co-authored-by: you-n-g <you-n-g@users.noreply.github.com>
50 lines
1.2 KiB
Python
50 lines
1.2 KiB
Python
"""
|
|
This is the preliminary version of the APE (Automated Prompt Engineering)
|
|
"""
|
|
|
|
import pickle
|
|
from pathlib import Path
|
|
|
|
from rdagent.log.conf import LOG_SETTINGS
|
|
|
|
|
|
def get_llm_qa(file_path):
|
|
data_flt = []
|
|
with open(file_path, "rb") as f:
|
|
data = pickle.load(f)
|
|
print(len(data))
|
|
for item in data:
|
|
if "debug_llm" in item["tag"]:
|
|
data_flt.append(item)
|
|
return data_flt
|
|
|
|
|
|
# Example usage
|
|
# use
|
|
file_path = Path(LOG_SETTINGS.trace_path) / "debug_llm.pkl"
|
|
llm_qa = get_llm_qa(file_path)
|
|
print(len(llm_qa))
|
|
|
|
print(llm_qa[0])
|
|
|
|
# Initialize APE backend
|
|
from rdagent.oai.llm_utils import APIBackend
|
|
from rdagent.utils.agent.tpl import T
|
|
|
|
api = APIBackend()
|
|
|
|
# Analyze test data and generate improved prompts
|
|
for qa in llm_qa:
|
|
# Generate system prompt for APE
|
|
system_prompt = T(".prompts:ape.system").r()
|
|
|
|
# Generate user prompt with context from LLM QA
|
|
user_prompt = T(".prompts:ape.user").r(
|
|
system=qa["obj"].get("system", ""), user=qa["obj"]["user"], answer=qa["obj"]["resp"]
|
|
)
|
|
analysis_result = api.build_messages_and_create_chat_completion(
|
|
system_prompt=system_prompt, user_prompt=user_prompt
|
|
)
|
|
print(f"█" * 60)
|
|
yes = input("Do you want to continue? (y/n)")
|