-
Notifications
You must be signed in to change notification settings - Fork 1
/
alter_tasks.py
executable file
·60 lines (43 loc) · 2.22 KB
/
alter_tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from dotenv import load_dotenv
from omegaconf import OmegaConf
from tqdm import tqdm
from plotting_benchmark.benchmark import PlottingBenchmark, get_model
load_dotenv()
def get_task_shanging_task(heading: str, plot_task: str) -> str:
task = f'You will be given a task to plot a dataframe. Make it shorter, producing two sentences, keeping all useful information. Reply only the task, beginning with "{heading}". Return Nothing else more. Here is a task to plot a dataframe:\n{plot_task}.'
return task
def get_task_changing_single_task(heading: str, plot_task: str) -> str:
task = f'You will be given a task to plot a dataframe. Make it very short, producing single sentence, keeping all useful information. Reply only the task, beginning with "{heading}". Return Nothing else more. Here is a task to plot a dataframe:\n{plot_task}.'
return task
def get_compressing_model():
compressing_prompt = "You are a helpful programming assistant proficient in python and matplotlib. You are an expert in compressing tasks into very informative and short task."
model = get_model(
model_name="openai/gpt-4o",
model_pars={"temperature": 0.0},
system_prompt=compressing_prompt,
)
return model
def alter_tasks():
pass
if __name__ == "__main__":
config_path = "configs/config.yaml"
dataset_json_path = "dataset.json"
config = OmegaConf.load(config_path)
paths = config.paths
benchmark = PlottingBenchmark(config_path="configs/config.yaml")
dataset = benchmark.dataloader.get_dataset()
model = get_compressing_model()
heading = "Plot Description: "
heading_len = len(heading)
short_tasks = []
for item in tqdm(dataset.itertuples(), total=len(dataset)):
plot_task = item.task__plot_description
plot_task = plot_task[heading_len:].strip() # Removing heading
task = get_task_changing_single_task(heading, plot_task)
short_task = model.make_request(request=task)["response"]
short_tasks.append(short_task)
dataset["_task__plot_description_short_single"] = short_tasks
dataset_with_short_path = dataset_json_path.with_stem(
dataset_json_path.stem + "_with_short_single"
)
dataset.to_json(dataset_with_short_path)