Skip to content

Commit

Permalink
wrap validation pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
andrebeu committed Feb 15, 2024
1 parent 8c422ea commit 81e5afb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
12 changes: 6 additions & 6 deletions api-service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
create_df_from_analysis_data,
combine_all_usages,
)
from utils.dynamic_rule_checking import check_rule_modification
from utils.rule_splitting import (
split_rule_by_or_operands,
split_broad_rule_with_instructions,
)
from utils.dynamic_rule_checking import validate_modified_rule


logger = setup_logger(__name__)
Expand Down Expand Up @@ -233,7 +233,7 @@ def rule_rewriting(input_data: RuleInputData) -> JSONResponse:
specific_actions=input_data.specific_actions,
)
response = response.replace("```xml\n", "").replace("\n```", "")
response, usages = check_rule_modification(response)
response, usages = validate_modified_rule(response)
all_usages = [usage] + usages
combined_usage = combine_all_usages(all_usages)
return JSONResponse(content={"response": response, "usage": combined_usage})
Expand Down Expand Up @@ -286,7 +286,7 @@ async def bulk_rule_rewriting(csv_file: UploadFile = File(...)) -> JSONResponse:
modified_rule_text = modified_rule_text.replace("```xml\n", "").replace(
"\n```", ""
)
modified_rule_text, usages = check_rule_modification(modified_rule_text)
modified_rule_text, usages = validate_modified_rule(modified_rule_text)
responses.append(
{
"original_rule_id": rule_id,
Expand Down Expand Up @@ -330,7 +330,7 @@ def rule_rewriting(input_data: RuleInputData) -> JSONResponse:
new_rules_verified = []
all_usages = [usage]
for r in new_rules:
validated_rule, _usage = check_rule_modification(r)
validated_rule, _usage = validate_modified_rule(r)
new_rules_verified.append(validated_rule)
all_usages.extend(_usage)
combined_usage = combine_all_usages(all_usages)
Expand Down Expand Up @@ -380,7 +380,7 @@ async def create_rule(input_data: CreateRuleInput) -> JSONResponse:
)
new_id = "".join(str(random.randint(0, 9)) for _ in range(40))
response = response.replace("{new_rule_id}", f"BRIEFCATCH_{new_id}")
response, usages = check_rule_modification(response)
response, usages = validate_modified_rule(response)
all_usages = [usage] + usages
combined_usage = combine_all_usages(all_usages)
return JSONResponse(content={"response": response, "usage": combined_usage})
Expand Down Expand Up @@ -443,7 +443,7 @@ async def bulk_rule_creation(csv_file: UploadFile = File(...)) -> JSONResponse:
new_id = "".join(str(random.randint(0, 9)) for _ in range(40))
response = response.replace("{new_rule_id}", f"BRIEFCATCH_{new_id}")
new_rule_name = f"BRIEFCATCH_{record.get('category').upper()}_{record.get('rule_number')}"
new_rule_name, usages = check_rule_modification(new_rule_name)
new_rule_name, usages = validate_modified_rule(new_rule_name)
responses.append(
{"rule_name": new_rule_name, "rule": response, "usage": usage}
)
Expand Down
16 changes: 13 additions & 3 deletions api-service/utils/dynamic_rule_checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
remove_thought_tags,
)
from regexp_validation import post_process_xml

from suggestion_tag_validation import validate_suggestion

dynamic_logger = setup_logger(__name__)

Expand Down Expand Up @@ -153,6 +153,16 @@ def check_rule_modification(input_rule_xml: str) -> Tuple[str, List[Dict]]:
response_model_rule_rewrite,
)
validated_rule_xml = new_rule_xml
# post process
validated_rule_xml = post_process_xml(validated_rule_xml)

return validated_rule_xml, usages


def validate_modified_rule(xml):
usages = []
# post process
xml = post_process_xml(xml)
xml, usage = check_rule_modification(xml)
usages.extend(usage)
xml, usages = validate_suggestion(xml)
usages.extend(usage)
return xml, usages

0 comments on commit 81e5afb

Please sign in to comment.