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

Feat/api keys from attributes #415

Merged
merged 7 commits into from
Apr 26, 2023
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
25 changes: 19 additions & 6 deletions skills/dff_template_prompted_skill/scenario/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@
ALLOW_PROMPT_RESET = int(getenv("ALLOW_PROMPT_RESET", 0))
ENVVARS_TO_SEND = getenv("ENVVARS_TO_SEND", None)
ENVVARS_TO_SEND = [] if ENVVARS_TO_SEND is None else ENVVARS_TO_SEND.split(",")
sending_variables = {f"{var}_list": [getenv(var, None)] for var in ENVVARS_TO_SEND}
# check if at least one of the env variables is not None
if len(sending_variables.keys()) > 0 and all([var_value is None for var_value in sending_variables.values()]):
raise NotImplementedError(
"ERROR: All environmental variables have None values. At least one of the variables must have not None value"
)

assert GENERATIVE_SERVICE_URL
assert PROMPT_FILE
Expand Down Expand Up @@ -68,6 +62,13 @@ def compose_data_for_model(ctx, actor):
return context


def if_none_var_values(sending_variables):
if len(sending_variables.keys()) > 0 and all([var_value[0] is None for var_value in sending_variables.values()]):
return True
else:
False


def generative_response(ctx: Context, actor: Actor, *args, **kwargs) -> Any:
curr_responses, curr_confidences, curr_human_attrs, curr_bot_attrs, curr_attrs = (
[],
Expand All @@ -87,6 +88,18 @@ def gathering_responses(reply, confidence, human_attr, bot_attr, attr):
curr_attrs += [attr]

dialog_context = compose_data_for_model(ctx, actor)
# get variables which names are in `ENVVARS_TO_SEND` (splitted by comma if many)
# from user_utterance attributes or from environment
human_uttr_attributes = int_ctx.get_last_human_utterance(ctx, actor).get("attributes", {})
sending_variables = {f"{var}_list": [human_uttr_attributes.get(var.lower(), None)] for var in ENVVARS_TO_SEND}
if if_none_var_values(sending_variables):
sending_variables = {f"{var}_list": [getenv(var, None)] for var in ENVVARS_TO_SEND}
if if_none_var_values(sending_variables):
logger.info(f"Did not get {ENVVARS_TO_SEND}'s values. Sending without them.")
else:
logger.info(f"Got {ENVVARS_TO_SEND}'s values from environment.")
else:
logger.info(f"Got {ENVVARS_TO_SEND}'s values from attributes.")

shared_memory = int_ctx.get_shared_memory(ctx, actor)
prompt = shared_memory.get("prompt", "")
Expand Down
11 changes: 11 additions & 0 deletions state_formatters/dp_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,7 @@ def dff_ai_faq_prompted_skill_formatter(dialog):
"dff_ai_faq_prompted_skill",
bot_last_turns=5,
types_utterances=["human_utterances", "bot_utterances", "utterances"],
wanted_keys=["text", "annotations", "active_skill", "user", "attributes"],
)


Expand All @@ -1021,6 +1022,7 @@ def dff_fashion_stylist_prompted_skill_formatter(dialog):
"dff_fashion_stylist_prompted_skill",
bot_last_turns=5,
types_utterances=["human_utterances", "bot_utterances", "utterances"],
wanted_keys=["text", "annotations", "active_skill", "user", "attributes"],
)


Expand All @@ -1030,6 +1032,7 @@ def dff_dream_persona_prompted_skill_formatter(dialog):
"dff_dream_persona_prompted_skill",
bot_last_turns=5,
types_utterances=["human_utterances", "bot_utterances", "utterances"],
wanted_keys=["text", "annotations", "active_skill", "user", "attributes"],
)


Expand All @@ -1039,6 +1042,7 @@ def dff_dream_persona_ru_prompted_skill_formatter(dialog):
"dff_dream_persona_ru_prompted_skill",
bot_last_turns=5,
types_utterances=["human_utterances", "bot_utterances", "utterances"],
wanted_keys=["text", "annotations", "active_skill", "user", "attributes"],
)


Expand All @@ -1048,6 +1052,7 @@ def dff_marketing_prompted_skill_formatter(dialog):
"dff_marketing_prompted_skill",
bot_last_turns=5,
types_utterances=["human_utterances", "bot_utterances", "utterances"],
wanted_keys=["text", "annotations", "active_skill", "user", "attributes"],
)


Expand All @@ -1057,6 +1062,7 @@ def dff_fairytale_prompted_skill_formatter(dialog):
"dff_fairytale_prompted_skill",
bot_last_turns=5,
types_utterances=["human_utterances", "bot_utterances", "utterances"],
wanted_keys=["text", "annotations", "active_skill", "user", "attributes"],
)


Expand All @@ -1066,6 +1072,7 @@ def dff_nutrition_prompted_skill_formatter(dialog):
"dff_nutrition_prompted_skill",
bot_last_turns=5,
types_utterances=["human_utterances", "bot_utterances", "utterances"],
wanted_keys=["text", "annotations", "active_skill", "user", "attributes"],
)


Expand All @@ -1075,6 +1082,7 @@ def dff_life_coaching_prompted_skill_formatter(dialog):
"dff_life_coaching_prompted_skill",
bot_last_turns=5,
types_utterances=["human_utterances", "bot_utterances", "utterances"],
wanted_keys=["text", "annotations", "active_skill", "user", "attributes"],
)


Expand All @@ -1084,6 +1092,7 @@ def dff_deepy_prompted_skill_formatter(dialog):
"dff_deepy_prompted_skill",
bot_last_turns=5,
types_utterances=["human_utterances", "bot_utterances", "utterances"],
wanted_keys=["text", "annotations", "active_skill", "user", "attributes"],
)


Expand All @@ -1092,6 +1101,7 @@ def dff_deeppavlov_prompted_skill_formatter(dialog):
dialog,
"dff_deeppavlov_prompted_skill",
types_utterances=["human_utterances", "bot_utterances", "utterances"],
wanted_keys=["text", "annotations", "active_skill", "user", "attributes"],
)


Expand All @@ -1101,6 +1111,7 @@ def dff_prompted_skill_formatter(dialog, skill_name=None):
skill_name,
bot_last_turns=5,
types_utterances=["human_utterances", "bot_utterances", "utterances"],
wanted_keys=["text", "annotations", "active_skill", "user", "attributes"],
)


Expand Down