INNER CODE UNIT · Python

set_s3_openai_api_key

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

    def set_s3_openai_api_key(context: BoltContext, next_):
        try:
            s3_response = s3_client.get_object(
                Bucket=openai_bucket_name, Key=context.team_id
            )
            config_str: str = s3_response["Body"].read().decode("utf-8")
            if config_str.startswith("{"):
                config = json.loads(config_str)
                context["OPENAI_API_KEY"] = config.get("api_key")
                context["OPENAI_MODEL"] = config.get("model")
                context["OPENAI_IMAGE_GENERATION_MODEL"] = config.get(
                    "image_generation_model", OPENAI_IMAGE_GENERATION_MODEL
                )
                context["OPENAI_TEMPERATURE"] = config.get(
                    "temperature", OPENAI_TEMPERATURE
                )
            else:
                # The legacy data format

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…