Spaces:
Running
Running
geekyrakshit
commited on
Commit
•
36c3c0f
1
Parent(s):
a323dd9
add: docs for utils
Browse files- docs/utils.md +3 -0
- guardrails_genie/utils.py +46 -0
- mkdocs.yml +1 -0
docs/utils.md
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# Utils
|
2 |
+
|
3 |
+
::: guardrails_genie.utils
|
guardrails_genie/utils.py
CHANGED
@@ -16,6 +16,20 @@ def get_markdown_from_pdf_url(url: str) -> str:
|
|
16 |
|
17 |
|
18 |
class EvaluationCallManager:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
def __init__(self, entity: str, project: str, call_id: str, max_count: int = 10):
|
20 |
self.base_call = weave.init(f"{entity}/{project}").get_call(call_id=call_id)
|
21 |
self.max_count = max_count
|
@@ -23,6 +37,21 @@ class EvaluationCallManager:
|
|
23 |
self.call_list = []
|
24 |
|
25 |
def collect_guardrail_guard_calls_from_eval(self):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
guard_calls, count = [], 0
|
27 |
for eval_predict_and_score_call in self.base_call.children():
|
28 |
if "Evaluation.summarize" in eval_predict_and_score_call._op_name:
|
@@ -44,6 +73,23 @@ class EvaluationCallManager:
|
|
44 |
return guard_calls
|
45 |
|
46 |
def render_calls_to_streamlit(self):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
dataframe = {
|
48 |
"input_prompt": [
|
49 |
call["input_prompt"] for call in self.call_list[0]["calls"]
|
|
|
16 |
|
17 |
|
18 |
class EvaluationCallManager:
|
19 |
+
"""
|
20 |
+
Manages the evaluation calls for a specific project and entity in Weave.
|
21 |
+
|
22 |
+
This class is responsible for initializing and managing evaluation calls associated with a
|
23 |
+
specific project and entity. It provides functionality to collect guardrail guard calls
|
24 |
+
from evaluation predictions and scores, and render these calls into a structured format
|
25 |
+
suitable for display in Streamlit.
|
26 |
+
|
27 |
+
Args:
|
28 |
+
entity (str): The entity name.
|
29 |
+
project (str): The project name.
|
30 |
+
call_id (str): The call id.
|
31 |
+
max_count (int): The maximum number of guardrail guard calls to collect from the evaluation.
|
32 |
+
"""
|
33 |
def __init__(self, entity: str, project: str, call_id: str, max_count: int = 10):
|
34 |
self.base_call = weave.init(f"{entity}/{project}").get_call(call_id=call_id)
|
35 |
self.max_count = max_count
|
|
|
37 |
self.call_list = []
|
38 |
|
39 |
def collect_guardrail_guard_calls_from_eval(self):
|
40 |
+
"""
|
41 |
+
Collects guardrail guard calls from evaluation predictions and scores.
|
42 |
+
|
43 |
+
This function iterates through the children calls of the base evaluation call,
|
44 |
+
extracting relevant guardrail guard calls and their associated scores. It stops
|
45 |
+
collecting calls if it encounters an "Evaluation.summarize" operation or if the
|
46 |
+
maximum count of guardrail guard calls is reached. The collected calls are stored
|
47 |
+
in a list of dictionaries, each containing the input prompt, outputs, and score.
|
48 |
+
|
49 |
+
Returns:
|
50 |
+
list: A list of dictionaries, each containing:
|
51 |
+
- input_prompt (str): The input prompt for the guard call.
|
52 |
+
- outputs (dict): The outputs of the guard call.
|
53 |
+
- score (dict): The score of the guard call.
|
54 |
+
"""
|
55 |
guard_calls, count = [], 0
|
56 |
for eval_predict_and_score_call in self.base_call.children():
|
57 |
if "Evaluation.summarize" in eval_predict_and_score_call._op_name:
|
|
|
73 |
return guard_calls
|
74 |
|
75 |
def render_calls_to_streamlit(self):
|
76 |
+
"""
|
77 |
+
Renders the collected guardrail guard calls into a pandas DataFrame suitable for
|
78 |
+
display in Streamlit.
|
79 |
+
|
80 |
+
This function processes the collected guardrail guard calls stored in `self.call_list` and
|
81 |
+
organizes them into a dictionary format that can be easily converted into a pandas DataFrame.
|
82 |
+
The DataFrame contains columns for the input prompts, the safety status of the outputs, and
|
83 |
+
the correctness of the predictions for each guardrail.
|
84 |
+
|
85 |
+
The structure of the DataFrame is as follows:
|
86 |
+
- The first column contains the input prompts.
|
87 |
+
- Subsequent columns contain the safety status and prediction correctness for each guardrail.
|
88 |
+
|
89 |
+
Returns:
|
90 |
+
pd.DataFrame: A DataFrame containing the input prompts, safety status, and prediction
|
91 |
+
correctness for each guardrail.
|
92 |
+
"""
|
93 |
dataframe = {
|
94 |
"input_prompt": [
|
95 |
call["input_prompt"] for call in self.call_list[0]["calls"]
|
mkdocs.yml
CHANGED
@@ -59,5 +59,6 @@ extra_javascript:
|
|
59 |
|
60 |
nav:
|
61 |
- Home: 'index.md'
|
|
|
62 |
|
63 |
repo_url: https://github.com/soumik12345/guardrails-genie
|
|
|
59 |
|
60 |
nav:
|
61 |
- Home: 'index.md'
|
62 |
+
- Utils: 'utils.md'
|
63 |
|
64 |
repo_url: https://github.com/soumik12345/guardrails-genie
|