Files
doczyai-pipelines/archive/git_diff_changes.py
T
Katon Minhas afb6d5185d Merged in feature/lesser-table-caching-refactor-hybrid (pull request #847)
Feature/lesser table caching refactor hybrid

* chore: Remove unused duplicate main.py from shared pipeline

* fix: Correct crosswalk paths in aarete_derived.py

* chore: Remove unused documentation files from fieldExtraction

* docs: Add documentation files to documentation folder

* docs: Update README with uv setup, expanded project structure, and branching conventions

* docs: Add uv installation steps with Ubuntu/WSL emphasis

* Enable prompt caching for all remaining LLM calls

- Add _INSTRUCTION() functions for: EXHIBIT_HEADER, EXHIBIT_LINKAGE,
  EXHIBIT_TITLE_MATCH, DATE_FIX, DERIVED_TERM_DATE, CHECK_PROVIDER_NAME_MATCH,
  SPECIAL_CASE_ASSIGNMENT
- Update all invoke_claude() calls in saas and clover pipelines to use
  cache=True with corresponding _INSTRUCTION() functions
- Add new instructions to get_cacheable_instructions() for cache warming
- Update tests for new instruction functions

Functions now using caching:
- prompt_exhibit_level
- prompt_exhibit_lesser (EXHIBIT_LEVEL_LESSER_OF)
- prompt_fee_schedule_breakout
- prompt_grouper_breakout
- prompt_special_case_assignment
- prompt_exhibit_linkage
- prompt_exhibit_header
- prompt_smart_chunked (ONE_TO_ONE templates)
- prompt_date_fix
- prompt_derived_term_date
- prompt_exhibit_title_match
- provider_name_match_check

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Reorder

* feat: Add bcbs_promise client pipeline with OFFSET_TERM extraction

- Add new bcbs_promise client with HSC-based OFFSET_TERM field extraction
- Extract full paragraph text of offset/recoupment provisions from contracts
- Derive OFFSET_INDICATOR (Y/N) from OFFSET_TERM presence
- Fix reorder_columns to preserve extra columns not in COLUMN_ORDER
- Update QC/QA output path to outputs/qc_qa/

* fix: Update dev deps and test assertions for QC/QA output path

- Add pytest/pytest-mock to dev dependencies for mypy type checking
- Update test assertions to expect outputs/qc_qa instead of qa_qc_output

* style: Apply black formatting to prompt_templates.py

* Merge main, move scripts

* Archive some scripts

* update py version

* remove .py version file

* Remove ASCII characters

* Restore testbed code

* restore tracking

* Update testbed metrics

* Enable prompt caching for CODE_LAST_CHECK, FILL_BILL_TYPE, DUAL_LOB_CHECK, and GROUPER_BREAKOUT

- Add CODE_LAST_CHECK_INSTRUCTION() for service specificity classification
- Add FILL_BILL_TYPE_INSTRUCTION() for bill type code determination
- Add DUAL_LOB_CHECK_INSTRUCTION() for Medicare/Medicaid classification
- Update code_funcs.py to use caching for CODE_LAST_CHECK, FILL_BILL_TYPE, GROUPER_BREAKOUT
- Update postprocessing_funcs.py to use caching for DUAL_LOB_CHECK
- Add new instructions to get_cacheable_instructions() for cache warming
- Add unit tests for new instruction functions

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Fix postprocessing_funcs to remove invalid columns

* Merge branch 'main' into feature/lesser-table-caching-refactor-hybrid

* Revert prompt caching changes from aed1b73c

* update formatting

* Update imports


Approved-by: Sha Brown
Approved-by: Praneel Panchigar
2026-01-26 16:52:55 +00:00

113 lines
3.5 KiB
Python

import os
import subprocess
import requests
BITBUCKET_REPO_OWNER = "aarete"
BITBUCKET_REPO_SLUG = "doczy.ai"
BB_PIPELINE_BRANCH = os.getenv("BB_PIPELINE_BRANCH", "DEV")
BITBUCKET_AUTH_HEADER = os.getenv("BITBUCKET_AUTH_HEADER")
from terminal import run_command, prepare_logger, decorate_warn
LOGGER = prepare_logger()
def check_bitbucket_auth_header():
if os.getenv("BITBUCKET_CI") == "true" and not BITBUCKET_AUTH_HEADER:
raise EnvironmentError("Error: BITBUCKET_AUTH_HEADER is not set.")
def get_last_successful_commit(module):
if os.getenv("BITBUCKET_CI") != "true":
rc, result = run_command(
"git rev-parse HEAD",
log_output=True,
log_cmd=True,
log_prefix=f"[{module}]",
)
return result
for commit in (
subprocess.check_output(["git", "log", "--format=%h", "-n", "30"])
.decode()
.split()
):
url = f"https://api.bitbucket.org/2.0/repositories/{BITBUCKET_REPO_OWNER}/{BITBUCKET_REPO_SLUG}/commit/{commit}/statuses/"
LOGGER.info(f"commit={commit}, url={url}")
basic_url_headers = {
BITBUCKET_AUTH_HEADER.split(": ")[0]: BITBUCKET_AUTH_HEADER.split(": ")[1]
}
response = requests.get(url, headers=basic_url_headers).json()
LOGGER.debug(f"response={response}")
for item in response.get("values", []):
name = item["name"]
if "security/snyk" in name or "iacbot" in name:
continue
commit_state = item["state"]
ref_name = item["refname"]
updated_on = item["updated_on"]
LOGGER.info(
f"COMMIT={commit}, COMMIT_STATE={commit_state}, REF_NAME={ref_name}, NAME={name}, UPDATED_ON={updated_on}"
)
if commit_state == "SUCCESSFUL" and ref_name.startswith(BB_PIPELINE_BRANCH):
return commit
return commit
def get_changes_output(module, last_successful_commit):
if os.getenv("BITBUCKET_CI") == "true":
_, result = run_command(
f"git diff --dirstat=files,0 {last_successful_commit} | sed -E 's/^[ 0-9.]+% //g'",
log_output=True,
log_cmd=True,
log_prefix=f"[{module}]",
)
return result
else:
_, result = run_command(
"git diff --dirstat=files,0 HEAD~1 | sed -E 's/^[ 0-9.]+% //g'",
log_output=True,
log_cmd=True,
log_prefix=f"[{module}]",
)
return result
def is_deploy_module(module, dir_prefix):
check_bitbucket_auth_header()
if os.getenv("IS_DEPLOY_ALL") == "true":
return True
if os.getenv("SKIP_DEPLOY"):
return False
if module == os.getenv("MODULE_NAME"):
return True
elif os.getenv("MODULE_NAME"):
return False
changes_output = get_changes_output(module, get_last_successful_commit(module))
LOGGER.info(f"changes_output={changes_output}")
special_checks = [
("textract-pipeline/terraform", "textract-pipeline/src"),
]
for mod, pattern in special_checks:
pattern_found = any(pattern in change for change in changes_output)
if module == mod and pattern_found:
LOGGER.info(
decorate_warn(
f"Marking {module} as changed based on the special pattern={pattern}"
)
)
return True
if f"{dir_prefix}{module}/" in changes_output:
return True
return False