Merged in bugfix/daip2-1440-contract-amendment-num (pull request #849)
Bugfix/daip2 1440 contract amendment num to main * update full context additional instruction for amendment num * uv formatting done * remove print statements * Merged main into bugfix/daip2-1440-contract-amendment-num * added filename amendment num * updated pipelines and removed print statements * Merged main into bugfix/daip2-1440-contract-amendment-num * code moved to hybrid smart chunking * Merged main into bugfix/daip2-1440-contract-amendment-num * Merged main into bugfix/daip2-1440-contract-amendment-num * removed categorical values from amendment number Approved-by: Katon Minhas
This commit is contained in:
committed by
Katon Minhas
parent
a5c743f37f
commit
ff8ec57ed0
@@ -6,6 +6,7 @@ COLUMN_ORDER = [
|
|||||||
"FILE_NAME",
|
"FILE_NAME",
|
||||||
"CONTRACT_TITLE",
|
"CONTRACT_TITLE",
|
||||||
"CONTRACT_AMENDMENT_NUM",
|
"CONTRACT_AMENDMENT_NUM",
|
||||||
|
"FILENAME_AMENDMENT_NUM",
|
||||||
"AARETE_DERIVED_AMENDMENT_NUM",
|
"AARETE_DERIVED_AMENDMENT_NUM",
|
||||||
"CLIENT_NAME",
|
"CLIENT_NAME",
|
||||||
"PAYER_NAME",
|
"PAYER_NAME",
|
||||||
|
|||||||
@@ -98,7 +98,6 @@ def process_single_field(
|
|||||||
elif isinstance(val, str):
|
elif isinstance(val, str):
|
||||||
parsed[field.field_name] = val
|
parsed[field.field_name] = val
|
||||||
field_value = parsed[field.field_name]
|
field_value = parsed[field.field_name]
|
||||||
|
|
||||||
if field_value == "N/A":
|
if field_value == "N/A":
|
||||||
field.field_type = "full_context"
|
field.field_type = "full_context"
|
||||||
if field.field_name == "PAYER_NAME":
|
if field.field_name == "PAYER_NAME":
|
||||||
@@ -341,6 +340,9 @@ def run_hybrid_smart_chunked_fields(
|
|||||||
gc.collect()
|
gc.collect()
|
||||||
logging.debug(f"RAG extraction done: {len(answers_dict)} fields")
|
logging.debug(f"RAG extraction done: {len(answers_dict)} fields")
|
||||||
|
|
||||||
|
# FILENAME_AMENDMENT_NUM
|
||||||
|
answers_dict = extract_amendment_num_from_filename(answers_dict, filename)
|
||||||
|
|
||||||
answers_dict = check_and_update_effective_date(
|
answers_dict = check_and_update_effective_date(
|
||||||
answers_dict, text_dict, filename
|
answers_dict, text_dict, filename
|
||||||
)
|
)
|
||||||
@@ -388,3 +390,42 @@ def run_hybrid_smart_chunked_fields(
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"RAG pipeline failed: {e}")
|
logging.error(f"RAG pipeline failed: {e}")
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
def extract_amendment_num_from_filename(answer_dict: dict, filename: str) -> dict:
|
||||||
|
"""Extract amendment number from filename if not found in contract content.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
answer_dict (dict): Dictionary containing CONTRACT_AMENDMENT_NUM key.
|
||||||
|
filename (str): Filename to extract amendment number from.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: Updated answer_dict with FILENAME_AMENDMENT_NUM populated.
|
||||||
|
"""
|
||||||
|
if (
|
||||||
|
string_utils.is_empty(answer_dict.get("CONTRACT_AMENDMENT_NUM"))
|
||||||
|
or answer_dict.get("CONTRACT_AMENDMENT_NUM") == "UNKNOWN"
|
||||||
|
):
|
||||||
|
|
||||||
|
prompt = prompt_templates.EXTRACT_AMENDMENT_NUM_FROM_FILENAME(filename)
|
||||||
|
llm_answer_raw = llm_utils.invoke_claude(
|
||||||
|
prompt,
|
||||||
|
"sonnet_latest",
|
||||||
|
filename,
|
||||||
|
cache=True,
|
||||||
|
instruction=prompt_templates.EXTRACT_AMENDMENT_NUM_FROM_FILENAME_INSTRUCTION(),
|
||||||
|
usage_label="EXTRACT_AMENDMENT_NUM_FROM_FILENAME",
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
llm_answer_final = string_utils.universal_json_load(llm_answer_raw)
|
||||||
|
answer_dict["FILENAME_AMENDMENT_NUM"] = llm_answer_final.get(
|
||||||
|
"amendment_number", "N/A"
|
||||||
|
)
|
||||||
|
except (ValueError, KeyError) as e:
|
||||||
|
logging.error(
|
||||||
|
f"Failed to parse amendment number from filename {filename}: {e}"
|
||||||
|
)
|
||||||
|
answer_dict["FILENAME_AMENDMENT_NUM"] = "N/A"
|
||||||
|
|
||||||
|
return answer_dict
|
||||||
|
|||||||
@@ -1203,6 +1203,20 @@ def ONE_TO_ONE_MULTI_FIELD_INSTRUCTION() -> str:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def EXTRACT_AMENDMENT_NUM_FROM_FILENAME(filename) -> str:
|
||||||
|
return f"""Filename: {filename}"""
|
||||||
|
|
||||||
|
|
||||||
|
def EXTRACT_AMENDMENT_NUM_FROM_FILENAME_INSTRUCTION() -> str:
|
||||||
|
return """[OBJECTIVE]\n
|
||||||
|
Analyze the given filename string to extract the amendment number of the contract document if it exists.
|
||||||
|
Return only numeric values representing the amendment number. categorical values like 'A','B' etc are not amednment numbers. If no amendment number is found, return N/A.
|
||||||
|
Briefly explain your reasoning, then put your final answer in JSON dictionary format as follows:
|
||||||
|
{{
|
||||||
|
"amendment_number": "<extracted amendment number or N/A>"
|
||||||
|
}}"""
|
||||||
|
|
||||||
|
|
||||||
#####################################################################################
|
#####################################################################################
|
||||||
############################### PREPROCESSING PROMPTS ###############################
|
############################### PREPROCESSING PROMPTS ###############################
|
||||||
#####################################################################################
|
#####################################################################################
|
||||||
|
|||||||
Reference in New Issue
Block a user