Skip to content

Commit

Permalink
Merge branch 'GoogleCloudPlatform:main' into tidy-example-notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanknights authored Nov 5, 2024
2 parents 951431c + 3189a7c commit ac5fa2d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/dfcx_scrapi/core/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __init__(
creds=None,
scope=False,
agent_id: str = None,
language_code: str = "en"
):
super().__init__(
creds_path=creds_path,
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/dfcx_scrapi/core/intents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
33 changes: 25 additions & 8 deletions src/dfcx_scrapi/tools/nlu_evals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -99,6 +96,7 @@ def __init__(
creds_path: str = None,
creds_dict: Dict[str, str] = None,
creds=None,
language_code: str = "en"
):

super().__init__(
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ac5fa2d

Please sign in to comment.