File size: 3,607 Bytes
0fadcb9
54af9e3
0fadcb9
 
cb7ff7d
0fadcb9
 
 
54af9e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0fadcb9
d005419
aa2cc5f
7648566
0fadcb9
 
 
 
 
d005419
0fadcb9
d005419
 
cb7ff7d
d005419
cb7ff7d
 
 
 
 
 
 
 
 
 
d005419
 
54af9e3
aa2cc5f
 
54af9e3
 
 
 
 
 
 
 
 
 
 
 
cb7ff7d
 
 
 
 
 
 
d005419
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
66
67
68
69
70
71
72
73
74
import datetime
from enum import Enum
from pathlib import Path

from local_storage.entities import DetailsType, SavedDetails
from utils.date_utils import get_today_date_as_dd_mm_yyyy


class Questions(Enum):
    FULL_NAME = 0
    WORK_TO_DO = 1
    COMMUNITY = 2
    BUILDING = 3
    UNIT_APT_NUMBER = 4
    OWNER_OR_TENANT = 5
    START_DATE = 6
    END_DATE = 7
    CONTACT_NUMBER = 8
    COMPANY_NAME = 9
    COMPANY_EMAIL = 10
    COMPANY_NUMBER = 11
    YOUR_EMAIL = 12

class PromptsManager:
    def __init__(self, work_categories: dict[str, str] = None):
        self.work_categories = work_categories
        base_path = Path(__file__).parent
        with open(Path(base_path, "system_prompt.txt")) as sysprompt_file:
            self.system_prompt: str = sysprompt_file.read()
        with open(Path(base_path, "questions.txt")) as questions_file:
            self.questions: list[str] = questions_file.readlines()
        with open(Path(base_path, "verification_prompt2.txt")) as verification_prompt_file:
            verification_prompt = verification_prompt_file.read()
            todays_date = get_today_date_as_dd_mm_yyyy()
            verification_prompt = verification_prompt.replace("{today}", todays_date)
            self.verification_prompt: str = verification_prompt
            self.verification_prompt_questions = self.verification_prompt.split("\n")

    def verify_user_input_prompt(self, user_prompt, exclude_questions_group: list[SavedDetails] = None) -> str:
        prompt = f"""
            Using only this information \n {user_prompt} \n answer the following questions, for each question that you cannot answer just answer 'null'.
            Put each answer in a new line, keep the answer brief 
            and maintain the order in which the questions are asked. Do not add any preamble:
        """

        skip_questions = [self.get_questions(d) for d in exclude_questions_group]
        questions = [q for idx, q in enumerate(self.verification_prompt_questions) if idx not in skip_questions]
        return prompt + "\n".join(questions)

    def get_work_category(self, work_description: str) -> str:
        return (
            f"The work to do is {work_description}: choose the most accurate categories among the following:"
            f"{', '.join(self.work_categories.values())}\n"
            f"Only return the categories, separated by a semicolon")

    @staticmethod
    def questions_to_field_labels():
        return {
            Questions.FULL_NAME: "Full name", Questions.WORK_TO_DO: "Work to do", Questions.COMMUNITY: "Community",
            Questions.BUILDING:"Building name", Questions.UNIT_APT_NUMBER: "Unit/apartment number",
            Questions.OWNER_OR_TENANT: "Owner/Tenant", Questions.START_DATE: "Start date",
            Questions.END_DATE: "End date", Questions.CONTACT_NUMBER: "Your contact number",
            Questions.COMPANY_NAME: "Contractor company name", Questions.COMPANY_EMAIL: "Contracting company email",
            Questions.COMPANY_NUMBER: "Contracting company contact number", Questions.YOUR_EMAIL: "Your email"
        }
    def get_questions(self, type_:DetailsType):
        if type_ == DetailsType.PERSONAL_DETAILS:
            return [Questions.FULL_NAME, Questions.CONTACT_NUMBER, Questions.YOUR_EMAIL]
        if type_ == DetailsType.CONTRACTOR_DETAILS:
            return [Questions.COMPANY_NAME, Questions.COMPANY_NUMBER, Questions.COMPANY_EMAIL]
        if type_ == DetailsType.LOCATION_DETAILS:
            return [Questions.OWNER_OR_TENANT, Questions.COMMUNITY, Questions.BUILDING, Questions.UNIT_APT_NUMBER]