Use AI as your intelligent assistant to analyze text for spam, sentiment, and moderation, delivering precise insights with confidence scores and detailed reasoning.
composer require jeffreyvanrossum/contextr
First, you need to setup your instance of contextr.
You can use OpenAI or Grok as AI providers.
$contextr = new Contextr\Contextr(provider: new Contextr\Providers\OpenAi(apiKey: 'API_KEY'));
// Or for Grok:
$contextr = new Contextr\Contextr(provider: new Contextr\Providers\Grok(apiKey: 'API_KEY'));
$check = $contextr->spam()
->text('Buy cheap viagra now!!! Click here: shady.link')
->context([
'topic' => 'Health Forum Discussion',
'user_history' => 'First time poster'
])
->withReasoning()
->analyze();
$check->data(); // full result array
$check->spam(); // true (boolean)
$check->confidence(); // 0.95 (float)
$check->reasoning(); // "Contains promotional content and suspicious link"
Determine if the sentiment is positive
, negative
or neutral
.
$check = $contextr->sentiment()
->text('This blu ray was great, too bad it did not include Project A.')
->context([
'product' => 'Jackie Chan Collection Vol 1983',
'category' => 'Blu ray'
])
->withReasoning()
->analyze();
$check->data(); // full result array
$check->sentiment(); // neutral (string)
$check->confidence(); // 0.75 (float)
$check->reasoning(); // "Expresses enjoyment of the blu ray but also disappointment about the absence of a specific content." (string)
Determine if user comments violate moderation rules.
$check = $contextr->moderation()
->text('These morons don’t even know how to kick a ball properly!')
->rules(['hate speech', 'profanity', 'civility'])
->context([
'platform' => 'sports news website',
'topic' => 'Premier League match review'
])
->withReasoning()
->withViolations()
->analyze();
$check->data(); // full result array
$check->violates(); // true (boolean)
$check->confidence(); // 0.75 (float)
$check->violations(); // ['profanity', 'civility'] (array)
$check->reasoning(); // "Contains insulting language and lacks respectful tone"
Determine the likelyhood that a text is AI-generated.
$check = $contextr->ai()
->text('The strategic intricacies of modern football necessitate a comprehensive understanding of player positioning, tactical adaptability, and cohesive team synergy to achieve superior performance outcomes.')
->context([
'platform' => 'football fan forum',
'topic' => 'Post-match discussion: Manchester United vs. Liverpool',
'user_history' => 'New account, posted 5 similar analyses in 24 hours'
])
->withReasoning()
>analyze();
$check->data(); // full result array
$check->ai(); // true (boolean)
$check->confidence(); // 0.92 (float)
$check->reasoning(); // "Overly polished language and generic analysis typical of AI-generated text, especially given the user's pattern of similar posts."
Would you like this API, but as a hosted service, with a nice interface to define custom base templates?
MIT. Please see the License File for more information.