From 98310fecace2dd5f2bb0342dd93e0e91b7da0c40 Mon Sep 17 00:00:00 2001 From: Wesley Lima Date: Mon, 3 Nov 2025 12:49:56 -0500 Subject: [PATCH] Adding tutorial for multi-turn ai chat --- ...i_chat_using_label_studio_enterprise.ipynb | 1288 +++++++++++++++++ 1 file changed, 1288 insertions(+) create mode 100644 tutorials/multi_turn_feedback_for_ai_chat_using_label_studio_enterprise/multi_turn_feedback_for_ai_chat_using_label_studio_enterprise.ipynb diff --git a/tutorials/multi_turn_feedback_for_ai_chat_using_label_studio_enterprise/multi_turn_feedback_for_ai_chat_using_label_studio_enterprise.ipynb b/tutorials/multi_turn_feedback_for_ai_chat_using_label_studio_enterprise/multi_turn_feedback_for_ai_chat_using_label_studio_enterprise.ipynb new file mode 100644 index 0000000..3d2c13b --- /dev/null +++ b/tutorials/multi_turn_feedback_for_ai_chat_using_label_studio_enterprise/multi_turn_feedback_for_ai_chat_using_label_studio_enterprise.ipynb @@ -0,0 +1,1288 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "8b187611", + "metadata": { + "id": "8b187611" + }, + "source": [ + "# Multi-turn Feedback for AI Chat using Label Studio Enterprise\n", + "\n", + "This notebook demonstrates how to create a Label Studio Enterprise project for evaluating chatbot conversations using the Chatbot Evaluation template.\n", + "\n", + "The allows you to:\n", + "- Review multi-turn conversations\n", + "- Rate assistant responses for accuracy, clarity, and helpfulness\n", + "- Evaluate grounding in documentation\n", + "- Assess tone and style\n", + "- Track whether questions were answered\n", + "\n", + "Reference: [Chatbot Evaluation Template](https://docs.humansignal.com/templates/chatbot)" + ] + }, + { + "cell_type": "markdown", + "id": "f3a5bae0", + "metadata": { + "id": "f3a5bae0" + }, + "source": [ + "## Setup and Installation\n", + "\n", + "First, install the Label Studio SDK if you haven't already.\n", + "\n", + "For more information about the SDK, see the [Label Studio Python SDK documentation](https://labelstud.io/guide/sdk).\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "eb1c5401", + "metadata": { + "vscode": { + "languageId": "shellscript" + }, + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "eb1c5401", + "outputId": "71d09d2c-1acb-4c0e-81aa-d55abc408ce5" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Collecting label-studio-sdk\n", + " Downloading label_studio_sdk-2.0.11-py3-none-any.whl.metadata (7.0 kB)\n", + "Requirement already satisfied: Pillow>=11.3.0 in /usr/local/lib/python3.12/dist-packages (from label-studio-sdk) (11.3.0)\n", + "Collecting appdirs>=1.4.3 (from label-studio-sdk)\n", + " Downloading appdirs-1.4.4-py2.py3-none-any.whl.metadata (9.0 kB)\n", + "Collecting datamodel-code-generator==0.26.1 (from label-studio-sdk)\n", + " Downloading datamodel_code_generator-0.26.1-py3-none-any.whl.metadata (24 kB)\n", + "Requirement already satisfied: httpx>=0.21.2 in /usr/local/lib/python3.12/dist-packages (from label-studio-sdk) (0.28.1)\n", + "Collecting ijson>=3.2.3 (from label-studio-sdk)\n", + " Downloading ijson-3.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (21 kB)\n", + "Collecting jsf<0.12.0,>=0.11.2 (from label-studio-sdk)\n", + " Downloading jsf-0.11.2-py3-none-any.whl.metadata (5.0 kB)\n", + "Requirement already satisfied: jsonschema>=4.23.0 in /usr/local/lib/python3.12/dist-packages (from label-studio-sdk) (4.25.1)\n", + "Requirement already satisfied: lxml>=4.2.5 in /usr/local/lib/python3.12/dist-packages (from label-studio-sdk) (5.4.0)\n", + "Requirement already satisfied: nltk<4.0.0,>=3.9.1 in /usr/local/lib/python3.12/dist-packages (from label-studio-sdk) (3.9.1)\n", + "Requirement already satisfied: numpy<3.0.0,>=1.26.4 in /usr/local/lib/python3.12/dist-packages (from label-studio-sdk) (2.0.2)\n", + "Requirement already satisfied: opencv-python<5.0.0,>=4.12.0 in /usr/local/lib/python3.12/dist-packages (from label-studio-sdk) (4.12.0.88)\n", + "Requirement already satisfied: pandas>=0.24.0 in /usr/local/lib/python3.12/dist-packages (from label-studio-sdk) (2.2.2)\n", + "Requirement already satisfied: pydantic>=1.9.2 in /usr/local/lib/python3.12/dist-packages (from label-studio-sdk) (2.11.9)\n", + "Requirement already satisfied: pydantic-core<3.0.0,>=2.18.2 in /usr/local/lib/python3.12/dist-packages (from label-studio-sdk) (2.33.2)\n", + "Requirement already satisfied: pyjwt<3.0.0,>=2.10.1 in /usr/local/lib/python3.12/dist-packages (from label-studio-sdk) (2.10.1)\n", + "Requirement already satisfied: requests>=2.22.0 in /usr/local/lib/python3.12/dist-packages (from label-studio-sdk) (2.32.4)\n", + "Collecting requests-mock==1.12.1 (from label-studio-sdk)\n", + " Downloading requests_mock-1.12.1-py2.py3-none-any.whl.metadata (4.1 kB)\n", + "Requirement already satisfied: typing_extensions>=4.0.0 in /usr/local/lib/python3.12/dist-packages (from label-studio-sdk) (4.15.0)\n", + "Collecting ujson>=5.8.0 (from label-studio-sdk)\n", + " Downloading ujson-5.11.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.metadata (9.4 kB)\n", + "Requirement already satisfied: urllib3>=2.5.0 in /usr/local/lib/python3.12/dist-packages (from label-studio-sdk) (2.5.0)\n", + "Collecting xmljson==0.2.1 (from label-studio-sdk)\n", + " Downloading xmljson-0.2.1-py2.py3-none-any.whl.metadata (12 kB)\n", + "Collecting argcomplete<4.0,>=1.10 (from datamodel-code-generator==0.26.1->label-studio-sdk)\n", + " Downloading argcomplete-3.6.2-py3-none-any.whl.metadata (16 kB)\n", + "Collecting black>=19.10b0 (from datamodel-code-generator==0.26.1->label-studio-sdk)\n", + " Downloading black-25.9.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl.metadata (83 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m83.5/83.5 kB\u001b[0m \u001b[31m3.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting genson<2.0,>=1.2.1 (from datamodel-code-generator==0.26.1->label-studio-sdk)\n", + " Downloading genson-1.3.0-py3-none-any.whl.metadata (28 kB)\n", + "Collecting inflect<6.0,>=4.1.0 (from datamodel-code-generator==0.26.1->label-studio-sdk)\n", + " Downloading inflect-5.6.2-py3-none-any.whl.metadata (21 kB)\n", + "Collecting isort<6.0,>=4.3.21 (from datamodel-code-generator==0.26.1->label-studio-sdk)\n", + " Downloading isort-5.13.2-py3-none-any.whl.metadata (12 kB)\n", + "Requirement already satisfied: jinja2<4.0,>=2.10.1 in /usr/local/lib/python3.12/dist-packages (from datamodel-code-generator==0.26.1->label-studio-sdk) (3.1.6)\n", + "Requirement already satisfied: packaging in /usr/local/lib/python3.12/dist-packages (from datamodel-code-generator==0.26.1->label-studio-sdk) (25.0)\n", + "Requirement already satisfied: pyyaml>=6.0.1 in /usr/local/lib/python3.12/dist-packages (from datamodel-code-generator==0.26.1->label-studio-sdk) (6.0.3)\n", + "Requirement already satisfied: anyio in /usr/local/lib/python3.12/dist-packages (from httpx>=0.21.2->label-studio-sdk) (4.11.0)\n", + "Requirement already satisfied: certifi in /usr/local/lib/python3.12/dist-packages (from httpx>=0.21.2->label-studio-sdk) (2025.8.3)\n", + "Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.12/dist-packages (from httpx>=0.21.2->label-studio-sdk) (1.0.9)\n", + "Requirement already satisfied: idna in /usr/local/lib/python3.12/dist-packages (from httpx>=0.21.2->label-studio-sdk) (3.10)\n", + "Requirement already satisfied: h11>=0.16 in /usr/local/lib/python3.12/dist-packages (from httpcore==1.*->httpx>=0.21.2->label-studio-sdk) (0.16.0)\n", + "Collecting faker>=15.3.4 (from jsf<0.12.0,>=0.11.2->label-studio-sdk)\n", + " Downloading faker-37.8.0-py3-none-any.whl.metadata (15 kB)\n", + "Collecting rstr>=3.2.0 (from jsf<0.12.0,>=0.11.2->label-studio-sdk)\n", + " Downloading rstr-3.2.2-py3-none-any.whl.metadata (7.1 kB)\n", + "Requirement already satisfied: smart-open>=6.3.0 in /usr/local/lib/python3.12/dist-packages (from smart-open[http]>=6.3.0->jsf<0.12.0,>=0.11.2->label-studio-sdk) (7.3.1)\n", + "Requirement already satisfied: attrs>=22.2.0 in /usr/local/lib/python3.12/dist-packages (from jsonschema>=4.23.0->label-studio-sdk) (25.3.0)\n", + "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /usr/local/lib/python3.12/dist-packages (from jsonschema>=4.23.0->label-studio-sdk) (2025.9.1)\n", + "Requirement already satisfied: referencing>=0.28.4 in /usr/local/lib/python3.12/dist-packages (from jsonschema>=4.23.0->label-studio-sdk) (0.36.2)\n", + "Requirement already satisfied: rpds-py>=0.7.1 in /usr/local/lib/python3.12/dist-packages (from jsonschema>=4.23.0->label-studio-sdk) (0.27.1)\n", + "Requirement already satisfied: click in /usr/local/lib/python3.12/dist-packages (from nltk<4.0.0,>=3.9.1->label-studio-sdk) (8.3.0)\n", + "Requirement already satisfied: joblib in /usr/local/lib/python3.12/dist-packages (from nltk<4.0.0,>=3.9.1->label-studio-sdk) (1.5.2)\n", + "Requirement already satisfied: regex>=2021.8.3 in /usr/local/lib/python3.12/dist-packages (from nltk<4.0.0,>=3.9.1->label-studio-sdk) (2024.11.6)\n", + "Requirement already satisfied: tqdm in /usr/local/lib/python3.12/dist-packages (from nltk<4.0.0,>=3.9.1->label-studio-sdk) (4.67.1)\n", + "Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.12/dist-packages (from pandas>=0.24.0->label-studio-sdk) (2.9.0.post0)\n", + "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.12/dist-packages (from pandas>=0.24.0->label-studio-sdk) (2025.2)\n", + "Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.12/dist-packages (from pandas>=0.24.0->label-studio-sdk) (2025.2)\n", + "Requirement already satisfied: annotated-types>=0.6.0 in /usr/local/lib/python3.12/dist-packages (from pydantic>=1.9.2->label-studio-sdk) (0.7.0)\n", + "Requirement already satisfied: typing-inspection>=0.4.0 in /usr/local/lib/python3.12/dist-packages (from pydantic>=1.9.2->label-studio-sdk) (0.4.2)\n", + "Requirement already satisfied: charset_normalizer<4,>=2 in /usr/local/lib/python3.12/dist-packages (from requests>=2.22.0->label-studio-sdk) (3.4.3)\n", + "Collecting mypy-extensions>=0.4.3 (from black>=19.10b0->datamodel-code-generator==0.26.1->label-studio-sdk)\n", + " Downloading mypy_extensions-1.1.0-py3-none-any.whl.metadata (1.1 kB)\n", + "Collecting pathspec>=0.9.0 (from black>=19.10b0->datamodel-code-generator==0.26.1->label-studio-sdk)\n", + " Downloading pathspec-0.12.1-py3-none-any.whl.metadata (21 kB)\n", + "Requirement already satisfied: platformdirs>=2 in /usr/local/lib/python3.12/dist-packages (from black>=19.10b0->datamodel-code-generator==0.26.1->label-studio-sdk) (4.4.0)\n", + "Collecting pytokens>=0.1.10 (from black>=19.10b0->datamodel-code-generator==0.26.1->label-studio-sdk)\n", + " Downloading pytokens-0.1.10-py3-none-any.whl.metadata (2.0 kB)\n", + "Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.12/dist-packages (from jinja2<4.0,>=2.10.1->datamodel-code-generator==0.26.1->label-studio-sdk) (3.0.3)\n", + "Collecting email-validator>=2.0.0 (from pydantic[email]!=2.0.0,!=2.0.1,!=2.4.0,<3.0,>=1.10.0; python_version >= \"3.12\" and python_version < \"4.0\"->datamodel-code-generator==0.26.1->label-studio-sdk)\n", + " Downloading email_validator-2.3.0-py3-none-any.whl.metadata (26 kB)\n", + "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.12/dist-packages (from python-dateutil>=2.8.2->pandas>=0.24.0->label-studio-sdk) (1.17.0)\n", + "Requirement already satisfied: wrapt in /usr/local/lib/python3.12/dist-packages (from smart-open>=6.3.0->smart-open[http]>=6.3.0->jsf<0.12.0,>=0.11.2->label-studio-sdk) (1.17.3)\n", + "Requirement already satisfied: sniffio>=1.1 in /usr/local/lib/python3.12/dist-packages (from anyio->httpx>=0.21.2->label-studio-sdk) (1.3.1)\n", + "Collecting dnspython>=2.0.0 (from email-validator>=2.0.0->pydantic[email]!=2.0.0,!=2.0.1,!=2.4.0,<3.0,>=1.10.0; python_version >= \"3.12\" and python_version < \"4.0\"->datamodel-code-generator==0.26.1->label-studio-sdk)\n", + " Downloading dnspython-2.8.0-py3-none-any.whl.metadata (5.7 kB)\n", + "Downloading label_studio_sdk-2.0.11-py3-none-any.whl (600 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m600.3/600.3 kB\u001b[0m \u001b[31m14.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading datamodel_code_generator-0.26.1-py3-none-any.whl (111 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m111.0/111.0 kB\u001b[0m \u001b[31m4.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading requests_mock-1.12.1-py2.py3-none-any.whl (27 kB)\n", + "Downloading xmljson-0.2.1-py2.py3-none-any.whl (10 kB)\n", + "Downloading appdirs-1.4.4-py2.py3-none-any.whl (9.6 kB)\n", + "Downloading ijson-3.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (148 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m148.3/148.3 kB\u001b[0m \u001b[31m3.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading jsf-0.11.2-py3-none-any.whl (49 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.3/49.3 kB\u001b[0m \u001b[31m1.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading ujson-5.11.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (57 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m57.4/57.4 kB\u001b[0m \u001b[31m3.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading argcomplete-3.6.2-py3-none-any.whl (43 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m43.7/43.7 kB\u001b[0m \u001b[31m2.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading black-25.9.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (1.7 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.7/1.7 MB\u001b[0m \u001b[31m44.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading faker-37.8.0-py3-none-any.whl (2.0 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.0/2.0 MB\u001b[0m \u001b[31m52.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading genson-1.3.0-py3-none-any.whl (21 kB)\n", + "Downloading inflect-5.6.2-py3-none-any.whl (33 kB)\n", + "Downloading isort-5.13.2-py3-none-any.whl (92 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m92.3/92.3 kB\u001b[0m \u001b[31m4.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading rstr-3.2.2-py3-none-any.whl (10 kB)\n", + "Downloading email_validator-2.3.0-py3-none-any.whl (35 kB)\n", + "Downloading mypy_extensions-1.1.0-py3-none-any.whl (5.0 kB)\n", + "Downloading pathspec-0.12.1-py3-none-any.whl (31 kB)\n", + "Downloading pytokens-0.1.10-py3-none-any.whl (12 kB)\n", + "Downloading dnspython-2.8.0-py3-none-any.whl (331 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m331.1/331.1 kB\u001b[0m \u001b[31m18.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hInstalling collected packages: xmljson, genson, appdirs, ujson, rstr, pytokens, pathspec, mypy-extensions, isort, inflect, ijson, faker, dnspython, argcomplete, requests-mock, email-validator, black, jsf, datamodel-code-generator, label-studio-sdk\n", + " Attempting uninstall: inflect\n", + " Found existing installation: inflect 7.5.0\n", + " Uninstalling inflect-7.5.0:\n", + " Successfully uninstalled inflect-7.5.0\n", + "Successfully installed appdirs-1.4.4 argcomplete-3.6.2 black-25.9.0 datamodel-code-generator-0.26.1 dnspython-2.8.0 email-validator-2.3.0 faker-37.8.0 genson-1.3.0 ijson-3.4.0 inflect-5.6.2 isort-5.13.2 jsf-0.11.2 label-studio-sdk-2.0.11 mypy-extensions-1.1.0 pathspec-0.12.1 pytokens-0.1.10 requests-mock-1.12.1 rstr-3.2.2 ujson-5.11.0 xmljson-0.2.1\n" + ] + } + ], + "source": [ + "%pip install label-studio-sdk" + ] + }, + { + "cell_type": "markdown", + "id": "e39a041e", + "metadata": { + "id": "e39a041e" + }, + "source": [ + "## Configure Credentials\n", + "To support loading credentials from Google Colab Secrets with fallback to .env and environment sourced variables the following cell can be used." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "85a7aa7b", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "85a7aa7b", + "outputId": "97cc6c56-5546-4387-ffac-225ccaeb13f5" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Requirement already satisfied: python-dotenv in /usr/local/lib/python3.12/dist-packages (1.1.1)\n" + ] + } + ], + "source": [ + "%pip install python-dotenv\n", + "\n", + "# Load configuration with Google Colab Secrets support + fallback\n", + "IS_GOOGLE_COLAB = False\n", + "\n", + "# Load from .env file if available (for local development)\n", + "try:\n", + " from dotenv import load_dotenv\n", + " load_dotenv()\n", + "except:\n", + " pass # will use system env vars\n", + "\n", + "def get_credential(key, default=None):\n", + " global IS_GOOGLE_COLAB\n", + " \"\"\"Get credential from Colab Secrets first, then environment variables\"\"\"\n", + " try:\n", + " # Try Google Colab Secrets first (most secure)\n", + " from google.colab import userdata\n", + " IS_GOOGLE_COLAB = True\n", + " return userdata.get(key)\n", + " except:\n", + " from os import environ\n", + " IS_GOOGLE_COLAB = False\n", + " # Fallback to environment variables (for local Jupyter)\n", + " return environ.get(key, default)" + ] + }, + { + "cell_type": "markdown", + "id": "1430bf66", + "metadata": { + "id": "1430bf66" + }, + "source": [ + "Set your environment variables before running:\n", + "\n", + "```bash\n", + "export LABEL_STUDIO_URL=\"https://app.humansignal.com\" # or your Label Studio URL\n", + "export LABEL_STUDIO_API_KEY=\"your-api-key-here\"\n", + "```\n", + "\n", + "**How to get your API key:**\n", + "1. Open Label Studio in your browser\n", + "2. Click on your profile (top-right)\n", + "3. Go to \"Account & Settings\"\n", + "4. Click \"Access Token\" (or \"Personal Access Token\")\n", + "5. Copy the existing token or create a new one\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "35f4e423", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 211 + }, + "id": "35f4e423", + "outputId": "8b03126e-b135-492a-d95f-dfb99457d1f5" + }, + "outputs": [ + { + "output_type": "error", + "ename": "ValueError", + "evalue": "❌ Please set LABEL_STUDIO_API_KEY environment variable.", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/tmp/ipython-input-3282658643.py\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mls_api_key\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 9\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'❌ Please set LABEL_STUDIO_API_KEY environment variable.'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 10\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 11\u001b[0m \u001b[0;31m# Connect to Label Studio\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mValueError\u001b[0m: ❌ Please set LABEL_STUDIO_API_KEY environment variable." + ] + } + ], + "source": [ + "import os\n", + "from label_studio_sdk import LabelStudio\n", + "\n", + "# Get credentials from environment variables\n", + "ls_api_key = os.environ.get('LABEL_STUDIO_API_KEY')\n", + "ls_url = os.environ.get('LABEL_STUDIO_URL', 'https://app.humansignal.com')\n", + "\n", + "if not ls_api_key:\n", + " raise ValueError('❌ Please set LABEL_STUDIO_API_KEY environment variable.')\n", + "\n", + "# Connect to Label Studio\n", + "try:\n", + " ls = LabelStudio(base_url=ls_url, api_key=ls_api_key)\n", + " print(f'✅ Connected to Label Studio at {ls_url}')\n", + "except Exception as e:\n", + " raise ConnectionError(f'❌ Failed to connect to Label Studio: {str(e)}')\n" + ] + }, + { + "cell_type": "markdown", + "id": "0fa79674", + "metadata": { + "id": "0fa79674" + }, + "source": [ + "## Define the Chatbot Evaluation Label Config\n", + "\n", + "This is the label config from the [Evaluate Production Conversations for RLHF\n", + "](https://docs.humansignal.com/templates/chat_rlhf) example. It includes:\n", + "- A chat interface for viewing conversations\n", + "- Overall quality of message rating\n", + "- Additinal comments" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "075fd9a6", + "metadata": { + "id": "075fd9a6", + "outputId": "9e8722a9-3a59-44e3-cb6e-7d9906b90f9a" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Label config loaded successfully\n" + ] + } + ], + "source": [ + "LABEL_CONFIG = \"\"\"\n", + "\n", + " \n", + " \n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + " \n", + "\n", + " \n", + " \n", + " \n", + "\n", + " \n", + " \n", + "
Overall quality of this conversation
\n", + " \n", + " \n", + " \n", + "