diff --git a/setup.py b/setup.py index 4816e697..3224edce 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ setup( name='dfcx-scrapi', - version='1.12.4', + version='1.12.5', description='A high level scripting API for bot builders, developers, and\ maintainers.', long_description=long_description, diff --git a/src/dfcx_scrapi/core/agents.py b/src/dfcx_scrapi/core/agents.py index b9030aed..5ce3e057 100644 --- a/src/dfcx_scrapi/core/agents.py +++ b/src/dfcx_scrapi/core/agents.py @@ -41,6 +41,7 @@ def __init__( creds=None, scope=False, agent_id: str = None, + language_code: str = "en" ): super().__init__( creds_path=creds_path, @@ -53,6 +54,8 @@ def __init__( self.agent_id = agent_id self.client_options = self._set_region(agent_id) + self.langauge_code = language_code + @scrapi_base.api_call_counter_decorator def _list_agents_client_request(self, location_id) -> List[ types.agent.Agent diff --git a/src/dfcx_scrapi/core/intents.py b/src/dfcx_scrapi/core/intents.py index de1b0cf7..ef0d4a70 100644 --- a/src/dfcx_scrapi/core/intents.py +++ b/src/dfcx_scrapi/core/intents.py @@ -44,6 +44,7 @@ def __init__( scope=False, intent_id: str = None, agent_id: str = None, + language_code: str = "en" ): super().__init__( creds_path=creds_path, @@ -59,6 +60,8 @@ def __init__( if agent_id: self.agent_id = agent_id + self.language_code = language_code + @staticmethod def concat_dict_and_df( intent_df: pd.DataFrame, diff --git a/src/dfcx_scrapi/tools/nlu_evals.py b/src/dfcx_scrapi/tools/nlu_evals.py index 5d106747..3bcc1c3c 100644 --- a/src/dfcx_scrapi/tools/nlu_evals.py +++ b/src/dfcx_scrapi/tools/nlu_evals.py @@ -24,9 +24,6 @@ from dfcx_scrapi.core import scrapi_base from dfcx_scrapi.core import agents -from dfcx_scrapi.core import flows -from dfcx_scrapi.core import pages -from dfcx_scrapi.core import intents from dfcx_scrapi.core import conversation from dfcx_scrapi.tools import dataframe_functions @@ -99,6 +96,7 @@ def __init__( creds_path: str = None, creds_dict: Dict[str, str] = None, creds=None, + language_code: str = "en" ): super().__init__( @@ -111,15 +109,24 @@ def __init__( self.agent_id = agent_id self._sheets_client = self._build_sheets_client() - self._a = agents.Agents(creds=self.creds) - self._i = intents.Intents(creds=self.creds) - self._f = flows.Flows(creds=self.creds) - self._p = pages.Pages(creds=self.creds) + self._a = agents.Agents(creds=self.creds, language_code=language_code) self._dc = conversation.DialogflowConversation( - creds_path=creds_path, agent_id=agent_id + creds_path=creds_path, agent_id=agent_id, + language_code=language_code ) self._dffx = dataframe_functions.DataframeFunctions(creds=self.creds) + def get_agent_type(self, agent_id: str): + """Return the Agent type for logging purposes.""" + agent = self._a.get_agent(agent_id) + + if agent.start_flow: + return "flow" + elif agent.start_playbook: + return "generative" + else: + raise ValueError("Could not determine Agent type.") + def _build_sheets_client(self): client = gspread.authorize(self.creds) @@ -233,6 +240,16 @@ def run_evals(self, df: pd.DataFrame, chunk_size: int = 300, """Run the full Eval dataset.""" logsx = "-" * 10 + agent_type = self.get_agent_type(self.agent_id) + warnx = "!" * 10 + if agent_type == "generative": + msg = f"{warnx} Agent Type is GENERATIVE {warnx} \nThis specific"\ + " class, NluEvals, is optimized for load testing standard"\ + " Dialogflow CX Flow based Agents with Intents.\nIf you wish"\ + " to evaluate a Generative Agent, please use"\ + " dfcx_scrapi.tools.evaluations.Evaluations instead.\n" + logging.warning(msg) + logging.info(f"{logsx} STARTING {eval_run_display_name} {logsx}") results = self._dc.run_intent_detection( test_set=df, chunk_size=chunk_size, rate_limit=rate_limit