IBM WatsonX Integration

Lunary has partnered with IBM to provide a seamless integration for monitoring WatsonX calls in your Python app.

Our Python SDK includes automatic integration with IBM WatsonX's foundation models using Lunary.

1

Setup the SDK

First, ensure you have installed the IBM WatsonX SDK and Lunary. Set your environment variables for IBM authentication.

pip install ibm-watsonx-ai lunary

Configure your environment variables:

  • IBM_API_KEY: your IBM API key
  • IBM_PROJECT_ID: your IBM project id

2

Monitor IBM WatsonX calls

Wrap your WatsonX model instance with Lunary's monitor method to automatically track your calls.

import os
from ibm_watsonx_ai import Credentials
from ibm_watsonx_ai.foundation_models import ModelInference
import lunary

model = ModelInference(
    model_id="meta-llama/llama-3-1-8b-instruct",
    credentials=Credentials(
        api_key=os.environ.get("IBM_API_KEY"),
        url="https://us-south.ml.cloud.ibm.com"
    ),
    project_id=os.environ.get("IBM_PROJECT_ID")
)

lunary.monitor(model)

messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Who won the world series in 2020?"}
]

response = model.chat(messages=messages)

3

Tag requests and identify users

Optionally, pass extra parameters to track details such as tags and user information by including additional arguments to the chat call.

response = model.chat(messages=messages, tags=["baseball"], user_id="1234", user_props={"name": "Alice"})

Questions? We're here to help.

Email