diff --git a/examples/bedrock/bedrock_example.py b/examples/bedrock/bedrock_example.py index b7e8a32..74e482b 100755 --- a/examples/bedrock/bedrock_example.py +++ b/examples/bedrock/bedrock_example.py @@ -58,12 +58,13 @@ def main(): context, variables={'myUserVariable': "Testing Variable"} ) - tracker = config_value.tracker if not config_value.enabled: print("AI Config is disabled") return + tracker = config_value.create_tracker() + # Map the messages to the format expected by Bedrock chat_messages = [{'role': msg.role, 'content': [{'text': msg.content}]} for msg in config_value.messages if msg.role != 'system'] system_messages = [{'text': msg.content} for msg in config_value.messages if msg.role == 'system'] diff --git a/examples/chat_observability/chat_observability_example.py b/examples/chat_observability/chat_observability_example.py index 1ecc7f7..6a5cbbf 100644 --- a/examples/chat_observability/chat_observability_example.py +++ b/examples/chat_observability/chat_observability_example.py @@ -82,7 +82,7 @@ async def async_main(): ) if not chat: - print(f"*** AI chat configuration is not enabled for key: {ai_config_key}") + print(f"*** Failed to create chat for key: {ai_config_key}") return user_input_1 = "What is feature flagging in 2 sentences?" diff --git a/examples/chat_observability/pyproject.toml b/examples/chat_observability/pyproject.toml index e29d6d0..d098273 100644 --- a/examples/chat_observability/pyproject.toml +++ b/examples/chat_observability/pyproject.toml @@ -15,6 +15,8 @@ python = "^3.10" python-dotenv = ">=1.0.0" launchdarkly-server-sdk-ai = "^0.18.0" launchdarkly-observability = ">=0.1.0" +launchdarkly-server-sdk-ai-openai = ">=0.4.0" +launchdarkly-server-sdk-ai-langchain = ">=0.5.0" openai = ">=0.2.0" [build-system] diff --git a/examples/gemini/gemini_example.py b/examples/gemini/gemini_example.py index ac2bcd3..7732314 100644 --- a/examples/gemini/gemini_example.py +++ b/examples/gemini/gemini_example.py @@ -128,12 +128,13 @@ def main(): context, variables={'myUserVariable': "Testing Variable"} ) - tracker = config_value.tracker if not config_value.enabled: print("AI Config is disabled") return + tracker = config_value.create_tracker() + # Configure Google Generative AI client = genai.Client( api_key=google_api_key, diff --git a/examples/judge/chat_judge_example.py b/examples/judge/chat_judge_example.py index ca99daa..e58dabb 100644 --- a/examples/judge/chat_judge_example.py +++ b/examples/judge/chat_judge_example.py @@ -56,7 +56,7 @@ async def async_main(): }) if not chat: - print(f"*** AI chat configuration is not enabled for key: {ai_config_key}") + print(f"*** Failed to create chat for key: {ai_config_key}") return print("\n*** Starting chat with automatic judge evaluation:") diff --git a/examples/judge/direct_judge_example.py b/examples/judge/direct_judge_example.py index f8126d4..85369ac 100644 --- a/examples/judge/direct_judge_example.py +++ b/examples/judge/direct_judge_example.py @@ -58,7 +58,7 @@ async def async_main(): judge = await aiclient.create_judge(judge_key, context) if not judge: - print(f"*** AI judge configuration is not enabled for key: {judge_key}") + print(f"*** Failed to create judge for key: {judge_key}") return print("\n*** Starting direct judge evaluation of input and output:") diff --git a/examples/langchain/langchain_example.py b/examples/langchain/langchain_example.py index 836e1eb..232736c 100644 --- a/examples/langchain/langchain_example.py +++ b/examples/langchain/langchain_example.py @@ -66,12 +66,13 @@ async def async_main(): context, variables={'myUserVariable': "Testing Variable"} ) - tracker = config_value.tracker if not config_value.enabled: print("AI Config is disabled") return + tracker = config_value.create_tracker() + try: # Create LangChain model instance using init_chat_model # Map the provider from config_value to LangChain format diff --git a/examples/langgraph_agent/langgraph_agent_example.py b/examples/langgraph_agent/langgraph_agent_example.py index f65b0d7..2778bd6 100644 --- a/examples/langgraph_agent/langgraph_agent_example.py +++ b/examples/langgraph_agent/langgraph_agent_example.py @@ -115,7 +115,7 @@ def main(): try: # Track and execute the agent - response = track_langgraph_metrics(agent_config.tracker, lambda: agent.invoke({ + response = track_langgraph_metrics(agent_config.create_tracker(), lambda: agent.invoke({ "messages": [{"role": "user", "content": "What is the weather in Tokyo?"}] })) diff --git a/examples/langgraph_multi_agent/langgraph_multi_agent_example.py b/examples/langgraph_multi_agent/langgraph_multi_agent_example.py index 8325074..2ce8c8c 100644 --- a/examples/langgraph_multi_agent/langgraph_multi_agent_example.py +++ b/examples/langgraph_multi_agent/langgraph_multi_agent_example.py @@ -95,7 +95,7 @@ def create_agent_with_config(aiclient, config_key, context): # Create a React agent with the LLM agent = create_react_agent(llm, [], prompt=agent_config.instructions) - return agent, agent_config.tracker, False + return agent, agent_config.create_tracker(), False def ai_node( state: CodeReviewState, diff --git a/examples/openai/openai_example.py b/examples/openai/openai_example.py index 0a11e5c..6520fb4 100755 --- a/examples/openai/openai_example.py +++ b/examples/openai/openai_example.py @@ -60,11 +60,12 @@ def main(): context, variables={'myUserVariable': "Testing Variable"} ) - tracker = config_value.tracker if not config_value.enabled: print("AI Config is disabled") return + + tracker = config_value.create_tracker() messages = [message.to_dict() for message in (config_value.messages or [])]