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: universal dist requires api keys in request #425

Merged
merged 1 commit 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
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ services:
memory: 100M

dff-universal-prompted-skill:
env_file: [ .env,.env_secret ]
env_file: [ .env ]
build:
args:
SERVICE_PORT: 8147
Expand Down
28 changes: 20 additions & 8 deletions skills/dff_universal_prompted_skill/scenario/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,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 Down Expand Up @@ -101,14 +108,19 @@ def gathering_responses(reply, confidence, human_attr, bot_attr, attr):
logger.info(f"lm_service: {lm_service}")

if "envvars_to_send" in CONSIDERED_LM_SERVICES[lm_service]:
sending_variables = {
f"{var}_list": [getenv(var, None)] for var in CONSIDERED_LM_SERVICES[lm_service]["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 them must have not None value"
)
# get variables which names are in `ENVVARS_TO_SEND` (splitted by comma if many)
# from user_utterance attributes or from environment
envvars_to_send = CONSIDERED_LM_SERVICES[lm_service]["envvars_to_send"]
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.")
else:
sending_variables = {}

Expand Down