Skip to content

chore: update deprecated API usage in hello-python-ai examples#23

Merged
jsonbailey merged 2 commits into
mainfrom
jb/aic-1934/update-python-examples
Apr 20, 2026
Merged

chore: update deprecated API usage in hello-python-ai examples#23
jsonbailey merged 2 commits into
mainfrom
jb/aic-1934/update-python-examples

Conversation

@jsonbailey
Copy link
Copy Markdown
Contributor

Summary

Audits and updates the Python AI SDK example apps to stop using deprecated API surfaces. Doc guides reference these examples, so they need to reflect current SDK usage.

Changes

  • examples/openai_example.py — Replaced deprecated tracker.track_openai_metrics(...) with tracker.track_metrics_of(..., get_ai_metrics_from_response) (imported from ldai_openai). Added flush() before close().
  • examples/chat_judge_example.py — Replaced deprecated aiclient.create_chat(...) with aiclient.create_model(...). Fixed import from ldai to ldai.client. Added flush() before close().
  • examples/chat_observability_example.py — Same create_chatcreate_model swap and ldaildai.client import fix. Added flush() before close().
  • examples/direct_judge_example.py — Fixed import from ldai to ldai.client. Added flush() before close().
  • examples/bedrock_example.py, gemini_example.py, langchain_example.py, langgraph_agent_example.py, langgraph_multi_agent_example.py — Added ldclient.get().flush() before ldclient.get().close() so pending events are sent before shutdown.

No functional behavior was changed — only API calls were updated to use current methods.

Test plan

  • Run poetry run chat-judge-example and confirm it executes end-to-end
  • Run poetry run openai-example and confirm metrics are tracked via the new extractor path
  • Spot-check the remaining examples still run without import errors

🤖 Generated with Claude Code

jsonbailey and others added 2 commits April 20, 2026 12:26
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Matches the import style used in the launchdarkly-server-sdk-ai README
and tests (e.g. `from ldai import LDAIClient`), rather than reaching into
the `ldai.client` submodule. Both forms resolve to the same symbols —
`ldai/__init__.py` re-exports them via `__all__` — but the package root
is the public API surface.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jsonbailey jsonbailey marked this pull request as ready for review April 20, 2026 17:51
@jsonbailey jsonbailey requested a review from a team as a code owner April 20, 2026 17:51
@jsonbailey jsonbailey merged commit c24a683 into main Apr 20, 2026
4 checks passed
@jsonbailey jsonbailey deleted the jb/aic-1934/update-python-examples branch April 20, 2026 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants