From 297ecfd5bebc16899238593b0db36b44d8ae302d Mon Sep 17 00:00:00 2001 From: Carson Date: Mon, 1 Jul 2024 12:26:02 -0500 Subject: [PATCH] Recommend dotenv for managing credentials --- examples/chat/.gitignore | 1 + examples/chat/enterprise/aws-bedrock-anthropic/app.py | 5 ++++- examples/chat/enterprise/azure-openai/app.py | 5 ++++- examples/chat/hello-providers/anthropic/app.py | 5 ++++- examples/chat/hello-providers/gemini/app.py | 7 ++++--- examples/chat/hello-providers/langchain/app.py | 5 ++++- examples/chat/hello-providers/openai/app.py | 5 ++++- 7 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 examples/chat/.gitignore diff --git a/examples/chat/.gitignore b/examples/chat/.gitignore new file mode 100644 index 000000000..4c49bd78f --- /dev/null +++ b/examples/chat/.gitignore @@ -0,0 +1 @@ +.env diff --git a/examples/chat/enterprise/aws-bedrock-anthropic/app.py b/examples/chat/enterprise/aws-bedrock-anthropic/app.py index 529b6742d..3d8771b4f 100644 --- a/examples/chat/enterprise/aws-bedrock-anthropic/app.py +++ b/examples/chat/enterprise/aws-bedrock-anthropic/app.py @@ -8,7 +8,10 @@ from shiny.express import ui -# Provide your AWS info here (or set the environment variable) +# Although you can set the AWS credentials here, it's recommended to put them in an .env +# file and load them with `dotenv` so your keys aren't exposed with your code. +# from dotenv import load_dotenv +# load_dotenv() llm = AnthropicBedrock( # aws_secret_key="..." # aws_access_key="..." diff --git a/examples/chat/enterprise/azure-openai/app.py b/examples/chat/enterprise/azure-openai/app.py index 623ee1475..862f2f9fd 100644 --- a/examples/chat/enterprise/azure-openai/app.py +++ b/examples/chat/enterprise/azure-openai/app.py @@ -9,7 +9,10 @@ from shiny.express import ui -# # Provide your Azure info here (or set the environment variable) +# Although you can set API keys here, it's recommended to put it in an .env file +# and load it with `dotenv` so your keys aren't exposed with your code. +# from dotenv import load_dotenv +# load_dotenv() llm = AzureOpenAI( api_key=os.getenv("AZURE_OPENAI_API_KEY"), api_version="2024-02-01", diff --git a/examples/chat/hello-providers/anthropic/app.py b/examples/chat/hello-providers/anthropic/app.py index 452b4ba5c..3194337d9 100644 --- a/examples/chat/hello-providers/anthropic/app.py +++ b/examples/chat/hello-providers/anthropic/app.py @@ -9,7 +9,10 @@ from shiny.express import ui -# Provide your API key here (or set the environment variable) +# Although you can set the API key here, it's recommended to put it in an .env file +# and load it with `dotenv` so your key isn't exposed with your code. +# from dotenv import load_dotenv +# load_dotenv() llm = AsyncAnthropic(api_key=os.environ.get("ANTHROPIC_API_KEY")) # Set some Shiny page options diff --git a/examples/chat/hello-providers/gemini/app.py b/examples/chat/hello-providers/gemini/app.py index d13f224de..4c868d73b 100644 --- a/examples/chat/hello-providers/gemini/app.py +++ b/examples/chat/hello-providers/gemini/app.py @@ -8,9 +8,10 @@ from shiny.express import ui -# Set the environment variable GOOGLE_API_KEY to your Google API key -# import os -# os.environ["GOOGLE_API_KEY"] = "your_google_api_key" +# You'll need to set the GOOGLE_API_KEY environment variable to your Google API key. +# We recommend putting it in a .env file and loading it with `dotenv`: +# from dotenv import load_dotenv +# load_dotenv() llm = GenerativeModel() # Set some Shiny page options diff --git a/examples/chat/hello-providers/langchain/app.py b/examples/chat/hello-providers/langchain/app.py index 269a6ed4d..060a775e7 100644 --- a/examples/chat/hello-providers/langchain/app.py +++ b/examples/chat/hello-providers/langchain/app.py @@ -10,7 +10,10 @@ from shiny.express import ui -# Provide your API key here (or set the environment variable) +# Although you can set the API key here, it's recommended to put it in an .env file +# and load it with `dotenv` so your key isn't exposed with your code: +# from dotenv import load_dotenv +# load_dotenv() llm = ChatOpenAI(api_key=os.environ.get("OPENAI_API_KEY")) # Set some Shiny page options diff --git a/examples/chat/hello-providers/openai/app.py b/examples/chat/hello-providers/openai/app.py index d45424b99..a80b0c636 100644 --- a/examples/chat/hello-providers/openai/app.py +++ b/examples/chat/hello-providers/openai/app.py @@ -9,7 +9,10 @@ from shiny.express import ui -# Provide your API key here (or set the environment variable) +# Although you can set the API key here, it's recommended to put it in an .env file +# and load it with `dotenv` so your key isn't exposed with your code: +# from dotenv import load_dotenv +# load_dotenv() llm = AsyncOpenAI(api_key=os.environ.get("OPENAI_API_KEY")) # Set some Shiny page options