-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstandardisation.py
58 lines (46 loc) · 2.04 KB
/
standardisation.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
from pathlib import Path
from dotenv import load_dotenv
from langchain.prompts.chat import (ChatPromptTemplate,
HumanMessagePromptTemplate)
from create_summaries import instantiate_model, load_template
SAVE_DIR = Path("data", "standardisation")
SUMMARIES_DIR = Path("data", "summaries")
def create_prompt():
"""creare a prompt template from a "standardisation_prompt.txt" file
in the "prompts_templates" folder
"""
query = load_template(Path("prompts_templates", "standardisation_prompt.txt"))
human_message_prompt = HumanMessagePromptTemplate.from_template(query)
chat_prompt = ChatPromptTemplate.from_messages([human_message_prompt])
return chat_prompt
def main():
load_dotenv()
sections_2015_fname = Path(SUMMARIES_DIR, "2015_sections_summary.txt")
sections_2023_fname = Path(SUMMARIES_DIR, "2023_sections_summary.txt")
with open(sections_2015_fname, "r", encoding="utf-8") as f:
section_2015 = f.read()
with open(sections_2023_fname, "r", encoding="utf-8") as f:
section_2023 = f.read()
chat_prompt = create_prompt()
gpt35_standardisation_fname = Path(SAVE_DIR, "gpt35_standardisation_advice.txt")
if not gpt35_standardisation_fname.exists():
gpt35 = instantiate_model("gpt-3.5-turbo-0613")
gpt35_output = gpt35(
chat_prompt.format_prompt(
text1=section_2015, text2=section_2023
).to_messages()
)
with open(gpt35_standardisation_fname, "w", encoding="utf-8") as f:
f.write(gpt35_output.content)
gpt4_standardisation_fname = Path(SAVE_DIR, "gpt4_standardisation_advice.txt")
if not gpt4_standardisation_fname.exists():
gpt4 = instantiate_model("gpt-4")
gpt4_output = gpt4(
chat_prompt.format_prompt(
text1=section_2015, text2=section_2023
).to_messages()
)
with open(gpt4_standardisation_fname, "w", encoding="utf-8") as f:
f.write(gpt4_output.content)
if __name__ == "__main__":
main()