INNER CODE UNIT · Python

validate_api_key_registration

seratch/ChatGPT-in-Slack · main_prod.py:219

    def validate_api_key_registration(ack: Ack, view: dict, context: BoltContext):
        already_set_api_key = context.get("OPENAI_API_KEY")

        inputs = view["state"]["values"]
        # Try to get the API key value, but handle if the field is missing or empty
        api_key_input = inputs.get("api_key", {}).get("input", {}).get("value", None)
        # If not provided, use the already-set API key from context
        api_key = api_key_input if api_key_input else already_set_api_key
        model = inputs["model"]["input"]["selected_option"]["value"]

        if not api_key:
            text = "An OpenAI API key is required."
            if already_set_api_key is not None:
                text = translate(
                    openai_api_key=already_set_api_key, context=context, text=text
                )
            ack(
                response_action="errors",

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…