Skip to content

Instantly share code, notes, and snippets.

@sauercrowd
Created October 22, 2024 09:16
Show Gist options
  • Save sauercrowd/f92135da9dec57d66fbf820232dff87a to your computer and use it in GitHub Desktop.
Save sauercrowd/f92135da9dec57d66fbf820232dff87a to your computer and use it in GitHub Desktop.
Langfuse - llamaindex integrations
# 1. https://docs.llamaindex.ai/en/v0.10.23/examples/callbacks/LangfuseCallbackHandler/#option-1-set-global-llamaindex-handler
from llama_index.core import global_handler, set_global_handler
set_global_handler("langfuse")
langfuse_callback_handler = global_handler
# 2. https://docs.llamaindex.ai/en/v0.10.23/examples/callbacks/LangfuseCallbackHandler/#option-2-use-langfuse-callback-directly
from llama_index.core import Settings
from llama_index.core.callbacks import CallbackManager
from langfuse.llama_index import LlamaIndexCallbackHandler
langfuse_callback_handler = LlamaIndexCallbackHandler()
Settings.callback_manager = CallbackManager([langfuse_callback_handler])
# 3. https://langfuse.com/docs/integrations/llama-index/example-python-instrumentation-module
from langfuse.llama_index import LlamaIndexInstrumentor
instrumentor = LlamaIndexInstrumentor()
instrumentor.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment