diff --git a/features/create_agent/.env.example b/features/create_agent/.env.example new file mode 100644 index 0000000..2b699ad --- /dev/null +++ b/features/create_agent/.env.example @@ -0,0 +1,8 @@ +# Your LaunchDarkly server-side SDK key +LAUNCHDARKLY_SDK_KEY= + +# Provider API key(s) for the provider your agent config uses +OPENAI_API_KEY= + +# Override to use a different AI Config +LAUNCHDARKLY_AGENT_KEY=sample-agent diff --git a/features/create_agent/README.md b/features/create_agent/README.md index 33777a6..9624ffa 100644 --- a/features/create_agent/README.md +++ b/features/create_agent/README.md @@ -13,14 +13,12 @@ This example demonstrates how to use LaunchDarkly's `create_agent` method, which 1. Create the following config in your LaunchDarkly project. You can use a different key by setting the environment variable in your `.env`. - - [Create an AI Agent Config](https://launchdarkly.com/docs/home/ai-configs/agents) with a model and agent instructions. Default key: `sample-agent-config`. + - [Create an AI Agent Config](https://launchdarkly.com/docs/home/ai-configs/agents) with a model and agent instructions. Default key: `sample-agent`. -1. Create a `.env` file in this directory with the following variables: +1. Copy `.env.example` to `.env` and fill in your keys: - ``` - LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key - LAUNCHDARKLY_AGENT_CONFIG_KEY=sample-agent-config - OPENAI_API_KEY=your-openai-api-key + ```bash + cp .env.example .env ``` 1. Install the required dependencies: diff --git a/features/create_agent/create_agent_example.py b/features/create_agent/create_agent_example.py index 6f7fa72..43d6c99 100644 --- a/features/create_agent/create_agent_example.py +++ b/features/create_agent/create_agent_example.py @@ -17,7 +17,7 @@ sdk_key = os.getenv('LAUNCHDARKLY_SDK_KEY') # Set agent_config_key to the AI Agent Config key you want to evaluate. -agent_config_key = os.getenv('LAUNCHDARKLY_AGENT_CONFIG_KEY', 'sample-agent-config') +agent_config_key = os.getenv('LAUNCHDARKLY_AGENT_KEY', 'sample-agent') def get_weather(city: str) -> str: @@ -110,6 +110,7 @@ async def async_main(): print("\nNo judge evaluations were performed.") except Exception as err: + # In production, sanitize before logging — provider errors may include credentials. print("Error:", err) finally: # Flush pending events and close the client. diff --git a/features/create_agent_graph/.env.example b/features/create_agent_graph/.env.example new file mode 100644 index 0000000..fede5cc --- /dev/null +++ b/features/create_agent_graph/.env.example @@ -0,0 +1,8 @@ +# Your LaunchDarkly server-side SDK key +LAUNCHDARKLY_SDK_KEY= + +# Provider API key(s) for the provider(s) your agent graph uses +OPENAI_API_KEY= + +# Override to use a different AI Config +LAUNCHDARKLY_AGENT_GRAPH_KEY=sample-agent-graph diff --git a/features/create_agent_graph/README.md b/features/create_agent_graph/README.md index 2592de1..d3f3b76 100644 --- a/features/create_agent_graph/README.md +++ b/features/create_agent_graph/README.md @@ -16,12 +16,10 @@ This example demonstrates how to use LaunchDarkly's `create_agent_graph` method, - [Create AI Agent Configs](https://launchdarkly.com/docs/home/ai-configs/agents) for each node in your graph. Configure each with a model and agent instructions. Add tools (e.g. `search_flights`, `search_hotels`, `get_weather`) to the agents that need them. - [Create an Agent Graph](https://launchdarkly.com/docs/home/ai-configs/create) that connects your agent configs as nodes with edges defining the workflow. Default key: `sample-agent-graph`. -1. Create a `.env` file in this directory with the following variables: +1. Copy `.env.example` to `.env` and fill in your keys: - ``` - LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key - LAUNCHDARKLY_AGENT_GRAPH_KEY=sample-agent-graph - OPENAI_API_KEY=your-openai-api-key + ```bash + cp .env.example .env ``` 1. Install the required dependencies: diff --git a/features/create_agent_graph/create_agent_graph_example.py b/features/create_agent_graph/create_agent_graph_example.py index c30b9e3..5ada8a0 100644 --- a/features/create_agent_graph/create_agent_graph_example.py +++ b/features/create_agent_graph/create_agent_graph_example.py @@ -128,6 +128,7 @@ async def async_main(): print(f" reasoning: {eval_result.reasoning}") except Exception as err: + # In production, sanitize before logging — provider errors may include credentials. print("Error:", err) finally: # Flush pending events and close the client. diff --git a/features/create_judge/.env.example b/features/create_judge/.env.example new file mode 100644 index 0000000..43fb371 --- /dev/null +++ b/features/create_judge/.env.example @@ -0,0 +1,8 @@ +# Your LaunchDarkly server-side SDK key +LAUNCHDARKLY_SDK_KEY= + +# Provider API key(s) for the provider your judge config uses +OPENAI_API_KEY= + +# Override to use a different AI Config +LAUNCHDARKLY_JUDGE_KEY=sample-judge diff --git a/features/create_judge/README.md b/features/create_judge/README.md index f5d0cd9..a58d461 100644 --- a/features/create_judge/README.md +++ b/features/create_judge/README.md @@ -13,14 +13,12 @@ This example demonstrates how to use LaunchDarkly's `create_judge` method to eva 1. Create the following config in your LaunchDarkly project. You can use a different key by setting the environment variable in your `.env`. - - [Create a Judge Config](https://launchdarkly.com/docs/home/ai-configs/judges) for evaluation. Default key: `sample-ai-judge`. + - [Create a Judge Config](https://launchdarkly.com/docs/home/ai-configs/judges) for evaluation. Default key: `sample-judge`. -1. Create a `.env` file in this directory with the following variables: +1. Copy `.env.example` to `.env` and fill in your keys: - ``` - LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key - LAUNCHDARKLY_AI_JUDGE_KEY=sample-ai-judge - OPENAI_API_KEY=your-openai-api-key + ```bash + cp .env.example .env ``` 1. Install the required dependencies: diff --git a/features/create_judge/create_judge_example.py b/features/create_judge/create_judge_example.py index 813fcb9..c188506 100644 --- a/features/create_judge/create_judge_example.py +++ b/features/create_judge/create_judge_example.py @@ -17,7 +17,7 @@ sdk_key = os.getenv('LAUNCHDARKLY_SDK_KEY') # Set judge_key to the Judge key you want to use. -judge_key = os.getenv('LAUNCHDARKLY_AI_JUDGE_KEY', 'sample-ai-judge') +judge_key = os.getenv('LAUNCHDARKLY_JUDGE_KEY', 'sample-judge') async def async_main(): @@ -95,6 +95,7 @@ async def async_main(): print("\nDone!") except Exception as err: + # In production, sanitize before logging — provider errors may include credentials. print("Error:", err) finally: # Flush pending events and close the client. diff --git a/features/create_model/.env.example b/features/create_model/.env.example new file mode 100644 index 0000000..7bb58dc --- /dev/null +++ b/features/create_model/.env.example @@ -0,0 +1,8 @@ +# Your LaunchDarkly server-side SDK key +LAUNCHDARKLY_SDK_KEY= + +# Provider API key(s) for the provider your AI config uses +OPENAI_API_KEY= + +# Override to use a different AI Config +LAUNCHDARKLY_COMPLETION_KEY=sample-completion diff --git a/features/create_model/README.md b/features/create_model/README.md index 80f049c..2502f8d 100644 --- a/features/create_model/README.md +++ b/features/create_model/README.md @@ -13,14 +13,12 @@ This example demonstrates how to use LaunchDarkly's `create_model` method, which 1. Create the following config in your LaunchDarkly project. You can use a different key by setting the environment variable in your `.env`. - - [Create an AI Config](https://launchdarkly.com/docs/home/ai-configs/create) with a model and system message. Default key: `sample-completion-config`. + - [Create an AI Config](https://launchdarkly.com/docs/home/ai-configs/create) with a model and system message. Default key: `sample-completion`. -1. Create a `.env` file in this directory with the following variables: +1. Copy `.env.example` to `.env` and fill in your keys: - ``` - LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key - LAUNCHDARKLY_AI_CONFIG_KEY=sample-completion-config - OPENAI_API_KEY=your-openai-api-key + ```bash + cp .env.example .env ``` 1. Install the required dependencies: diff --git a/features/create_model/create_model_example.py b/features/create_model/create_model_example.py index 9022c2d..e044e90 100644 --- a/features/create_model/create_model_example.py +++ b/features/create_model/create_model_example.py @@ -17,7 +17,7 @@ sdk_key = os.getenv('LAUNCHDARKLY_SDK_KEY') # Set config_key to the AI Config key you want to evaluate. -ai_config_key = os.getenv('LAUNCHDARKLY_AI_CONFIG_KEY', 'sample-completion-config') +ai_config_key = os.getenv('LAUNCHDARKLY_COMPLETION_KEY', 'sample-completion') async def async_main(): @@ -96,6 +96,7 @@ async def async_main(): print("\nNo judge evaluations were performed. Try adding a judge to the AI config to see results.") except Exception as err: + # In production, sanitize before logging — provider errors may include credentials. print("Error:", err) finally: # Flush pending events and close the client. diff --git a/getting_started/bedrock/converse/.env.example b/getting_started/bedrock/converse/.env.example new file mode 100644 index 0000000..aa988e4 --- /dev/null +++ b/getting_started/bedrock/converse/.env.example @@ -0,0 +1,12 @@ +# Your LaunchDarkly server-side SDK key +LAUNCHDARKLY_SDK_KEY= + +# Your AWS credentials for Bedrock access +AWS_ACCESS_KEY_ID= +AWS_SECRET_ACCESS_KEY= + +# Override to use a different AWS region +AWS_DEFAULT_REGION=us-east-1 + +# Override to use a different AI Config +LAUNCHDARKLY_COMPLETION_KEY=sample-completion diff --git a/getting_started/bedrock/converse/README.md b/getting_started/bedrock/converse/README.md index 09da9dc..497a2c4 100644 --- a/getting_started/bedrock/converse/README.md +++ b/getting_started/bedrock/converse/README.md @@ -13,26 +13,17 @@ This example demonstrates how to use LaunchDarkly's AI Config with the AWS Bedro 1. Create the following config in your LaunchDarkly project. You can use a different key by setting the environment variable in your `.env`. - - [Create an AI Config](https://launchdarkly.com/docs/home/ai-configs/create) with a Bedrock model and a system message. Default key: `sample-completion-config`. + - [Create an AI Config](https://launchdarkly.com/docs/home/ai-configs/create) with a Bedrock model and a system message. Default key: `sample-completion`. -1. Create a `.env` file in this directory with the following variables: +1. Copy `.env.example` to `.env` and fill in your keys: + ```bash + cp .env.example .env ``` - LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key - LAUNCHDARKLY_AI_CONFIG_KEY=sample-completion-config - ``` - - > `LAUNCHDARKLY_AI_CONFIG_KEY` defaults to `sample-completion-config` if not set. -1. Ensure your AWS credentials can be [auto-detected by the `boto3` library](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html). You can set them in your `.env` file: - - ``` - AWS_ACCESS_KEY_ID=your-access-key-id - AWS_SECRET_ACCESS_KEY=your-secret-access-key - AWS_DEFAULT_REGION=us-east-1 - ``` + `LAUNCHDARKLY_COMPLETION_KEY` defaults to `sample-completion` if not set. - Other options include role providers or shared credential files. + Ensure your AWS credentials can be [auto-detected by the `boto3` library](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html). Setting them in `.env` is one option; role providers or shared credential files are also supported. 1. Install the required dependencies: diff --git a/getting_started/bedrock/converse/bedrock_example.py b/getting_started/bedrock/converse/bedrock_example.py index 2d853da..1fded50 100755 --- a/getting_started/bedrock/converse/bedrock_example.py +++ b/getting_started/bedrock/converse/bedrock_example.py @@ -40,14 +40,14 @@ def get_bedrock_metrics(response): sdk_key = os.getenv('LAUNCHDARKLY_SDK_KEY') # Set config_key to the AI Config key you want to evaluate. -ai_config_key = os.getenv('LAUNCHDARKLY_AI_CONFIG_KEY', 'sample-completion-config') +ai_config_key = os.getenv('LAUNCHDARKLY_COMPLETION_KEY', 'sample-completion') def main(): if not sdk_key: print("*** Please set the LAUNCHDARKLY_SDK_KEY env first") exit() if not ai_config_key: - print("*** Please set the LAUNCHDARKLY_AI_CONFIG_KEY env first") + print("*** Please set the LAUNCHDARKLY_COMPLETION_KEY env first") exit() ldclient.set_config(Config(sdk_key, plugins=[ diff --git a/getting_started/gemini/generate_content/.env.example b/getting_started/gemini/generate_content/.env.example new file mode 100644 index 0000000..1cf1d92 --- /dev/null +++ b/getting_started/gemini/generate_content/.env.example @@ -0,0 +1,8 @@ +# Your LaunchDarkly server-side SDK key +LAUNCHDARKLY_SDK_KEY= + +# Your Google API key +GOOGLE_API_KEY= + +# Override to use a different AI Config +LAUNCHDARKLY_COMPLETION_KEY=sample-completion diff --git a/getting_started/gemini/generate_content/README.md b/getting_started/gemini/generate_content/README.md index 9abe617..8a94bfc 100644 --- a/getting_started/gemini/generate_content/README.md +++ b/getting_started/gemini/generate_content/README.md @@ -13,14 +13,12 @@ This example demonstrates how to use LaunchDarkly's AI Config with the Google Ge 1. Create the following config in your LaunchDarkly project. You can use a different key by setting the environment variable in your `.env`. - - [Create an AI Config](https://launchdarkly.com/docs/home/ai-configs/create) with a Gemini model (e.g. `gemini-2.0-flash`) and a system message. Default key: `sample-completion-config`. + - [Create an AI Config](https://launchdarkly.com/docs/home/ai-configs/create) with a Gemini model (e.g. `gemini-2.0-flash`) and a system message. Default key: `sample-completion`. -1. Create a `.env` file in this directory with the following variables: +1. Copy `.env.example` to `.env` and fill in your keys: - ``` - LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key - LAUNCHDARKLY_AI_CONFIG_KEY=sample-completion-config - GOOGLE_API_KEY=your-google-api-key + ```bash + cp .env.example .env ``` 1. Install the required dependencies: diff --git a/getting_started/gemini/generate_content/gemini_example.py b/getting_started/gemini/generate_content/gemini_example.py index 22ba7ec..086204c 100644 --- a/getting_started/gemini/generate_content/gemini_example.py +++ b/getting_started/gemini/generate_content/gemini_example.py @@ -20,7 +20,7 @@ sdk_key = os.getenv('LAUNCHDARKLY_SDK_KEY') # Set config_key to the AI Config key you want to evaluate. -ai_config_key = os.getenv('LAUNCHDARKLY_AI_CONFIG_KEY', 'sample-completion-config') +ai_config_key = os.getenv('LAUNCHDARKLY_COMPLETION_KEY', 'sample-completion') # Set Google API key google_api_key = os.getenv('GOOGLE_API_KEY') @@ -93,7 +93,7 @@ def main(): print("*** Please set the LAUNCHDARKLY_SDK_KEY env first") exit() if not ai_config_key: - print("*** Please set the LAUNCHDARKLY_AI_CONFIG_KEY env first") + print("*** Please set the LAUNCHDARKLY_COMPLETION_KEY env first") exit() if not google_api_key: print("*** Please set the GOOGLE_API_KEY env first") diff --git a/getting_started/langchain/invoke/.env.example b/getting_started/langchain/invoke/.env.example new file mode 100644 index 0000000..09e5c3d --- /dev/null +++ b/getting_started/langchain/invoke/.env.example @@ -0,0 +1,11 @@ +# Your LaunchDarkly server-side SDK key +LAUNCHDARKLY_SDK_KEY= + +# Provider API keys - fill in the ones for the provider(s) your AI config uses +OPENAI_API_KEY= +GOOGLE_API_KEY= +AWS_ACCESS_KEY_ID= +AWS_SECRET_ACCESS_KEY= + +# Override to use a different AI Config +LAUNCHDARKLY_COMPLETION_KEY=sample-completion diff --git a/getting_started/langchain/invoke/README.md b/getting_started/langchain/invoke/README.md index 5f42e0e..da05362 100644 --- a/getting_started/langchain/invoke/README.md +++ b/getting_started/langchain/invoke/README.md @@ -13,22 +13,12 @@ This example demonstrates how to use LaunchDarkly's AI Config with LangChain, su 1. Create the following config in your LaunchDarkly project. You can use a different key by setting the environment variable in your `.env`. - - [Create an AI Config](https://launchdarkly.com/docs/home/ai-configs/create) with a model and a system message. Default key: `sample-completion-config`. + - [Create an AI Config](https://launchdarkly.com/docs/home/ai-configs/create) with a model and a system message. Default key: `sample-completion`. -1. Create a `.env` file in this directory with the following variables: +1. Copy `.env.example` to `.env` and fill in your keys (only the provider keys for providers you actually use are required): - ``` - LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key - LAUNCHDARKLY_AI_CONFIG_KEY=sample-completion-config - ``` - - Add the API keys for the providers you want to use: - - ``` - OPENAI_API_KEY=your-openai-api-key - GOOGLE_API_KEY=your-google-api-key - AWS_ACCESS_KEY_ID=your-access-key-id - AWS_SECRET_ACCESS_KEY=your-secret-access-key + ```bash + cp .env.example .env ``` 1. Install the required dependencies: diff --git a/getting_started/langchain/invoke/langchain_example.py b/getting_started/langchain/invoke/langchain_example.py index 8fdba44..3b763d2 100644 --- a/getting_started/langchain/invoke/langchain_example.py +++ b/getting_started/langchain/invoke/langchain_example.py @@ -19,7 +19,7 @@ sdk_key = os.getenv('LAUNCHDARKLY_SDK_KEY') # Set config_key to the AI Config key you want to evaluate. -ai_config_key = os.getenv('LAUNCHDARKLY_AI_CONFIG_KEY', 'sample-completion-config') +ai_config_key = os.getenv('LAUNCHDARKLY_COMPLETION_KEY', 'sample-completion') def map_provider_to_langchain(provider_name): """Map LaunchDarkly provider names to LangChain provider names.""" @@ -35,7 +35,7 @@ async def async_main(): print("*** Please set the LAUNCHDARKLY_SDK_KEY env first") exit() if not ai_config_key: - print("*** Please set the LAUNCHDARKLY_AI_CONFIG_KEY env first") + print("*** Please set the LAUNCHDARKLY_COMPLETION_KEY env first") exit() ldclient.set_config(Config(sdk_key, plugins=[ @@ -119,6 +119,7 @@ async def async_main(): print(f" Tool calls: {', '.join(summary.tool_calls)}") except Exception as e: + # In production, sanitize before logging — provider errors may include credentials. print(f"Error during completion: {e}") print("Please ensure you have the correct API keys and credentials set up for the detected provider.") diff --git a/getting_started/langgraph/react_agent/.env.example b/getting_started/langgraph/react_agent/.env.example new file mode 100644 index 0000000..d909fdb --- /dev/null +++ b/getting_started/langgraph/react_agent/.env.example @@ -0,0 +1,11 @@ +# Your LaunchDarkly server-side SDK key +LAUNCHDARKLY_SDK_KEY= + +# Provider API keys - fill in the ones for the provider(s) your agent config uses +OPENAI_API_KEY= +GOOGLE_API_KEY= +AWS_ACCESS_KEY_ID= +AWS_SECRET_ACCESS_KEY= + +# Override to use a different AI Config +LAUNCHDARKLY_AGENT_KEY=sample-agent diff --git a/getting_started/langgraph/react_agent/README.md b/getting_started/langgraph/react_agent/README.md index d94d8c7..71d831c 100644 --- a/getting_started/langgraph/react_agent/README.md +++ b/getting_started/langgraph/react_agent/README.md @@ -13,22 +13,12 @@ This example demonstrates how to use LaunchDarkly's AI Config with LangGraph to 1. Create the following config in your LaunchDarkly project. You can use a different key by setting the environment variable in your `.env`. - - [Create an AI Agent Config](https://launchdarkly.com/docs/home/ai-configs/agents) with a model and agent instructions. Default key: `sample-agent-config`. + - [Create an AI Agent Config](https://launchdarkly.com/docs/home/ai-configs/agents) with a model and agent instructions. Default key: `sample-agent`. -1. Create a `.env` file in this directory with the following variables: +1. Copy `.env.example` to `.env` and fill in your keys (only the provider keys for providers you actually use are required): - ``` - LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key - LAUNCHDARKLY_AGENT_CONFIG_KEY=sample-agent-config - ``` - - Add the API keys for the providers you want to use: - - ``` - OPENAI_API_KEY=your-openai-api-key - GOOGLE_API_KEY=your-google-api-key - AWS_ACCESS_KEY_ID=your-access-key-id - AWS_SECRET_ACCESS_KEY=your-secret-access-key + ```bash + cp .env.example .env ``` 1. Install the required dependencies: diff --git a/getting_started/langgraph/react_agent/langgraph_agent_example.py b/getting_started/langgraph/react_agent/langgraph_agent_example.py index ba1a4c9..0244865 100644 --- a/getting_started/langgraph/react_agent/langgraph_agent_example.py +++ b/getting_started/langgraph/react_agent/langgraph_agent_example.py @@ -20,7 +20,7 @@ sdk_key = os.getenv('LAUNCHDARKLY_SDK_KEY') # Set config key for the agent -agent_config_key = os.getenv('LAUNCHDARKLY_AGENT_CONFIG_KEY', 'sample-agent-config') +agent_config_key = os.getenv('LAUNCHDARKLY_AGENT_KEY', 'sample-agent') def map_provider_to_langchain(provider_name): """Map LaunchDarkly provider names to LangChain provider names.""" @@ -122,6 +122,7 @@ def main(): print(f" Tool calls: {', '.join(summary.tool_calls)}") except Exception as e: + # In production, sanitize before logging — provider errors may include credentials. print(f"\nError: {e}") print("Please ensure you have the correct API keys and credentials set up for the detected providers.") diff --git a/getting_started/langgraph/state_graph/.env.example b/getting_started/langgraph/state_graph/.env.example new file mode 100644 index 0000000..758abdb --- /dev/null +++ b/getting_started/langgraph/state_graph/.env.example @@ -0,0 +1,14 @@ +# Your LaunchDarkly server-side SDK key +LAUNCHDARKLY_SDK_KEY= + +# Provider API keys - fill in the ones for the provider(s) your agent configs use +OPENAI_API_KEY= +GOOGLE_API_KEY= +AWS_ACCESS_KEY_ID= +AWS_SECRET_ACCESS_KEY= + +# Override to use a different AI Config +LAUNCHDARKLY_ANALYZER_KEY=code-review-analyzer + +# Override to use a different AI Config +LAUNCHDARKLY_DOCUMENTATION_KEY=code-review-documentation diff --git a/getting_started/langgraph/state_graph/README.md b/getting_started/langgraph/state_graph/README.md index 1388a02..d529205 100644 --- a/getting_started/langgraph/state_graph/README.md +++ b/getting_started/langgraph/state_graph/README.md @@ -16,21 +16,10 @@ This example demonstrates how to use LaunchDarkly's AI Config with LangGraph to - [Create an AI Agent Config](https://launchdarkly.com/docs/home/ai-configs/agents) for code analysis. Default key: `code-review-analyzer`. - [Create an AI Agent Config](https://launchdarkly.com/docs/home/ai-configs/agents) for documentation generation. Default key: `code-review-documentation`. -1. Create a `.env` file in this directory with the following variables: +1. Copy `.env.example` to `.env` and fill in your keys (only the provider keys for providers you actually use are required): - ``` - LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key - LAUNCHDARKLY_ANALYZER_CONFIG_KEY=code-review-analyzer - LAUNCHDARKLY_DOCUMENTATION_CONFIG_KEY=code-review-documentation - ``` - - Add the API keys for the providers you want to use: - - ``` - OPENAI_API_KEY=your-openai-api-key - GOOGLE_API_KEY=your-google-api-key - AWS_ACCESS_KEY_ID=your-access-key-id - AWS_SECRET_ACCESS_KEY=your-secret-access-key + ```bash + cp .env.example .env ``` 1. Install the required dependencies: diff --git a/getting_started/langgraph/state_graph/langgraph_multi_agent_example.py b/getting_started/langgraph/state_graph/langgraph_multi_agent_example.py index c05edef..b2b1691 100644 --- a/getting_started/langgraph/state_graph/langgraph_multi_agent_example.py +++ b/getting_started/langgraph/state_graph/langgraph_multi_agent_example.py @@ -23,8 +23,8 @@ sdk_key = os.getenv('LAUNCHDARKLY_SDK_KEY') # Set config keys for the two agents -analyzer_config_key = os.getenv('LAUNCHDARKLY_ANALYZER_CONFIG_KEY', 'code-review-analyzer') -documentation_config_key = os.getenv('LAUNCHDARKLY_DOCUMENTATION_CONFIG_KEY', 'code-review-documentation') +analyzer_config_key = os.getenv('LAUNCHDARKLY_ANALYZER_KEY', 'code-review-analyzer') +documentation_config_key = os.getenv('LAUNCHDARKLY_DOCUMENTATION_KEY', 'code-review-documentation') # Custom state class for the code review workflow class CodeReviewState(TypedDict): @@ -148,6 +148,7 @@ def ai_node( ) except Exception as e: + # In production, sanitize before logging — provider errors may include credentials. print(f"Error in node for {config_key}: {e}") return Command( goto=END, @@ -279,6 +280,7 @@ def calculate_average(numbers): print("="*80) except Exception as e: + # In production, sanitize before logging — provider errors may include credentials. print(f"Error during workflow execution: {e}") print("Please ensure you have the correct API keys and credentials set up for the detected providers.") diff --git a/getting_started/openai/chat_completions/.env.example b/getting_started/openai/chat_completions/.env.example new file mode 100644 index 0000000..d20db55 --- /dev/null +++ b/getting_started/openai/chat_completions/.env.example @@ -0,0 +1,8 @@ +# Your LaunchDarkly server-side SDK key +LAUNCHDARKLY_SDK_KEY= + +# Your OpenAI API key +OPENAI_API_KEY= + +# Override to use a different AI Config +LAUNCHDARKLY_COMPLETION_KEY=sample-completion diff --git a/getting_started/openai/chat_completions/README.md b/getting_started/openai/chat_completions/README.md index cb81328..368fa97 100644 --- a/getting_started/openai/chat_completions/README.md +++ b/getting_started/openai/chat_completions/README.md @@ -13,14 +13,12 @@ This example demonstrates how to use LaunchDarkly's AI Config with the OpenAI pr 1. Create the following config in your LaunchDarkly project. You can use a different key by setting the environment variable in your `.env`. - - [Create an AI Config](https://launchdarkly.com/docs/home/ai-configs/create) with an OpenAI model (e.g. `gpt-4`) and a system message. Default key: `sample-completion-config`. + - [Create an AI Config](https://launchdarkly.com/docs/home/ai-configs/create) with an OpenAI model (e.g. `gpt-4`) and a system message. Default key: `sample-completion`. -1. Create a `.env` file in this directory with the following variables: +1. Copy `.env.example` to `.env` and fill in your keys: - ``` - LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key - LAUNCHDARKLY_AI_CONFIG_KEY=sample-completion-config - OPENAI_API_KEY=your-openai-api-key + ```bash + cp .env.example .env ``` 1. Install the required dependencies: diff --git a/getting_started/openai/chat_completions/openai_example.py b/getting_started/openai/chat_completions/openai_example.py index ad59114..19fd0cf 100755 --- a/getting_started/openai/chat_completions/openai_example.py +++ b/getting_started/openai/chat_completions/openai_example.py @@ -20,7 +20,7 @@ sdk_key = os.getenv('LAUNCHDARKLY_SDK_KEY') # Set config_key to the AI Config key you want to evaluate. -ai_config_key = os.getenv('LAUNCHDARKLY_AI_CONFIG_KEY', 'sample-completion-config') +ai_config_key = os.getenv('LAUNCHDARKLY_COMPLETION_KEY', 'sample-completion') def main(): @@ -28,7 +28,7 @@ def main(): print("*** Please set the LAUNCHDARKLY_SDK_KEY env first") exit() if not ai_config_key: - print("*** Please set the LAUNCHDARKLY_AI_CONFIG_KEY env first") + print("*** Please set the LAUNCHDARKLY_COMPLETION_KEY env first") exit() ldclient.set_config(Config(sdk_key, plugins=[