From fc4715eeab420ace57753fd639ca85dfb1d2f2eb Mon Sep 17 00:00:00 2001 From: Thiago Riemma Carbonera Date: Thu, 26 Mar 2026 17:14:58 -0300 Subject: [PATCH] fix(prompt_registry): add __init__.py and registry for langfuse integration --- litellm/integrations/langfuse/__init__.py | 21 ++++++++++++++++++++ tests/test_langfuse_prompt_init.py | 24 +++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 litellm/integrations/langfuse/__init__.py create mode 100644 tests/test_langfuse_prompt_init.py diff --git a/litellm/integrations/langfuse/__init__.py b/litellm/integrations/langfuse/__init__.py new file mode 100644 index 00000000000..d48ae2675ab --- /dev/null +++ b/litellm/integrations/langfuse/__init__.py @@ -0,0 +1,21 @@ +"""Langfuse integration for LiteLLM Prompt Management.""" + +from .langfuse_prompt_management import LangfusePromptManagement + + +def initialize_prompt(litellm_params, prompt_spec): + """ + Initialization function that prompt_registry.py will call. + """ + return LangfusePromptManagement( + langfuse_public_key=getattr(litellm_params, "langfuse_public_key", None), + langfuse_secret=getattr(litellm_params, "langfuse_secret", None), + langfuse_host=getattr(litellm_params, "langfuse_host", None), + ) + + +prompt_initializer_registry = { + "langfuse": initialize_prompt, +} + +__all__ = ["initialize_prompt", "prompt_initializer_registry"] diff --git a/tests/test_langfuse_prompt_init.py b/tests/test_langfuse_prompt_init.py new file mode 100644 index 00000000000..58108f13970 --- /dev/null +++ b/tests/test_langfuse_prompt_init.py @@ -0,0 +1,24 @@ +import pytest +from litellm.proxy.prompts.prompt_registry import get_prompt_initializer_from_integrations +from litellm.types.prompts.init_prompts import PromptLiteLLMParams, PromptSpec + +def test_langfuse_discovery_and_init(): + """ + Tests whether Langfuse is dynamically discovered and can be initialized. + This validates the fix in __init__.py at litellm/integrations/langfuse/ + """ + + registry = get_prompt_initializer_from_integrations() + assert "langfuse" in registry, "Error: Langfuse wasn't discovered by the prompt_registry!" + + init_func = registry["langfuse"] + params = PromptLiteLLMParams( + prompt_integration="langfuse", + langfuse_public_key="test-key", + langfuse_secret="test-secret" + ) + spec = PromptSpec(prompt_id="test-id", litellm_params=params) + + obj = init_func(params, spec) + assert obj is not None, "Initiation function returned None!" + assert obj.integration_name == "langfuse" \ No newline at end of file