diff --git a/examples/capture_content.py b/examples/capture_content.py new file mode 100644 index 00000000..dfce35db --- /dev/null +++ b/examples/capture_content.py @@ -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 "" +""" + +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) diff --git a/main.py b/main.py index 0bbaefe1..09d17ff2 100644 --- a/main.py +++ b/main.py @@ -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?" @@ -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",