Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions examples/capture_content.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
Example: enable conversation content for every handler at process startup.

The handlers in the global registry are built with no ``capture_content``
argument. They read the process default when they run. ``configure`` is
separate from ``init_client``: ``main.py`` initializes the client, and this
example calls ``configure`` once before the first AI invocation. An explicit
``True`` or ``False`` on a factory would override this default.

Usage (via main.py):
python main.py capture-content <flag-key> "<user input>"
"""

from __future__ import annotations

import json

import examples.register # noqa: F401 – side-effect: populate global_registry
from examples.utils import new_context, write_output
from launchdarkly_ai_server import SDKOptions, config, configure, global_registry


async def run(key: str, user_input: str) -> None:
configure(options=SDKOptions(capture_content=True))
response = await config(
key=key,
registry=global_registry,
).invoke(user_input, new_context())

print(json.dumps(response, indent=2, default=str))
write_output(response)
2 changes: 2 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

Examples:
python main.py agent launch-darkly-documentation-summarizer "What is the LaunchDarkly AI SDK?"
python main.py capture-content launch-darkly-documentation-summarizer "What is the LaunchDarkly AI SDK?"
python main.py streaming launch-darkly-documentation-summarizer "Summarise feature flags in 3 bullets"
python main.py judge launch-darkly-documentation-summarizer "What is the LaunchDarkly AI SDK?"
python main.py graph my-agent-graph "What is the LaunchDarkly AI SDK?"
Expand Down Expand Up @@ -44,6 +45,7 @@

EXAMPLES: dict[str, str] = {
"agent": "examples.agent",
"capture-content": "examples.capture_content",
"streaming": "examples.streaming",
"graph": "examples.graph_example",
"graph-history": "examples.graph_history",
Expand Down
Loading