-
Notifications
You must be signed in to change notification settings - Fork 622
UN-2427 [FEAT]: Dynamically override LLM Profile in API Deployment invocation #1388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
vishnuszipstack
merged 14 commits into
main
from
UN-2427-dynamically-override-llm-profile-in-api-deployment-invocation
Jul 4, 2025
Merged
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1ce8e39
FEAT: implement complete LLM profile ID propagation and tool settings…
vishnuszipstack 8d558bf
removed unwanted file
vishnuszipstack 05819ee
pr comment fixes
vishnuszipstack 27a44f5
added llm id below to name and moved copy button
vishnuszipstack 23fe35b
moved llm profile id ownership validation to serializer
vishnuszipstack 16d454e
pr comment fixes and removed unwanted code in frontend sonar fix
vishnuszipstack 0371ce0
Merge branch 'main' into UN-2427-dynamically-override-llm-profile-in-…
vishnuszipstack 6ab5d95
sdk version bump up
vishnuszipstack 749c762
sdk version bump up
vishnuszipstack 09fe885
Commit uv.lock changes
vishnuszipstack 0922bd9
Merge branch 'main' into UN-2427-dynamically-override-llm-profile-in-…
vishnuszipstack 7fd392e
sdk version bump up in other places
vishnuszipstack 053e21f
Merge remote-tracking branch 'origin/UN-2427-dynamically-override-llm…
vishnuszipstack 89b1c66
Commit uv.lock changes
vishnuszipstack File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| import operator | ||
| from typing import Any | ||
|
|
||
|
|
||
| class ResultKeys: | ||
| METADATA = "metadata" | ||
| CONFIDENCE_DATA = "confidence_data" | ||
| OUTPUT = "output" | ||
|
|
||
|
|
||
| def _check_confidence(field_entries, threshold): | ||
| """Check if any confidence value meets or exceeds the threshold.""" | ||
| return any( | ||
| float(entry.get("confidence", 0)) * 100 >= threshold | ||
| for entries in field_entries | ||
| if entries | ||
| for entry in entries | ||
| if "confidence" in entry | ||
| ) | ||
|
|
||
|
|
||
| def _get_field_value(context: dict[str, Any], keys: list[str]) -> Any: | ||
| """Retrieve nested field value using dot notation keys.""" | ||
| field_value = context.get(ResultKeys.OUTPUT, {}) | ||
| for key in keys: | ||
| if isinstance(field_value, dict): | ||
| field_value = field_value.get(key, {}) | ||
| else: | ||
| return None | ||
| return field_value | ||
|
|
||
|
|
||
| def _evaluate_rule(rule: dict[str, Any], context: dict[str, Any]) -> bool: | ||
| """Evaluate a single rule against the context.""" | ||
| operator_map = { | ||
| "less": operator.lt, | ||
| "greater": operator.gt, | ||
| "equal": operator.eq, | ||
| "not_equal": operator.ne, | ||
| "less_or_equal": operator.le, | ||
| "greater_or_equal": operator.ge, | ||
| "starts_with": lambda field, value: str(field).startswith(value), | ||
| "ends_with": lambda field, value: str(field).endswith(value), | ||
| "like": lambda field, value: value in str(field), | ||
| "not_like": lambda field, value: value not in str(field), | ||
| } | ||
|
|
||
| field = rule["properties"]["field"] | ||
| operator_name = rule["properties"]["operator"] | ||
| value = rule["properties"]["value"][0] | ||
| keys = field.split(".") | ||
|
|
||
| if keys[0] == "jsonField": | ||
| field_value = _get_field_value(context, keys[1:]) | ||
| elif keys[0] == "confidence": | ||
| confidence_data = context.get(ResultKeys.METADATA, {}).get( | ||
| ResultKeys.CONFIDENCE_DATA, {} | ||
| ) | ||
| field_entries = confidence_data.get(keys[1], []) | ||
| return _check_confidence(field_entries, value) | ||
| else: | ||
| return False | ||
|
|
||
| try: | ||
| if isinstance(field_value, bool): | ||
| field_value = str(field_value).lower() | ||
| value = str(value).lower() | ||
| return operator_map[operator_name](field_value, value) | ||
| except Exception as e: | ||
| print(f"Error evaluating rule: {e}") | ||
| return False | ||
|
|
||
|
|
||
| def _evaluate_group(group: dict[str, Any], context: dict[str, Any]) -> bool: | ||
| """Evaluate a group of rules or nested groups.""" | ||
| conjunction = group["properties"].get("conjunction", "and").lower() | ||
| negate = group["properties"].get("not", False) | ||
|
|
||
| results = [] | ||
| for child in group.get("children1", []): | ||
| if child["type"] == "rule": | ||
| results.append(_evaluate_rule(child, context)) | ||
| elif child["type"] in ["group", "rule_group"]: | ||
| results.append(_evaluate_group(child, context)) | ||
|
|
||
| result = all(results) if conjunction == "and" else any(results) | ||
| return not result if negate else result | ||
|
|
||
|
|
||
| rules_json = { | ||
| "type": "group", | ||
| "id": "b88b8b8b-89ab-4cde-b012-31958e37dae3", | ||
| "children1": [ | ||
| { | ||
| "type": "rule_group", | ||
| "id": "989ab9b8-0123-4456-b89a-b1958e37e4a8", | ||
| "properties": { | ||
| "conjunction": "AND", | ||
| "not": False, | ||
| "field": "jsonField.newrule_2", | ||
| "fieldSrc": "field", | ||
| }, | ||
| "children1": [ | ||
| { | ||
| "type": "rule", | ||
| "id": "9a89a8b9-89ab-4cde-b012-31958e7d3ee2", | ||
| "properties": { | ||
| "fieldSrc": "field", | ||
| "field": "jsonField.newrule_2.city", | ||
| "operator": "equal", | ||
| "value": ["Cannanore"], | ||
| "valueSrc": ["value"], | ||
| "valueType": ["text"], | ||
| "valueError": [None], | ||
| }, | ||
| } | ||
| ], | ||
| } | ||
| ], | ||
| "properties": {"conjunction": "AND", "not": False}, | ||
| } | ||
|
|
||
| result = { | ||
| "output": { | ||
| "newrule_1": "Mr. Vishnu Sathyanesan", | ||
| "newrule_2": { | ||
| "address": "165/26, Panjanyan, West Thayinari Kara Road", | ||
| "city": "Cannanore", | ||
| "district": "Kannur", | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| print(_evaluate_group(rules_json, result)) | ||
vishnuszipstack marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.