-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_formula_to_table.py
65 lines (49 loc) · 1.75 KB
/
add_formula_to_table.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
61
62
63
64
65
import argparse
from data_handler.JsonHandler import JsonHandler
from formula.FormulaHandler import FormulaHandler
from model.ChatGPT import ChatGPT
from repository.DiskFormulaRepository import DiskFormulaRepository
formula_repository = DiskFormulaRepository(formula_table_path="./data/formula_table.json", variable_class_table_path="./data/variable_class_table.json")
json_handler = JsonHandler()
LLM_PRICE_PER_1K_TOKENS = 0.002
LLM_MAX_CONTEXT_TOKENS_LENGTH = 4090
"""
get args
"""
parser = argparse.ArgumentParser()
parser.add_argument("--data_path", help="Specify the data path")
args, extra_args = parser.parse_known_args()
extra_args = dict(zip(extra_args[0::2], extra_args[1::2]))
data_path = args.data_path
if data_path is None:
print("data_path is not specified")
exit(1)
"""
read config
"""
config = json_handler.return_json_as_dict(json_path="./config.json")
"""
set up chatgpt
"""
model = ChatGPT(
price_per_1k_tokens=LLM_PRICE_PER_1K_TOKENS,
max_context_tokens_length=LLM_MAX_CONTEXT_TOKENS_LENGTH,
)
ChatGPT.set_api_key(config["openai_api_key"])
"""
add formula to formula table
might send request to ChatGPT
"""
formula_handler = FormulaHandler(model=model)
formula_handler.set_formula_detail_list_from_file(data_path)
formula_detail_list = formula_handler.get_formula_detail_list()
for formula_detail in formula_detail_list:
print(f"origin formula:\n\n{formula_detail.formula}")
print("---")
print(f"generated program:\n\n{formula_detail.calc_formula}")
# client check if the formula program is correct
client_answer = input("Is the formula program correct? (y/n)")
if client_answer != "y":
print("formula program is not correct, pass this one")
continue
formula_repository.add_formula(formula_detail)