Pretty tricky! You can use an LLM to maybe predict a structured object
from pydantic.v1 import BaseModel, Field
from typing import Literal
IntentTypes = Literal["BOOKING", "QUIT", "ANGRY", ...]
class Intent(BaseModel):
"""The intent behind a piece of text."""
intent: IntentTypes = Field(description="The type of intent that best represents a piece of text. Make sure to only use a valid intent type: ['BOOKING', 'QUIT', 'ANGRY', ...]"
explanation: str = Field(description="An explanation for your choice of intent.")
from llama_index.core.prompts import PromptTemplate
from llama_index.llms.openai import OpenAI
llm = OpenAI()
prompt = PromptTemplate("Here is some context, give me an intent: {context}")
intent = llm.structured_predict(Intent, prompt, context="...")
print(intent)