lexsi-sdk 0.1.16__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lexsi_sdk/__init__.py +5 -0
- lexsi_sdk/client/__init__.py +0 -0
- lexsi_sdk/client/client.py +176 -0
- lexsi_sdk/common/__init__.py +0 -0
- lexsi_sdk/common/config/.env.prod +3 -0
- lexsi_sdk/common/constants.py +143 -0
- lexsi_sdk/common/enums.py +8 -0
- lexsi_sdk/common/environment.py +49 -0
- lexsi_sdk/common/monitoring.py +81 -0
- lexsi_sdk/common/trigger.py +75 -0
- lexsi_sdk/common/types.py +122 -0
- lexsi_sdk/common/utils.py +93 -0
- lexsi_sdk/common/validation.py +110 -0
- lexsi_sdk/common/xai_uris.py +197 -0
- lexsi_sdk/core/__init__.py +0 -0
- lexsi_sdk/core/agent.py +62 -0
- lexsi_sdk/core/alert.py +56 -0
- lexsi_sdk/core/case.py +618 -0
- lexsi_sdk/core/dashboard.py +131 -0
- lexsi_sdk/core/guardrails/__init__.py +0 -0
- lexsi_sdk/core/guardrails/guard_template.py +299 -0
- lexsi_sdk/core/guardrails/guardrail_autogen.py +554 -0
- lexsi_sdk/core/guardrails/guardrails_langgraph.py +525 -0
- lexsi_sdk/core/guardrails/guardrails_openai.py +541 -0
- lexsi_sdk/core/guardrails/openai_runner.py +1328 -0
- lexsi_sdk/core/model_summary.py +110 -0
- lexsi_sdk/core/organization.py +549 -0
- lexsi_sdk/core/project.py +5131 -0
- lexsi_sdk/core/synthetic.py +387 -0
- lexsi_sdk/core/text.py +595 -0
- lexsi_sdk/core/tracer.py +208 -0
- lexsi_sdk/core/utils.py +36 -0
- lexsi_sdk/core/workspace.py +325 -0
- lexsi_sdk/core/wrapper.py +766 -0
- lexsi_sdk/core/xai.py +306 -0
- lexsi_sdk/version.py +34 -0
- lexsi_sdk-0.1.16.dist-info/METADATA +100 -0
- lexsi_sdk-0.1.16.dist-info/RECORD +40 -0
- lexsi_sdk-0.1.16.dist-info/WHEEL +5 -0
- lexsi_sdk-0.1.16.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from typing import Callable, Optional
|
|
3
|
+
from lexsi_sdk.client.client import APIClient
|
|
4
|
+
from IPython.display import display, HTML
|
|
5
|
+
|
|
6
|
+
from lexsi_sdk.common.xai_uris import POLL_EVENTS
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def parse_float(s):
|
|
10
|
+
"""parse float from string, return None if not possible
|
|
11
|
+
|
|
12
|
+
:param s: string to parse
|
|
13
|
+
:return: float or None
|
|
14
|
+
"""
|
|
15
|
+
try:
|
|
16
|
+
return float(s)
|
|
17
|
+
except ValueError:
|
|
18
|
+
return None
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def parse_datetime(s, format="%Y-%m-%d %H:%M:%S"):
|
|
22
|
+
"""Parse datetime from string, return None if not possible
|
|
23
|
+
|
|
24
|
+
:param s: string to parse
|
|
25
|
+
:param format: format string for datetime parsing
|
|
26
|
+
:return: datetime or None
|
|
27
|
+
"""
|
|
28
|
+
try:
|
|
29
|
+
return datetime.strptime(s, format)
|
|
30
|
+
except ValueError:
|
|
31
|
+
return None
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def pretty_date(date: str) -> str:
|
|
35
|
+
"""return date in format dd-mm-YYYY HH:MM:SS
|
|
36
|
+
|
|
37
|
+
:param date: str datetime
|
|
38
|
+
:return: pretty datetime
|
|
39
|
+
"""
|
|
40
|
+
try:
|
|
41
|
+
datetime_obj = datetime.strptime(date, "%Y-%m-%dT%H:%M:%S.%f")
|
|
42
|
+
except ValueError:
|
|
43
|
+
try:
|
|
44
|
+
datetime_obj = datetime.strptime(date, "%Y-%m-%d %H:%M:%S.%f")
|
|
45
|
+
except ValueError:
|
|
46
|
+
print("Date format invalid.")
|
|
47
|
+
|
|
48
|
+
return datetime_obj.strftime("%d-%m-%Y %H:%M:%S")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def poll_events(
|
|
52
|
+
api_client: APIClient,
|
|
53
|
+
project_name: str,
|
|
54
|
+
event_id: str,
|
|
55
|
+
handle_failed_event: Optional[Callable] = None,
|
|
56
|
+
progress_message: str = "progress",
|
|
57
|
+
):
|
|
58
|
+
"""Poll long-running event stream and print incremental progress.
|
|
59
|
+
|
|
60
|
+
:param api_client: API client with streaming support.
|
|
61
|
+
:param project_name: Project name owning the event.
|
|
62
|
+
:param event_id: Identifier of the event to track.
|
|
63
|
+
:param handle_failed_event: Optional callback to invoke on failure.
|
|
64
|
+
:param progress_message: Label used when printing progress.
|
|
65
|
+
:return: None. Raises on failure events.
|
|
66
|
+
"""
|
|
67
|
+
last_message = ""
|
|
68
|
+
log_length = 0
|
|
69
|
+
progress = 0
|
|
70
|
+
|
|
71
|
+
for event in api_client.stream(
|
|
72
|
+
uri=f"{POLL_EVENTS}?project_name={project_name}&event_id={event_id}",
|
|
73
|
+
method="GET"
|
|
74
|
+
):
|
|
75
|
+
details = event.get("details")
|
|
76
|
+
|
|
77
|
+
if not event.get("success"):
|
|
78
|
+
raise Exception(details)
|
|
79
|
+
if details.get("event_logs"):
|
|
80
|
+
print(details.get("event_logs")[log_length:])
|
|
81
|
+
log_length = len(details.get("event_logs"))
|
|
82
|
+
if details.get("message") != last_message:
|
|
83
|
+
last_message = details.get("message")
|
|
84
|
+
print(f"{details.get('message')}")
|
|
85
|
+
if details.get("progress"):
|
|
86
|
+
if details.get("progress") != progress:
|
|
87
|
+
progress = details.get("progress")
|
|
88
|
+
print(f"{progress_message}: {progress}%")
|
|
89
|
+
# display(HTML(f"<progress style='width:100%' value='{progress}' max='100'></progress>"))
|
|
90
|
+
if details.get("status") == "failed":
|
|
91
|
+
if handle_failed_event:
|
|
92
|
+
handle_failed_event()
|
|
93
|
+
raise Exception(details.get("message"))
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from typing import List, Optional, Callable
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class Validate:
|
|
6
|
+
"""Lightweight validation helpers for SDK inputs."""
|
|
7
|
+
|
|
8
|
+
@staticmethod
|
|
9
|
+
def string(field_name: str, value: str):
|
|
10
|
+
"""Ensure a non-empty string was provided for the given field.
|
|
11
|
+
|
|
12
|
+
:param field_name: Name of the field being validated.
|
|
13
|
+
:param value: Incoming string value to validate.
|
|
14
|
+
:raises Exception: If the string is empty or only whitespace.
|
|
15
|
+
"""
|
|
16
|
+
if not (value and value.strip()):
|
|
17
|
+
raise Exception(f"{field_name} is not valid, cannot be empty")
|
|
18
|
+
|
|
19
|
+
@staticmethod
|
|
20
|
+
def list(field_name: str, value: List):
|
|
21
|
+
"""Ensure a list value is provided and not empty.
|
|
22
|
+
|
|
23
|
+
:param field_name: Name of the field being validated.
|
|
24
|
+
:param value: Incoming list value to validate.
|
|
25
|
+
:raises Exception: If the list is missing or empty.
|
|
26
|
+
"""
|
|
27
|
+
if not value:
|
|
28
|
+
raise Exception(f"{field_name} is required, cannot be empty list")
|
|
29
|
+
|
|
30
|
+
@staticmethod
|
|
31
|
+
def value_against_list(
|
|
32
|
+
field_name: str,
|
|
33
|
+
value: str | List,
|
|
34
|
+
valid_list: List,
|
|
35
|
+
handle_error: Optional[Callable] = None,
|
|
36
|
+
):
|
|
37
|
+
"""Validate whether a value (or list of values) exists in a whitelist.
|
|
38
|
+
|
|
39
|
+
:param field_name: Name of the field being validated.
|
|
40
|
+
:param value: String or list of values to check.
|
|
41
|
+
:param valid_list: Allowed set of values.
|
|
42
|
+
:param handle_error: Optional callback invoked before raising an error.
|
|
43
|
+
:raises Exception: If the provided value(s) are not in the allowed list.
|
|
44
|
+
"""
|
|
45
|
+
try:
|
|
46
|
+
if isinstance(value, str):
|
|
47
|
+
if value not in valid_list:
|
|
48
|
+
raise Exception(
|
|
49
|
+
f"{value} is not valid {field_name}, select from \n{valid_list}"
|
|
50
|
+
)
|
|
51
|
+
if isinstance(value, List):
|
|
52
|
+
Validate.list(field_name, value)
|
|
53
|
+
for val in value:
|
|
54
|
+
if val not in valid_list:
|
|
55
|
+
raise Exception(
|
|
56
|
+
f"{val} is not a valid {field_name}, pick valid {field_name} from \n{valid_list}"
|
|
57
|
+
)
|
|
58
|
+
except Exception as e:
|
|
59
|
+
if handle_error:
|
|
60
|
+
handle_error()
|
|
61
|
+
raise e
|
|
62
|
+
|
|
63
|
+
@staticmethod
|
|
64
|
+
def check_for_missing_keys(value: dict, required_keys: list):
|
|
65
|
+
"""Validate that required keys are present in a dict.
|
|
66
|
+
|
|
67
|
+
:param value: Dictionary to inspect.
|
|
68
|
+
:param required_keys: Keys that must be present.
|
|
69
|
+
:raises Exception: If any required keys are missing.
|
|
70
|
+
"""
|
|
71
|
+
missing_keys = [key for key in required_keys if key not in value]
|
|
72
|
+
|
|
73
|
+
if missing_keys:
|
|
74
|
+
raise Exception(f"Keys not present: {missing_keys}")
|
|
75
|
+
|
|
76
|
+
@staticmethod
|
|
77
|
+
def validate_date_feature_val(payload: dict, all_datetime_features: List[str]):
|
|
78
|
+
"""Validate date feature payload shape and values.
|
|
79
|
+
|
|
80
|
+
:param payload: Incoming date feature payload.
|
|
81
|
+
:param all_datetime_features: Valid datetime feature names.
|
|
82
|
+
:raises Exception: If the payload is malformed or contains invalid values.
|
|
83
|
+
"""
|
|
84
|
+
if payload.get("date_feature", None):
|
|
85
|
+
if payload["date_feature"] not in all_datetime_features:
|
|
86
|
+
raise Exception(
|
|
87
|
+
f"{payload} is not a valid date_feature. Pick a valid payload from {all_datetime_features}."
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
if not payload["baseline_date"]:
|
|
91
|
+
raise Exception(
|
|
92
|
+
"baseline_date is required when date_feature is passed."
|
|
93
|
+
)
|
|
94
|
+
if not payload["current_date"]:
|
|
95
|
+
raise Exception("current_date is required when date_feature is passed.")
|
|
96
|
+
|
|
97
|
+
if (
|
|
98
|
+
payload["baseline_date"]["start_date"]
|
|
99
|
+
> payload["baseline_date"]["end_date"]
|
|
100
|
+
):
|
|
101
|
+
raise Exception(
|
|
102
|
+
"start_date of baseline_date should be less than end_date."
|
|
103
|
+
)
|
|
104
|
+
if (
|
|
105
|
+
payload["current_date"]["start_date"]
|
|
106
|
+
> payload["current_date"]["end_date"]
|
|
107
|
+
):
|
|
108
|
+
raise Exception(
|
|
109
|
+
"start_date of current_date should be less than end_date."
|
|
110
|
+
)
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
# API version
|
|
4
|
+
API_VERSION = os.getenv("XAI_API_VERSION", "v1")
|
|
5
|
+
API_VERSION_V2 = "v2"
|
|
6
|
+
|
|
7
|
+
# APP
|
|
8
|
+
XAI_APP_URI = "https://console.lexsi.ai"
|
|
9
|
+
|
|
10
|
+
# URIs of XAI base service starts here
|
|
11
|
+
# Auth
|
|
12
|
+
LOGIN_URI = f"{API_VERSION_V2}/access-token/authorize"
|
|
13
|
+
|
|
14
|
+
# User
|
|
15
|
+
GET_WORKSPACES_URI = f"{API_VERSION_V2}/users/workspaces"
|
|
16
|
+
GET_WORKSPACES_DETAILS_URI = f"{API_VERSION_V2}/project/details/workspace"
|
|
17
|
+
CREATE_WORKSPACE_URI = f"{API_VERSION_V2}/users/create_workspace"
|
|
18
|
+
|
|
19
|
+
# Custom Server
|
|
20
|
+
AVAILABLE_CUSTOM_SERVERS_URI = f"{API_VERSION_V2}/project/server_types"
|
|
21
|
+
START_CUSTOM_SERVER_URI = f"{API_VERSION_V2}/project/start_server"
|
|
22
|
+
STOP_CUSTOM_SERVER_URI = f"{API_VERSION_V2}/project/stop_server"
|
|
23
|
+
|
|
24
|
+
# Batch Server
|
|
25
|
+
AVAILABLE_BATCH_SERVERS_URI = f"{API_VERSION_V2}/users/automl_custom_servers"
|
|
26
|
+
|
|
27
|
+
# Notifications
|
|
28
|
+
GET_NOTIFICATIONS_URI = f"{API_VERSION_V2}/notifications/fetch"
|
|
29
|
+
CLEAR_NOTIFICATIONS_URI = f"{API_VERSION_V2}/notifications/clear"
|
|
30
|
+
|
|
31
|
+
# Workspace
|
|
32
|
+
UPDATE_WORKSPACE_URI = f"{API_VERSION_V2}/users/workspace_config_update"
|
|
33
|
+
CREATE_PROJECT_URI = f"{API_VERSION_V2}/users/create_project"
|
|
34
|
+
|
|
35
|
+
# Project
|
|
36
|
+
UPDATE_PROJECT_URI = f"{API_VERSION_V2}/users/project_config_update"
|
|
37
|
+
UPLOAD_DATA_FILE_URI = f"{API_VERSION_V2}/project/uploadfile_with_info"
|
|
38
|
+
UPLOAD_DATA_FILE_INFO_URI = f"{API_VERSION_V2}/project/get_Uploaded_file_info"
|
|
39
|
+
DELETE_DATA_FILE_URI = f"{API_VERSION_V2}/project/delete_data"
|
|
40
|
+
ALL_DATA_FILE_URI = f"{API_VERSION_V2}/project/get_all_uploaded_files"
|
|
41
|
+
UPLOAD_DATA_URI = f"{API_VERSION_V2}/project/upload_data"
|
|
42
|
+
UPLOAD_DATA_WITH_CHECK_URI = f"{API_VERSION_V2}/project/upload_data_with_check"
|
|
43
|
+
UPLOAD_MODEL_URI = f"{API_VERSION_V2}/project/upload_model"
|
|
44
|
+
GET_MODEL_TYPES_URI = f"{API_VERSION_V2}/project/get_model_types"
|
|
45
|
+
GET_DATA_SUMMARY_URI = f"{API_VERSION_V2}/project/data_summary"
|
|
46
|
+
GET_DATA_DIAGNOSIS_URI = f"{API_VERSION_V2}/project/get_data_diagnosis"
|
|
47
|
+
RUN_DATA_DRIFT_DIAGNOSIS_URI = f"{API_VERSION_V2}/project/run_data_drift_diagnosis"
|
|
48
|
+
GET_DATA_DRIFT_DIAGNOSIS_URI = f"{API_VERSION_V2}/project/get_data_drift_diagnosis"
|
|
49
|
+
GET_PROJECT_CONFIG = f"{API_VERSION_V2}/users/get_xai_config"
|
|
50
|
+
AVAILABLE_TAGS_URI = f"{API_VERSION_V2}/project/get_all_available_tags_info"
|
|
51
|
+
TAG_DATA_URI = f"{API_VERSION_V2}/project/tag_data"
|
|
52
|
+
GET_FEATURE_IMPORTANCE_URI = f"{API_VERSION_V2}/project/get_feature_importance"
|
|
53
|
+
|
|
54
|
+
# Monitoring
|
|
55
|
+
GENERATE_DASHBOARD_URI = f"{API_VERSION_V2}/dashboards/generate_dashboard"
|
|
56
|
+
DASHBOARD_CONFIG_URI = f"{API_VERSION_V2}/dashboards/config"
|
|
57
|
+
MODEL_PERFORMANCE_DASHBOARD_URI = (
|
|
58
|
+
f"{API_VERSION_V2}/dashboards/model_performance_dashboard"
|
|
59
|
+
)
|
|
60
|
+
DASHBOARD_LOGS_URI = f"{API_VERSION_V2}/dashboards/get_dashboard_logs"
|
|
61
|
+
GET_DASHBOARD_URI = f"{API_VERSION_V2}/dashboards/get_dashboard"
|
|
62
|
+
DOWNLOAD_DASHBOARD_LOGS_URI = f"{API_VERSION_V2}/dashboards/download_dashboard_logs"
|
|
63
|
+
GET_DASHBOARD_SCORE_URI = f"{API_VERSION_V2}/dashboards/get_dashboard_score"
|
|
64
|
+
|
|
65
|
+
# Auto ML
|
|
66
|
+
MODEL_PARAMETERS_URI = f"{API_VERSION_V2}/users/get_xai_model_parameters"
|
|
67
|
+
TRAIN_MODEL_URI = f"{API_VERSION_V2}/users/xai_config_update"
|
|
68
|
+
GET_MODELS_URI = f"{API_VERSION_V2}/ai-models/get_all_models"
|
|
69
|
+
UPDATE_ACTIVE_MODEL_URI = f"{API_VERSION_V2}/ai-models/update_active_model"
|
|
70
|
+
UPDATE_ACTIVE_INFERENCE_MODEL_URI = (
|
|
71
|
+
f"{API_VERSION_V2}/ai-models/update_active_inference"
|
|
72
|
+
)
|
|
73
|
+
REMOVE_MODEL_URI = f"{API_VERSION_V2}/ai-models/remove_model"
|
|
74
|
+
RUN_MODEL_ON_DATA_URI = f"{API_VERSION_V2}/ai-models/run_model_on_data"
|
|
75
|
+
DOWNLOAD_TAG_DATA_URI = f"{API_VERSION_V2}/ai-models/download_tag_data"
|
|
76
|
+
MODEL_SUMMARY_URI = f"{API_VERSION_V2}/project/get_model_perfermance"
|
|
77
|
+
PROJECT_OVERVIEW_TEXT_URI = f"{API_VERSION_V2}/ai-models/project_overview"
|
|
78
|
+
MODEL_SVG_URI = f"{API_VERSION_V2}/project/get_model_svg_plot"
|
|
79
|
+
MODEL_INFERENCES_URI = f"{API_VERSION_V2}/ai-models/get_all_tags_for_models"
|
|
80
|
+
UPLOAD_DATA_PROJECT_URI = f"{API_VERSION_V2}/project/case-register"
|
|
81
|
+
GET_CASE_PROFILE_URI = f"{API_VERSION_V2}/project/get-case-profile"
|
|
82
|
+
|
|
83
|
+
# Explainability
|
|
84
|
+
GET_CASES_URI = f"{API_VERSION_V2}/ai-models/get_cases"
|
|
85
|
+
SEARCH_CASE_URI = f"{API_VERSION_V2}/ai-models/search_case"
|
|
86
|
+
CASE_INFO_URI = f"{API_VERSION_V2}/ai-models/get_case_info_components"
|
|
87
|
+
CASE_INFO_TEXT_URI = f"{API_VERSION_V2}/ai-models/get_case_info_text"
|
|
88
|
+
CASE_DTREE_URI = f"{API_VERSION_V2}/ai-models/get_case_dtree"
|
|
89
|
+
DELETE_CASE_URI = f"{API_VERSION_V2}/project/delete_data_with_filter"
|
|
90
|
+
CASE_LOGS_URI = f"{API_VERSION_V2}/ai-models/explainability_logs"
|
|
91
|
+
CASE_LOGS_TEXT_URI = f"{API_VERSION_V2}/ai-models/explainability_logs_text"
|
|
92
|
+
GET_VIEWED_CASE_URI = f"{API_VERSION_V2}/ai-models/get_viewed_case"
|
|
93
|
+
GENERATE_TEXT_CASE_URI = f"{API_VERSION_V2}/ai-models/run_model_on_data_text"
|
|
94
|
+
GENERATE_TEXT_CASE_STREAM_URI = f"{API_VERSION_V2}/ai-models/run_model_on_data_text_stream"
|
|
95
|
+
|
|
96
|
+
# Observations
|
|
97
|
+
GET_OBSERVATIONS_URI = f"{API_VERSION_V2}/observations/get_observations"
|
|
98
|
+
GET_OBSERVATION_PARAMS_URI = f"{API_VERSION_V2}/observations/get_observation_params"
|
|
99
|
+
CREATE_OBSERVATION_URI = f"{API_VERSION_V2}/observations/create_observation"
|
|
100
|
+
UPDATE_OBSERVATION_URI = f"{API_VERSION_V2}/observations/observation_config_update"
|
|
101
|
+
DUPLICATE_OBSERVATION_URI = f"{API_VERSION_V2}/observations/duplicate_observation"
|
|
102
|
+
|
|
103
|
+
# Policies
|
|
104
|
+
GET_POLICIES_URI = f"{API_VERSION_V2}/policies/get_policies"
|
|
105
|
+
GET_POLICY_PARAMS_URI = f"{API_VERSION_V2}/policies/get_policy_params"
|
|
106
|
+
CREATE_POLICY_URI = f"{API_VERSION_V2}/policies/create_policy"
|
|
107
|
+
UPDATE_POLICY_URI = f"{API_VERSION_V2}/policies/policy_config_update"
|
|
108
|
+
VALIDATE_POLICY_URI = f"{API_VERSION_V2}/policies/validate_policy"
|
|
109
|
+
DUPLICATE_POLICY_URI = f"{API_VERSION_V2}/policies/duplicate_policy"
|
|
110
|
+
|
|
111
|
+
# Alerts
|
|
112
|
+
GET_TRIGGERS_URI = f"{API_VERSION_V2}/triggers/get_triggers"
|
|
113
|
+
CREATE_TRIGGER_URI = f"{API_VERSION_V2}/triggers/update_triggers"
|
|
114
|
+
DELETE_TRIGGER_URI = f"{API_VERSION_V2}/triggers/update_triggers"
|
|
115
|
+
DUPLICATE_MONITORS_URI = f"{API_VERSION_V2}/triggers/duplicate_monitors"
|
|
116
|
+
EXECUTED_TRIGGER_URI = f"{API_VERSION_V2}/triggers/get_executed_triggers"
|
|
117
|
+
GET_EXECUTED_TRIGGER_INFO = f"{API_VERSION_V2}/triggers/get_trigger_details"
|
|
118
|
+
GET_LABELS_URI = f"{API_VERSION_V2}/triggers/get_label_classes"
|
|
119
|
+
GET_TRIGGERS_DAYS_URI = f"{API_VERSION_V2}/triggers/get_alerts"
|
|
120
|
+
GET_MONITORS_ALERTS = f"{API_VERSION_V2}/triggers/get_monitors_alerts"
|
|
121
|
+
|
|
122
|
+
# Synthetic AI
|
|
123
|
+
AVAILABLE_SYNTHETIC_CUSTOM_SERVERS_URI = f"{API_VERSION_V2}/synthetics/custom_servers"
|
|
124
|
+
GET_SYNTHETIC_MODEL_PARAMS_URI = (
|
|
125
|
+
f"{API_VERSION_V2}/synthetics/get_synthetic_model_parameters"
|
|
126
|
+
)
|
|
127
|
+
TRAIN_SYNTHETIC_MODEL_URI = f"{API_VERSION_V2}/synthetics/train_synthetic_model"
|
|
128
|
+
GET_SYNTHETIC_MODELS_URI = f"{API_VERSION_V2}/synthetics/get_synthetics_models"
|
|
129
|
+
DELETE_SYNTHETIC_MODEL_URI = f"{API_VERSION_V2}/synthetics/delete_synthetic_model"
|
|
130
|
+
GET_SYNTHETIC_MODEL_DETAILS_URI = (
|
|
131
|
+
f"{API_VERSION_V2}/synthetics/get_synthetic_model_details"
|
|
132
|
+
)
|
|
133
|
+
GENERATE_SYNTHETIC_DATA_URI = f"{API_VERSION_V2}/synthetics/generate_synthetic_data"
|
|
134
|
+
GENERATE_ANONYMITY_SCORE_URI = f"{API_VERSION_V2}/synthetics/generate_anonimity_score"
|
|
135
|
+
GET_ANONYMITY_SCORE_URI = f"{API_VERSION_V2}/synthetics/get_anonimity_score"
|
|
136
|
+
|
|
137
|
+
GET_SYNTHETIC_DATA_TAGS_URI = f"{API_VERSION_V2}/synthetics/get_synthetic_data_tags"
|
|
138
|
+
DOWNLOAD_SYNTHETIC_DATA_URI = f"{API_VERSION_V2}/synthetics/download_synthetic_data"
|
|
139
|
+
DELETE_SYNTHETIC_TAG_URI = f"{API_VERSION_V2}/project/delete_data_with_filter"
|
|
140
|
+
|
|
141
|
+
CREATE_SYNTHETIC_PROMPT_URI = f"{API_VERSION_V2}/synthetics/create_synthetic_prompts"
|
|
142
|
+
UPDATE_SYNTHETIC_PROMPT_URI = f"{API_VERSION_V2}/synthetics/synthetic_prompts_update"
|
|
143
|
+
GET_SYNTHETIC_PROMPT_URI = f"{API_VERSION_V2}/synthetics/get_synthetics_promts"
|
|
144
|
+
|
|
145
|
+
# Events
|
|
146
|
+
POLL_EVENTS = f"{API_VERSION_V2}/events/poll"
|
|
147
|
+
FETCH_EVENTS = f"{API_VERSION_V2}/events/fetch"
|
|
148
|
+
|
|
149
|
+
# Organization
|
|
150
|
+
USER_ORGANIZATION_URI = f"{API_VERSION_V2}/organization/user_organization"
|
|
151
|
+
CREATE_ORGANIZATION_URI = f"{API_VERSION_V2}/organization/create_organization"
|
|
152
|
+
INVITE_USER_ORGANIZATION_URI = f"{API_VERSION_V2}/organization/invite_user"
|
|
153
|
+
REMOVE_USER_ORGANIZATION_URI = f"{API_VERSION_V2}/organization/organization_user_delete"
|
|
154
|
+
ORGANIZATION_MEMBERS_URI = f"{API_VERSION_V2}/organization/organization_users"
|
|
155
|
+
UPDATE_ORGANIZATION_URI = f"{API_VERSION_V2}/organization/organization_user_update"
|
|
156
|
+
|
|
157
|
+
# Data Connectors
|
|
158
|
+
CREATE_DATA_CONNECTORS = f"{API_VERSION_V2}/linkservices/create"
|
|
159
|
+
TEST_DATA_CONNECTORS = f"{API_VERSION_V2}/linkservices/test_connection"
|
|
160
|
+
LIST_BUCKETS = f"{API_VERSION_V2}/linkservices/list_buckets"
|
|
161
|
+
LIST_FILEPATHS = f"{API_VERSION_V2}/linkservices/list_filepath"
|
|
162
|
+
LIST_DATA_CONNECTORS = f"{API_VERSION_V2}/linkservices/list"
|
|
163
|
+
DELETE_DATA_CONNECTORS = f"{API_VERSION_V2}/linkservices/delete"
|
|
164
|
+
UPLOAD_FILE_DATA_CONNECTORS = f"{API_VERSION_V2}/project/uploadfile_with_linkservices"
|
|
165
|
+
DROPBOX_OAUTH = f"{API_VERSION_V2}/linkservices/dropbox_auth"
|
|
166
|
+
|
|
167
|
+
# Credits
|
|
168
|
+
COMPUTE_CREDIT_URI = f"{API_VERSION_V2}/plans/compute_credit"
|
|
169
|
+
|
|
170
|
+
# evals
|
|
171
|
+
TABULAR_ML = f"{API_VERSION_V2}/evals/evals-tabular"
|
|
172
|
+
TABULAR_DL = f"{API_VERSION_V2}/evals/evals-tabular"
|
|
173
|
+
IMAGE_DL = f"{API_VERSION_V2}/evals/"
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
# Agents
|
|
177
|
+
EXPLAINABILITY_SUMMARY = f"{API_VERSION_V2}/agents/explainability_summary"
|
|
178
|
+
|
|
179
|
+
#Text
|
|
180
|
+
MESSAGES_URI = f"sessions/get_session_messages"
|
|
181
|
+
SESSIONS_URI = f"sessions/get_sessions"
|
|
182
|
+
TRACES_URI = f"traces/get_traces"
|
|
183
|
+
GET_GUARDRAILS_URI = f"guardrails/active_guardrails"
|
|
184
|
+
UPDATE_GUARDRAILS_STATUS_URI = f"guardrails/update_guardrail_status"
|
|
185
|
+
DELETE_GUARDRAILS_URI = f"guardrails/delete_guardrail"
|
|
186
|
+
AVAILABLE_GUARDRAILS_URI = f"guardrails/all"
|
|
187
|
+
CONFIGURE_GUARDRAILS_URI = f"guardrails/configure"
|
|
188
|
+
RUN_GUARDRAILS_URI=f"guardrails/run_guardrail"
|
|
189
|
+
GET_AVAILABLE_TEXT_MODELS_URI = f"{API_VERSION_V2}/users/get_available_text_models"
|
|
190
|
+
QUANTIZE_MODELS_URI = f"{API_VERSION_V2}/ai-models/run_quantization_on_model"
|
|
191
|
+
INITIALIZE_TEXT_MODEL_URI = f"{API_VERSION_V2}/users/initalize_text_model"
|
|
192
|
+
TEXT_MODEL_INFERENCE_SETTINGS_URI = f"{API_VERSION_V2}/ai-models/update_inference_settings"
|
|
193
|
+
RUN_GUARDRAILS_PARALLEL_URI=f"guardrails/run_guardrail_parallel"
|
|
194
|
+
RUN_CHAT_COMPLETION = f"gateway/v1/chat/completions"
|
|
195
|
+
RUN_IMAGE_GENERATION = f"gateway/v1/images/generations"
|
|
196
|
+
RUN_CREATE_EMBEDDING = f"gateway/v1/embeddings"
|
|
197
|
+
RUN_COMPLETION = f"gateway/v1/completions"
|
|
File without changes
|
lexsi_sdk/core/agent.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
from lexsi_sdk.common.xai_uris import (
|
|
2
|
+
AVAILABLE_GUARDRAILS_URI,
|
|
3
|
+
CONFIGURE_GUARDRAILS_URI,
|
|
4
|
+
DELETE_GUARDRAILS_URI,
|
|
5
|
+
GET_AVAILABLE_TEXT_MODELS_URI,
|
|
6
|
+
GET_GUARDRAILS_URI,
|
|
7
|
+
INITIALIZE_TEXT_MODEL_URI,
|
|
8
|
+
MESSAGES_URI,
|
|
9
|
+
SESSIONS_URI,
|
|
10
|
+
TRACES_URI,
|
|
11
|
+
UPDATE_GUARDRAILS_STATUS_URI,
|
|
12
|
+
)
|
|
13
|
+
from lexsi_sdk.core.project import Project
|
|
14
|
+
import pandas as pd
|
|
15
|
+
|
|
16
|
+
from lexsi_sdk.core.wrapper import monitor
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class AgentProject(Project):
|
|
20
|
+
"""Project for Agent modality
|
|
21
|
+
|
|
22
|
+
:return: AgentProject
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
def sessions(self) -> pd.DataFrame:
|
|
26
|
+
"""All sessions
|
|
27
|
+
|
|
28
|
+
:return: response
|
|
29
|
+
"""
|
|
30
|
+
res = self.api_client.get(f"{SESSIONS_URI}?project_name={self.project_name}")
|
|
31
|
+
if not res["success"]:
|
|
32
|
+
raise Exception(res.get("details"))
|
|
33
|
+
|
|
34
|
+
return pd.DataFrame(res.get("details"))
|
|
35
|
+
|
|
36
|
+
def messages(self, session_id: str) -> pd.DataFrame:
|
|
37
|
+
"""All messages for a session
|
|
38
|
+
|
|
39
|
+
:param session_id: id of the session
|
|
40
|
+
:return: response
|
|
41
|
+
"""
|
|
42
|
+
res = self.api_client.get(
|
|
43
|
+
f"{MESSAGES_URI}?project_name={self.project_name}&session_id={session_id}"
|
|
44
|
+
)
|
|
45
|
+
if not res["success"]:
|
|
46
|
+
raise Exception(res.get("details"))
|
|
47
|
+
|
|
48
|
+
return pd.DataFrame(res.get("details"))
|
|
49
|
+
|
|
50
|
+
def traces(self, trace_id: str) -> pd.DataFrame:
|
|
51
|
+
"""Traces generated for trace_id
|
|
52
|
+
|
|
53
|
+
:param trace_id: id of the trace
|
|
54
|
+
:return: response
|
|
55
|
+
"""
|
|
56
|
+
res = self.api_client.get(
|
|
57
|
+
f"{TRACES_URI}?project_name={self.project_name}&trace_id={trace_id}"
|
|
58
|
+
)
|
|
59
|
+
if not res["success"]:
|
|
60
|
+
raise Exception(res.get("details"))
|
|
61
|
+
|
|
62
|
+
return pd.DataFrame(res.get("details"))
|
lexsi_sdk/core/alert.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
from typing import List, Optional
|
|
2
|
+
from pydantic import BaseModel
|
|
3
|
+
import pandas as pd
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Alert(BaseModel):
|
|
7
|
+
"""Represents a monitoring alert and helper views."""
|
|
8
|
+
info: dict
|
|
9
|
+
detailed_report: Optional[List[dict] | dict] = None
|
|
10
|
+
not_used_features: Optional[List[dict]] = None
|
|
11
|
+
|
|
12
|
+
def __init__(self, **kwargs):
|
|
13
|
+
"""Initialize base model without extra behavior."""
|
|
14
|
+
super().__init__(**kwargs)
|
|
15
|
+
|
|
16
|
+
def view_info(self) -> pd.DataFrame:
|
|
17
|
+
"""view the alert info
|
|
18
|
+
|
|
19
|
+
:return: _description_
|
|
20
|
+
"""
|
|
21
|
+
if not self.info:
|
|
22
|
+
return "There was an error while executing the alert."
|
|
23
|
+
|
|
24
|
+
return pd.DataFrame([self.info])
|
|
25
|
+
|
|
26
|
+
def view_detailed_report(self) -> pd.DataFrame:
|
|
27
|
+
"""view the detailed report of alert
|
|
28
|
+
|
|
29
|
+
:return: _description_
|
|
30
|
+
"""
|
|
31
|
+
if not self.detailed_report:
|
|
32
|
+
return "No detailed report found for the alert."
|
|
33
|
+
|
|
34
|
+
if isinstance(self.detailed_report, list):
|
|
35
|
+
detailed_report = [
|
|
36
|
+
{
|
|
37
|
+
key: value
|
|
38
|
+
for key, value in feature.items()
|
|
39
|
+
if key != "current_small_hist" and key != "ref_small_hist"
|
|
40
|
+
}
|
|
41
|
+
for feature in self.detailed_report
|
|
42
|
+
]
|
|
43
|
+
if isinstance(self.detailed_report, dict):
|
|
44
|
+
detailed_report = [self.detailed_report]
|
|
45
|
+
|
|
46
|
+
return pd.DataFrame(detailed_report)
|
|
47
|
+
|
|
48
|
+
def view_not_used_features(self) -> pd.DataFrame:
|
|
49
|
+
"""view the not used features of alert
|
|
50
|
+
|
|
51
|
+
:return: _description_
|
|
52
|
+
"""
|
|
53
|
+
if not self.not_used_features:
|
|
54
|
+
return "Not used features is empty."
|
|
55
|
+
|
|
56
|
+
return pd.DataFrame(self.not_used_features)
|