From c83fbb11b6a7d2115d8b16be00e6057abf0e3bc3 Mon Sep 17 00:00:00 2001 From: Cubix33 Date: Mon, 16 Mar 2026 09:21:32 +0000 Subject: [PATCH] #261- remove type_check --- src/llm.py | 27 +++++++-------------------- src/main.py | 5 +++-- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/src/llm.py b/src/llm.py index 70937f9..91fb540 100644 --- a/src/llm.py +++ b/src/llm.py @@ -4,26 +4,14 @@ class LLM: - def __init__(self, transcript_text=None, target_fields=None, json=None): + def __init__(self, transcript_text: str = None, target_fields: list = None, json: dict = None) -> None: if json is None: json = {} self._transcript_text = transcript_text # str self._target_fields = target_fields # List, contains the template field. self._json = json # dictionary - def type_check_all(self): - if type(self._transcript_text) is not str: - raise TypeError( - f"ERROR in LLM() attributes ->\ - Transcript must be text. Input:\n\ttranscript_text: {self._transcript_text}" - ) - elif type(self._target_fields) is not list: - raise TypeError( - f"ERROR in LLM() attributes ->\ - Target fields must be a list. Input:\n\ttarget_fields: {self._target_fields}" - ) - - def build_prompt(self, current_field): + def build_prompt(self, current_field: str) -> str: """ This method is in charge of the prompt engineering. It creates a specific prompt for each target field. @params: current_field -> represents the current element of the json that is being prompted. @@ -44,9 +32,8 @@ def build_prompt(self, current_field): return prompt - def main_loop(self): - # self.type_check_all() - for field in self._target_fields.keys(): + def main_loop(self) -> 'LLM': + for field in self._target_fields: prompt = self.build_prompt(field) # print(prompt) # ollama_url = "http://localhost:11434/api/generate" @@ -83,7 +70,7 @@ def main_loop(self): return self - def add_response_to_json(self, field, value): + def add_response_to_json(self, field: str, value: str) -> None: """ this method adds the following value under the specified field, or under a new field if the field doesn't exist, to the json dict @@ -104,7 +91,7 @@ def add_response_to_json(self, field, value): return - def handle_plural_values(self, plural_value): + def handle_plural_values(self, plural_value: str) -> list: """ This method handles plural values. Takes in strings of the form 'value1; value2; value3; ...; valueN' @@ -131,5 +118,5 @@ def handle_plural_values(self, plural_value): return values - def get_data(self): + def get_data(self) -> dict: return self._json diff --git a/src/main.py b/src/main.py index 5bb632b..54f6b0a 100644 --- a/src/main.py +++ b/src/main.py @@ -3,6 +3,7 @@ from commonforms import prepare_form from pypdf import PdfReader from controller import Controller +from typing import Union def input_fields(num_fields: int): fields = [] @@ -68,7 +69,7 @@ def run_pdf_fill_process(user_input: str, definitions: list, pdf_form_path: Unio if __name__ == "__main__": file = "./src/inputs/file.pdf" user_input = "Hi. The employee's name is John Doe. His job title is managing director. His department supervisor is Jane Doe. His phone number is 123456. His email is jdoe@ucsc.edu. The signature is , and the date is 01/02/2005" - fields = ["Employee's name", "Employee's job title", "Employee's department supervisor", "Employee's phone number", "Employee's email", "Signature", "Date"] + descriptive_fields = ["Employee's name", "Employee's job title", "Employee's department supervisor", "Employee's phone number", "Employee's email", "Signature", "Date"] prepared_pdf = "temp_outfile.pdf" prepare_form(file, prepared_pdf) @@ -80,4 +81,4 @@ def run_pdf_fill_process(user_input: str, definitions: list, pdf_form_path: Unio num_fields = 0 controller = Controller() - controller.fill_form(user_input, fields, file) + controller.fill_form(user_input, descriptive_fields, file)