Advanced Topics

Classifying Text with GPAL.AI

GPAL.AI runs text through a large language model to classify it -- sentiment, spam, intent, and a dozen other built-in categories, or a category you define yourself -- using the same fluent settings-then-execute pattern as the rest of GPAL.

Provider, Task, and Classification Type

GPAL.AI starts the chain. You pick an AI provider, attach credentials if needed, and select the classification task. A built-in set of classification categories -- sentiment, spam, topic, intent, emotion, toxicity, priority, and more -- each come with their own labels and prompt template pre-configured, so you do not need to write a prompt. Picking a category is the only configuration required beyond the provider.

IGPALGrid<string> sentimentResults;

GPAL.AI

.WithProvider(AIProviderType.XAI)

.WithTask(AITask.Classification)

.WithClassificationType(AIClassificationType.Sentiment)

.WithInputFrom("This update made everything so much easier to use!")

.WithOutputTo(out sentimentResults)

.Execute();

Input Sources and Output Targets

WithInputFrom accepts a plain string, a GPALFile, a GPALDatabase, an IGPALGrid<string> (one classification per row), a Uri (the page's text is fetched and classified), or a form control. GPALInput or GPALTextArea. So a form field's contents can be classified as the user types or submits. WithOutputTo mirrors this on the way out: pass an IGPALGrid<string> by out parameter to capture results in code, or pass a GPALFile, GPALDatabase, or GPALTextArea to send results straight there. Each result row holds the label GPAL.AI chose for the corresponding input.

// Classify every row of a feedback export and write the verdicts to a new file

GPAL.AI

.WithProvider(AIProviderType.XAI)

.WithTask(AITask.Classification)

.WithClassificationType(AIClassificationType.Spam)

.WithInputFrom(GPAL.FileFor("feedback.csv"))

.WithOutputTo(GPAL.FileFor("feedback-spam-check.csv"))

.Execute();

TIP

WithInputFrom and WithOutputTo both take a plain object, so the implicit string-to-GPALFile conversion never kicks in. A bare string is treated as literal text to classify (or an unsupported output target), not a file path. Use GPAL.FileFor(path) whenever the source or destination is a file.

Custom Classifications and Live Forms

A custom classification type lets you define your own labels and prompt template for any category GPAL does not ship with. You supply the label list and a prompt that tells the model what to look for. A callback can also be registered to fire once the results grid is ready, so a workflow can react immediately to a classification result rather than waiting until execution continues past the Execute call.

GPAL.AI

.WithProvider(AIProviderType.XAI)

.WithTask(AITask.Classification)

.WithClassificationType(AIClassificationType.Custom)

.WithCustomClassification(new ClassificationConfig

{

Labels = new[] { "Bug Report", "Feature Request", "Question" },

PromptTemplate = "Classify {0} as {1}"

})

.WithInputFrom("The export button crashes the app on large files")

.WithOutputTo(out IGPALGrid<string> results)

.Execute();