⚡ You're viewing a live demo of ChimerAI. Data resets daily at midnight UTC.Get the CLI →

NLP Analysis Tool

ChimerAI's NLP Tool performs natural language processing tasks — sentiment analysis, entity extraction, keyword extraction, text summarisation, and more — using your configured LLM.

What you get

  • Sentiment analysis — Positive/negative/neutral + confidence score
  • Named entity extraction — People, organisations, locations, dates
  • Keyword extraction — Top-N keywords with relevance scores
  • Text summarisation — Configurable length (short/medium/detailed)
  • Language detection — Identify the input language
  • Intent classification — Map text to custom intent labels
  • Batch processing — Analyse multiple texts in one request

Quick setup

npx chimerai add ai-tools --only nlp

Scaffolds:

app/api/tools/nlp/route.ts        ← NLP endpoint
services/ai/tools/nlp_tools.py    ← Python NLP implementation

Usage

const res = await fetch('/api/tools/nlp', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    text: 'Apple announced new MacBook Pro models yesterday in Cupertino.',
    tasks: ['sentiment', 'entities', 'keywords', 'summary'],
    summaryLength: 'short',
  }),
});

const result = await res.json();
// result.sentiment: { label: 'positive', score: 0.87 }
// result.entities: [{ text: 'Apple', type: 'ORG' }, { text: 'Cupertino', type: 'LOC' }]
// result.keywords: [{ word: 'MacBook Pro', score: 0.95 }]
// result.summary: 'Apple unveiled new MacBook Pro laptops...'

Intent classification

const res = await fetch('/api/tools/nlp/classify', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    text: 'I want to cancel my subscription',
    labels: ['billing', 'support', 'feature_request', 'complaint', 'other'],
  }),
});

const { intent, confidence } = await res.json();
// intent: 'billing', confidence: 0.94

Python implementation

from openai import AsyncOpenAI
import json

client = AsyncOpenAI()

async def analyse_text(text: str, tasks: list[str]) -> dict:
    task_desc = ", ".join(tasks)
    prompt = f"""Analyse the following text and return a JSON object with these fields: {task_desc}.

For 'sentiment': {{ "label": "positive|negative|neutral", "score": 0.0-1.0 }}
For 'entities': array of {{ "text": str, "type": "PERSON|ORG|LOC|DATE|..." }}
For 'keywords': array of {{ "word": str, "score": 0.0-1.0 }}
For 'summary': string

Text: {text}

Return ONLY valid JSON."""

    response = await client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": prompt}],
        response_format={"type": "json_object"},
        temperature=0,
    )
    return json.loads(response.choices[0].message.content)

Use cases

  • Customer feedback analysis — Auto-categorise support tickets by sentiment + intent
  • Content moderation — Extract entities to detect PII before storing
  • Search enhancement — Extract keywords for better full-text search indexing
  • Auto-tagging — Tag content with extracted entities and topics

Further reading

ChimerAI Docs · Back to Demo