Skip to main content

MLflow instrumentation for the snowglobe client

Project description

Snowlgobe Telemetry Instrumentation for MLflow

Instrument your Snowglobe connected app with MLflow and start collecting insightful traces when you run Simulations in Snowglobe. Read more about MLflow's tracing capability for GenAI Apps here.

Installation

pip install snowglobe-telemetry-mlflow

If using uv, set the --prerelease=allow flag

uv pip install --prerelease=allow snowglobe-telemetry-mlflow

Add the MLflowInstrumentor to your agent file

Reminder: Each agent wrapper file resides in the root directory of your project, and is named after the agent (e.g. My Agent Name becomes my_agent_name.py).

from snowglobe.client import CompletionRequest, CompletionFunctionOutputs
from openai import OpenAI
import os

### Add these two lines to your agent file and watch context rich traces come in!
from snowglobe.telemetry.mlflow import MLflowInstrumentor
MLflowInstrumentor().instrument()


client = OpenAI(api_key=os.getenv("SNOWGLOBE_API_KEY"))

def completion_fn(request: CompletionRequest) -> CompletionFunctionOutputs:
    """
    Process a scenario request from Snowglobe.
    
    This function is called by the Snowglobe client to process requests. It should return a
    CompletionFunctionOutputs object with the response content.

    Example CompletionRequest:
    CompletionRequest(
        messages=[
            SnowglobeMessage(role="user", content="Hello, how are you?", snowglobe_data=None),
        ]
    )

    Example CompletionFunctionOutputs:
    CompletionFunctionOutputs(response="This is a string response from your application")
    
    Args:
        request (CompletionRequest): The request object containing the messages.

    Returns:
        CompletionFunctionOutputs: The response object with the generated content.
    """

    # Process the request using the messages. Example:
    messages = request.to_openai_messages()
    response = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=messages
    )
    return CompletionFunctionOutputs(response=response.choices[0].message.content)

Enhancing Snowglobe Connect SDK's Traces with Autologging

You can turn on mlflow autologging in your app to add additional context to the traces the Snowglobe Connect SDK captures. In your agent wrapper file, simply call the appropriate autolog method for the LLM provider you're using. The below example shows how to enable this for OpenAI:

import mlflow

mlflow.openai.autolog()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

snowglobe_telemetry_mlflow-0.0.0a0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

snowglobe_telemetry_mlflow-0.0.0a0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file snowglobe_telemetry_mlflow-0.0.0a0.tar.gz.

File metadata

File hashes

Hashes for snowglobe_telemetry_mlflow-0.0.0a0.tar.gz
Algorithm Hash digest
SHA256 de097d9308151fa43106ba663c24a91f66c3c626d2388191450c426decb2b2b6
MD5 a9fda484e77bfcb0603edc64a1b07544
BLAKE2b-256 a2caa9a7e0fc50d2e01fe792b0cfe00ae54413b10bf36822c44a980d026aa0e5

See more details on using hashes here.

File details

Details for the file snowglobe_telemetry_mlflow-0.0.0a0-py3-none-any.whl.

File metadata

File hashes

Hashes for snowglobe_telemetry_mlflow-0.0.0a0-py3-none-any.whl
Algorithm Hash digest
SHA256 eaea80598d36635432c895443e7adb5b822b79bf03a52c2a906ff11945a59e75
MD5 8c3843d87bf2e00a068ac635071bd4c1
BLAKE2b-256 a55cf4ce01a16cbebb28b4d94c1f4034f65abc5346f49411483b3c35af5187ec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page