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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file snowglobe_telemetry_mlflow-0.0.1.tar.gz.
File metadata
- Download URL: snowglobe_telemetry_mlflow-0.0.1.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aaaa29d628660cb75fe470c11175e85bed9b39a3e1428f012f232bb9a712729a
|
|
| MD5 |
9696215625bc11381ed3ae2928045021
|
|
| BLAKE2b-256 |
e7a2a8dd911590b3902e1518851a311de93ad58d8e70db9d270273ee15761969
|
File details
Details for the file snowglobe_telemetry_mlflow-0.0.1-py3-none-any.whl.
File metadata
- Download URL: snowglobe_telemetry_mlflow-0.0.1-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed7ab72f951f4fa781d9e3adcfbf39341d308994b94eeebd5af37b78f0fa8e4e
|
|
| MD5 |
634f216f0ebc2317191426f9c6414ce2
|
|
| BLAKE2b-256 |
c0170af3aeaf123dacc78af04cffdc8dc25ca740efdfb1a99815862c9b6f2a35
|