-
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refine class design and inheritance first version code (#41)
* refine class design and inheritance first version code * fix all typos --------- Co-authored-by: xuyang1 <[email protected]>
- Loading branch information
1 parent
f52ebc3
commit 5bf6934
Showing
39 changed files
with
717 additions
and
482 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
rdagent/app/factor_extraction_and_implementation/factor_extract_and_implement.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from abc import abstractmethod | ||
from pathlib import Path | ||
|
||
from jinja2 import Environment, StrictUndefined | ||
|
||
from rdagent.core.prompts import Prompts | ||
from rdagent.core.proposal import ( | ||
Hypothesis, | ||
Hypothesis2Task, | ||
HypothesisGen, | ||
Scenario, | ||
Trace, | ||
) | ||
from rdagent.oai.llm_utils import APIBackend | ||
|
||
prompt_dict = Prompts(file_path=Path(__file__).parent / "prompts.yaml") | ||
|
||
|
||
FactorHypothesis = Hypothesis | ||
|
||
|
||
class FactorHypothesisGen(HypothesisGen): | ||
def __init__(self, scen: Scenario): | ||
super().__init__(scen) | ||
self.gen_context_flag = False | ||
self.gen_context_dict = None | ||
self.gen_json_flag = False | ||
|
||
# The following methods are scenario related so they should be implemented in the subclass | ||
@abstractmethod | ||
def prepare_gen_context(self, trace: Trace) -> None: ... | ||
|
||
@abstractmethod | ||
def gen_response_to_hypothesis_list(self, response: str) -> FactorHypothesis: ... | ||
|
||
def gen(self, trace: Trace) -> FactorHypothesis: | ||
assert self.gen_context_flag, "Please call prepare_gen_context before calling gen." | ||
self.gen_context_flag = False # reset the flag | ||
|
||
system_prompt = ( | ||
Environment(undefined=StrictUndefined) | ||
.from_string(prompt_dict["factor_hypothesis_gen"]["system_prompt"]) | ||
.render(scenario=self.scen.get_scenario_all_desc()) | ||
) | ||
user_prompt = ( | ||
Environment(undefined=StrictUndefined) | ||
.from_string(prompt_dict["factor_hypothesis_gen"]["user_prompt"]) | ||
.render(self.gen_context_dict) | ||
) | ||
|
||
resp = APIBackend().build_messages_and_create_chat_completion( | ||
user_prompt, system_prompt, json_mode=self.gen_json_flag | ||
) | ||
|
||
hypothesis = self.gen_response_to_hypothesis_list(resp) | ||
|
||
return hypothesis | ||
|
||
|
||
class FactorHypothesis2Task(Hypothesis2Task): | ||
def convert(self, bs: FactorHypothesis) -> None: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
factor_hypothesis_gen: | ||
system_prompt: |- | ||
The user is trying to generate new hypothesis on the factors in data-driven research and development. | ||
The factors are used in a certain scenario, the scenario is as follows: | ||
{{ scenario }} | ||
The user has made several hypothesis on this sencario and did several evaluation on them. The user will provide this information to you. | ||
To help you generate new hypothesis, the user has prepared some additional information for you. You should use this information to help generate new factors. | ||
user_prompt: |- | ||
The user has made several hypothesis on this sencario and did several evaluation on them. | ||
The former hypothesis and the corresponding feedbacks are as follows: | ||
{{ hypothesis_and_feedback }} | ||
To help you generate new factors, we have prepared the following information for you: | ||
{{ RAG }} | ||
Please generate the new hypothesis based on the information above and generate the output following the format below: | ||
{{ factor_output_format }} | ||
factor_hypothesis_to_tasks: | ||
system_prompt: |- | ||
The user is trying to generate new factors based on the hypothesis generated in the previous step. | ||
The factors are used in certain scenario, the scenario is as follows: | ||
{{ scenario }} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from rdagent.components.task_implementation.factor_implementation.factor import ( | ||
FactorExperiment, | ||
) | ||
from rdagent.core.experiment import Loader | ||
|
||
|
||
class FactorExperimentLoader(Loader[FactorExperiment]): | ||
pass | ||
|
||
|
||
class ModelExperimentLoader(Loader[FactorExperiment]): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from rdagent.components.task_implementation.factor_implementation.factor import ( | ||
FactorTask, | ||
) | ||
from rdagent.core.experiment import Loader | ||
|
||
|
||
class FactorTaskLoader(Loader[FactorTask]): | ||
pass | ||
|
||
|
||
class ModelTaskLoader(Loader[FactorTask]): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.