Skip to content
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

Adding session parameters to evaluations function #262

Merged
merged 4 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/dfcx_scrapi/core/scrapi_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,14 @@ def dict_to_struct(some_dict: Dict[str, Any]):

return new_struct

@staticmethod
def str_to_dict(some_str: str) -> Dict[str, Any]:
"""Safe convert str to Dict or fail."""
try:
return json.loads(some_str)
except json.JSONDecodeError as err:
raise ValueError(f"Invalid JSON string: `{some_str}`") from err

@staticmethod
def parse_agent_id(resource_id: str):
"""Attempts to parse Agent ID from provided Resource ID."""
Expand Down
14 changes: 11 additions & 3 deletions src/dfcx_scrapi/tools/evaluations.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,16 @@ def run_detect_intent_queries(self, df: pd.DataFrame) -> pd.DataFrame:
if row["action_type"] != "User Utterance":
continue

res = self.sessions_client.detect_intent(
self.agent_id, self.session_id, row["action_input"]
session_parameters = None

if "session_parameters" in row:
session_parameters = self.str_to_dict(row["session_parameters"])

res = self.s.detect_intent(
agent_id=self.agent_id,
session_id=self.session_id,
text=row["action_input"],
parameters=session_parameters
)

# Add data to the existing row
Expand Down Expand Up @@ -768,7 +776,7 @@ def convert_column_types(self, df: pd.DataFrame) -> pd.DataFrame:
"""Convert column types as needed."""
STR_COLUMNS = [
"eval_id", "action_type", "action_input", "action_input_parameters",
"tool_action", "notes"
"tool_action", "notes", "session_parameters"
]

for col in df.columns:
Expand Down