POST
/
search
/
query_classifier
/
classify
import PiClient from 'withpi';

const client = new PiClient({
  apiKey: process.env['WITHPI_API_KEY'], // This is the default and can be omitted
});

async function main() {
  const response = await client.search.queryClassifier.classify({
    classes: [
      { description: 'Questions seeking objective, verifiable information or facts', label: 'factual' },
      {
        description: 'Questions asking for subjective judgments, preferences, or personal views',
        label: 'opinion',
      },
      {
        description: 'Questions about how to perform tasks or follow specific processes',
        label: 'procedural',
      },
    ],
    queries: [
      'What is the capital of France?',
      'How do I feel about the current political climate?',
      'What steps should I follow to bake a chocolate cake?',
    ],
  });

  console.log(response.results);
}

main();
{
  "results": [
    {
      "prediction": "<string>",
      "probabilities": [
        {
          "label": "<string>",
          "score": 123
        }
      ],
      "query": "<string>"
    }
  ]
}

Authorizations

x-api-key
string
header
required

Body

application/json
classes
object[]
required

The list of class definitions to classify the queries into. Must be <= 20.

Example:
[
  {
    "description": "Questions seeking objective, verifiable information or facts",
    "label": "factual"
  },
  {
    "description": "Questions asking for subjective judgments, preferences, or personal views",
    "label": "opinion"
  },
  {
    "description": "Questions about how to perform tasks or follow specific processes",
    "label": "procedural"
  }
]
queries
string[]
required

The list of queries to classify. Must be <= 10.

Example:
[
  "What is the capital of France?",
  "How do I feel about the current political climate?",
  "What steps should I follow to bake a chocolate cake?"
]
batch_size
integer
default:5

Number of inputs to generate in one LLM call. Must be <=10.

Required range: 1 <= x <= 10
Example:

10

examples
object[] | null

Optional list of examples to provide as few-shot examples for the classifier. Must be <= 20.

Example:
[
  {
    "label": "factual",
    "text": "When was the Eiffel Tower built?"
  },
  {
    "label": "opinion",
    "text": "Is jazz better than classical music?"
  },
  {
    "label": "procedural",
    "text": "How do I change a flat tire?"
  }
]
mode
enum<string>

The mode to use for the classification. The probabilistic mode returns probabilities for each class.

Available options:
generative,
probabilistic

Response

200
application/json
Successful Response
results
object[]
required