Skip to content

Commit

Permalink
feat: universal dist requires api keys in request (#425)
Browse files Browse the repository at this point in the history
  • Loading branch information
dilyararimovna committed May 1, 2023
1 parent 2ade268 commit c6ffe45
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
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

0 comments on commit c6ffe45

Please sign in to comment.