databricks-logo

    evaluation_genai

    (Python)
    Loading...

    This notebook should only be run in a Databricks Job, as part of MLflow 3.0 Deployment Jobs.

    2
    %pip install databricks-agents
    %pip install mlflow --upgrade
    dbutils.library.restartPython()
    3
    import pandas as pd
    
    eval_df = pd.DataFrame([
      {"inputs": {"question": "What is MLflow Tracking and how does it work?"}},
      {"inputs": {"question": "What is Unity Catalog?"}},
      {"inputs": {"question": "What are user-defined functions (UDFs)?"}}
    ])
    4
    import os
    
    # REQUIRED: set the OpenAI API key here
    os.environ["OPENAI_API_KEY"] = "..."
    5
    # Go to your git folder and checkout the branch with your app
    %cd /your-folder
    !git checkout your-branch
    6
    from openai import OpenAI
    
    from mlflow.genai.scorers import RelevanceToQuery
    import mlflow
    
    # REQUIRED: import your app here
    from ... import openai_app
    
    # REQUIRED: add evaluation data here
    data = eval_df
    
    mlflow.genai.evaluate(
        data=eval_df,
        predict_fn=openai_app,
        scorers=[RelevanceToQuery()]
    )
    ;