INNER CODE UNIT · Python

save_api_key_registration

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

    def save_api_key_registration(
        view: dict,
        logger: logging.Logger,
        context: BoltContext,
    ):
        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
        already_set_api_key = context.get("OPENAI_API_KEY")
        api_key = api_key_input if api_key_input else already_set_api_key
        model = inputs["model"]["input"]["selected_option"]["value"]
        try:
            client = OpenAI(api_key=api_key)
            client.models.retrieve(model=model)
            s3_client.put_object(
                Bucket=openai_bucket_name,
                Key=context.team_id,

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…