Intent Classifier with Function Calling

I've mentioned the use of intent classifier in the Don't boil the ocean article in March 2024. By that time I was using few shots prompting to influence the response to follow my defined JSON schema. Here's is a more robust alternative using function calling[1].

Steps:

  1. Select a LLM which supports function calling
  2. Create tool definitions - one for each intent
  3. Invoke the LLM and force tool use

I'm using Mistral Large in this example. The goal is to categorise user intention into one of the groups: 1/ greetings, 2/ harmful, or 3/ others.

tools = [
    {
        "type": "function",
        "function": {
            "name": "greetings",
            "description": "Handler of user greetings",
            "parameters": {
                "type": "object",
            },
        },
    },
    {
        "type": "function",
        "function": {
            "name": "harmful",
            "description": "Handler of harmful conversation",
            "parameters": {
                "type": "object",
            },
        },
    },
    {
        "type": "function",
        "function": {
            "name": "others",
            "description": "Handler of everything else not specified in other tools",
            "parameters": {
                "type": "object",
            },
        },
    },
]        

When invoking the model, make sure to specify tool_choice to any to force tool use instead of generating text response.


[1] Function calling - https://docs.mistral.ai/capabilities/function_calling/


To view or add a comment, sign in

More articles by Corvus L.

Explore content categories