Musterby Elitery
Integrations

Mirascope

Trace Mirascope LLM calls in Muster via the with_langfuse decorator.

Mirascope is a Python toolkit for LLM applications that supports multiple providers and prompt-template patterns. Muster captures Mirascope calls through the with_langfuse decorator.

Key Features

  • Automatic tracing via the with_langfuse decorator across all Mirascope functions.
  • Multi-provider support for every Mirascope-supported provider.
  • Streaming compatibility for both standard and streaming responses.
  • Detailed insights into conversation history, token usage, and response details.

Setup

1. Install dependencies

pip install "mirascope[langfuse]"

2. Configure credentials

import os

os.environ["LANGFUSE_PUBLIC_KEY"] = "pk-lf-..."
os.environ["LANGFUSE_SECRET_KEY"] = "sk-lf-..."
os.environ["LANGFUSE_BASE_URL"] = "https://app.getmuster.io"

Standard calls with tools

from mirascope.core import anthropic, prompt_template
from mirascope.integrations.langfuse import with_langfuse


def format_book(title: str, author: str):
    return f"{title} by {author}"


@with_langfuse()
@anthropic.call(model="claude-3-5-sonnet-20240620", tools=[format_book])
@prompt_template("Recommend a {genre} book.")
def recommend_book(genre: str):
    ...


print(recommend_book("fantasy"))

Streaming responses

from mirascope.core import openai, prompt_template
from mirascope.integrations.langfuse import with_langfuse


@with_langfuse()
@openai.call(
    model="gpt-4o-mini",
    stream=True,
    call_params={"stream_options": {"include_usage": True}},
)
@prompt_template("Recommend a {genre} book.")
def recommend_book(genre: str):
    ...


for chunk, _ in recommend_book("fantasy"):
    print(chunk.content, end="", flush=True)

Some providers require specific call_params configuration for usage tracking when streaming.

See also