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.2.tar.gz (9.4 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.2-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file snowglobe_telemetry_mlflow-0.0.2.tar.gz.

File metadata

File hashes

Hashes for snowglobe_telemetry_mlflow-0.0.2.tar.gz
Algorithm Hash digest
SHA256 44e42e43cb35a3d83171d07cd429ca7acbb67447c923900b15809642c7caba9b
MD5 17a4c77b438cd47a3ac4b2218947d9ea
BLAKE2b-256 29f8aabd2448edfb4aa89395b49750984c9de74c4e9e655c245cf4f3bdc598cc

See more details on using hashes here.

File details

Details for the file snowglobe_telemetry_mlflow-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for snowglobe_telemetry_mlflow-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b6722a7e9d10f9d019dac80e0b29187cb66ee05207a3a8af3b92827d7c92f5a4
MD5 292b7ee488d011c19d2c2f71aeea88b8
BLAKE2b-256 0d6af63ee1ac6e348609a0c1e37285e55e25ce5c5b45e0f4c4b7bfd7dbb95240

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