llm_intent_classifier#

class besser.agent.nlp.intent_classifier.llm_intent_classifier.LLMIntentClassifier(nlp_engine, state)[source]#

Bases: IntentClassifier

An LLM-based Intent Classifier.

It sends a prompt to an LLM, indicating how to perform the Intent Classification task and providing the State’s intents and its parameters

Parameters:
  • nlp_engine (NLPEngine) – the NLPEngine that handles the NLP processes of the agent

  • state (State) – the state the intent classifier belongs to

Attributes:

_abc_impl = <_abc._abc_data object>#
_generate_prompt(message)[source]#

Generates the prompt for the LLM giving instructions for the intent classification task.

Parameters:

message (str) – the user message on which the LLM must detect the intent

Returns:

the generated prompt

Return type:

str

default_json_to_intent_classifier_predictions(message, response_json)[source]#

Parse the JSON generated by an LLM to the list of intent classifier prediction objects.

The expected JSON structure is the following:

{
    'intent1': {
            'score': 0.7,
            'parameters': {
                'param1': 'value1',
                'param2': 'value2'
            }
        },
    'intent2': {...}
}
Parameters:
  • message (str) – the original user message sent to the agent

  • response_json (dict) – the LLM generated JSON response containing the intent predictions

Returns:

the list of intent classifier predictions

Return type:

list[IntentClassifierPrediction]

predict(message)[source]#

Predict the intent of a given message.

Instead of returning only the intent with the highest likelihood, return all predictions. Predictions include not only the intent scores but other information extracted from the message.

Parameters:

message (str) – the message to predict the intent

Returns:

the list of predictions made by the intent classifier.

Return type:

list[IntentClassifierPrediction]

train()[source]#

Train the intent classifier.