NEW OpenAI Structured Outputs with Label Studio 🚀

Langchain search agent

This example demonstrates how to use Label Studio with a custom Machine Learning backend.

It uses a Langchain-based agent that accepts a text input, searches for Google, and returns the answer based on the search results (a.k.a Retrieval Augmented Generation).

Before you begin

Before you begin, you must install the Label Studio ML backend.

This tutorial uses the langchain_search_agent example.

Prerequisites

To use the Google search engine, you need to have a Google Custom Search Engine (CSE) API key and a search engine ID.

GOOGLE_API_KEY=<your_google_api_key>
GOOGLE_CSE_ID=<your_google_search_engine_id>

For more information, see Programmable Search Engine ID.

Use OpenAI

To use OpenAI, you need to have an OpenAI API key.

OPENAI_API_KEY=<your_openai_api_key>

For more information, see Where do I find my OpenAI API Key?.

Labeling interface

The labeling interface must include:

  • Input prompt
  • LLM response
  • Search results snippets
  • Classification labels

Example


<View>
    <Style>
        .lsf-main-content.lsf-requesting .prompt::before { content: ' loading...'; color: #808080; }
    </Style>
    <Text name="input" value="$text"/>
    <View className="prompt">
        <TextArea name="prompt" toName="input" maxSubmissions="1" editable="true"/>
    </View>
    <TextArea name="response" toName="input" maxSubmissions="1" editable="true"/>
    <TextArea name="snippets" toName="input"/>
    <Choices name="classification" toName="input" choice="single" showInLine="true">
        <Choice value="Good"/>
        <Choice value="Bad"/>
    </Choices>
</View>

Quickstart

  1. Build and start the Machine Learning backend on http://localhost:9090:
docker-compose up
  1. Validate that the backend is running:
$ curl http://localhost:9090/health
{"status":"UP"}
  1. Create a project in Label Studio. Then from the Model page in the project settings, connect the model. The default URL is http://localhost:9090.