Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 7 additions & 20 deletions src/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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'
Expand All @@ -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
5 changes: 3 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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 <Mamañema>, 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)

Expand All @@ -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)