Skip to main content

Opik integration adapter for Metrics Computation Engine

Project description

MCE Opik Adapter

A Python adapter library that integrates Opik metrics as third-party plugins for the Metric Computation Engine (MCE). This adapter enables seamless use of Opik's LLM evaluation metrics within the MCE framework for evaluating agentic applications.

Installation

Install via MCE extras:

pip install "metrics-computation-engine[opik]"

Prerequisites

Supported Opik Metrics

The following Opik metrics are supported by this adapter (use with the opik. prefix in service payloads):

Metric Name Description
Hallucination Evaluates whether the model response contains hallucinations
Sentiment Measures the sentiment of a model response

For requests to support additional Opik metrics, please file an issue in our repo: agntcy/telemetry-hub.

Usage

Basic Usage

import asyncio
from mce_opik_adapter.adapter import OpikMetricAdapter
from metrics_computation_engine.models.requests import LLMJudgeConfig
from metrics_computation_engine.registry import MetricRegistry

# Initialize LLM configuration
llm_config = LLMJudgeConfig(
    LLM_BASE_MODEL_URL="https://api.openai.com/v1",
    LLM_MODEL_NAME="gpt-4o",
    LLM_API_KEY="your-api-key-here"
)

# Create registry and register Opik metrics
registry = MetricRegistry()

# Method 1: Direct registration with metric name
registry.register_metric(OpikMetricAdapter, "Hallucination")

# Method 2: Using get_metric_class helper with prefix
from metrics_computation_engine.util import get_metric_class
metric, metric_name = get_metric_class("opik.Hallucination")
registry.register_metric(metric, metric_name)

Using with MCE REST API

When using the MCE as a service, include Opik metrics in your API request:

{
  "metrics": [
    "opik.Hallucination",
    "opik.Sentiment"
  ],
  "llm_judge_config": {
    "LLM_API_KEY": "your-api-key",
    "LLM_MODEL_NAME": "gpt-4o",
    "LLM_BASE_MODEL_URL": "https://api.openai.com/v1"
  },
  "data_fetching_infos": {
    "batch_config": {
      "time_range": { "start": "2024-01-01T00:00:00Z", "end": "2024-12-31T23:59:59Z" }
    },
    "session_ids": []
  }
}

Contributing

Contributions are welcome! Please follow these steps to contribute:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Commit your changes (git commit -am 'Add new feature').
  4. Push to the branch (git push origin feature-branch).
  5. Create a new Pull Request.

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

mce_opik_adapter-0.1.2.tar.gz (387.8 kB view details)

Uploaded Source

Built Distribution

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

mce_opik_adapter-0.1.2-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file mce_opik_adapter-0.1.2.tar.gz.

File metadata

  • Download URL: mce_opik_adapter-0.1.2.tar.gz
  • Upload date:
  • Size: 387.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mce_opik_adapter-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1db50febd6e81be4a6da4908d7edf0187f23cccb82fe6f402d7bd84e6191f7b1
MD5 2cf1870d3445acdb985abe98c3aa7b13
BLAKE2b-256 77ee22b3c913354316e485ec51bc4f16649011e82795fb4d3e0c00b3c4db1a9b

See more details on using hashes here.

File details

Details for the file mce_opik_adapter-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for mce_opik_adapter-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7b0a920906a3564614e12bf03bb498c86b9bd3374326b945a32c2cfe359c4449
MD5 c8b28d6c87ae474dbb463f6d6bc7b501
BLAKE2b-256 23ab02349eae3578247184b709af7948e7e6f34208a3552422fdd899d32aa511

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