Code
First, let’s implement a function that extracts a simple list of entities:Simple extraction
Categorized extraction
Key concepts
This implementation showcases several important ControlFlow features that enable quick development of NLP tools:-
Agents: We create an agent with a specific LLM model (GPT-4o mini) to perform the named entity recognition.
-
Flexible result types: We demonstrate two different result types: a simple list of strings and a dictionary of categorized entities. This flexibility allows us to adapt the output structure to our specific needs.
-
Detailed instructions: In the categorized version, we provide detailed instructions to guide the model in structuring its output. This allows us to define a specific schema for the results without changing the underlying model.
-
Context passing: The
context
parameter is used to pass the input text to the task.