Code
The following code creates a function that classifies the sentiment of a given text on a scale from 0 (very negative) to 1 (very positive). It uses a GPT-4o mini model for classification and leverages ControlFlow’s task running and result validation features.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 sentiment analysis.
-
Result types: We specify
result_type=float
to ensure the sentiment score is returned as a float value. -
Result validation: The
result_validator
parameter is used with thebetween()
function to ensure the result falls within the expected range. -
Context passing: The
context
parameter is used to pass the input text to the task.