← Back to changelog
May 16, 2024

Mirascope integration

Picture Marc KlingenMarc Klingen

Mirascope is a Python toolkit for building LLM applications and it natively integrates with Langfuse.

Mirascope automatically passes the Langfuse observe() decorator to all relevant functions within Mirascope via its with_langfuse decorator.

import os
from mirascope.langfuse import with_langfuse
from mirascope.anthropic import AnthropicCall
 
os.environ["LANGFUSE_SECRET_KEY"] = "sk-lf-..."
os.environ["LANGFUSE_PUBLIC_KEY"] = "pk-lf-..."
os.environ["LANGFUSE_HOST"] = "https://cloud.langfuse.com"
 
 
@with_langfuse
class BookRecommender(AnthropicCall):
    prompt_template = "Please recommend some {genre} books"
 
    genre: str
 
 
recommender = BookRecommender(genre="fantasy")
response = recommender.call()  # this will automatically get logged with langfuse
print(response.content)
#> Here are some recommendations for great fantasy book series: ...

This will give you:

  • A trace around the AnthropicCall.call() that captures items like the prompt template, and input/output attributes and more.
  • Human-readable display of the conversation with the agent
  • Details of the response, including the number of tokens used

Mirascope Trace call

Learn more

Was this page useful?

Questions? We're here to help

Subscribe to updates