llm_intent_classifier#

class besser.bot.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 bot

  • 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

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]

predict_huggingface(prompt)[source]#

Send the prompt to the HuggingFace (local) LLM.

Parameters:

prompt (str) – the input prompt

Returns:

the intent predictions

Return type:

dict[str, dict]

predict_huggingface_inference_api(prompt)[source]#

Send the prompt to the HuggingFace Inference API LLM.

Parameters:

prompt (str) – the input prompt

Returns:

the intent predictions

Return type:

dict[str, dict]

predict_openai(prompt)[source]#

Send the prompt to the OpenAI LLM.

Parameters:

prompt (str) – the input prompt

Returns:

the intent predictions

Return type:

dict[str, dict]

predict_replicate(prompt)[source]#

Send the prompt to the Replicate LLM.

Parameters:

prompt (str) – the input prompt

Returns:

the intent predictions

Return type:

dict[str, dict]

train()[source]#

Train the intent classifier.