Check the details at SharpAPI's Content Summarize API page.
- PHP >= 8.1
- Laravel >= 10.48.29
Follow these steps to install and set up the SharpAPI Laravel Content Summarize API package.
- Install the package via
composer:
composer require sharpapi/laravel-content-summarize-
Register at SharpAPI.com to obtain your API key.
-
Set the API key in your
.envfile:
SHARP_API_KEY=your_api_key_here- [OPTIONAL] Publish the configuration file:
php artisan vendor:publish --tag=sharpapi-content-summarize- Text Summarization: Generate concise summaries of long-form content
- Customizable Length: Control the length of the generated summaries
- Multi-language Support: Summarize content in multiple languages
- Preserve Key Information: Maintain the most important points from the original text
- AI-Powered: Leverage advanced AI models for high-quality summarization
You can inject the ContentSummarizeService class to access the text summarization functionality.
- Summarize Text: Use the service to generate concise summaries of your content.
Here is an example of how to use ContentSummarizeService within a Laravel controller:
<?php
namespace App\Http\Controllers;
use GuzzleHttp\Exception\GuzzleException;
use SharpAPI\ContentSummarize\ContentSummarizeService;
class SummarizeController extends Controller
{
protected ContentSummarizeService $summarizeService;
public function __construct(ContentSummarizeService $summarizeService)
{
$this->summarizeService = $summarizeService;
}
/**
* @throws GuzzleException
*/
public function summarizeText(string $text)
{
// summarize() returns a status URL; fetchResults() polls until the job is done.
// In production, run this in a queued job rather than an HTTP request.
$statusUrl = $this->summarizeService->summarize($text);
$job = $this->summarizeService->fetchResults($statusUrl);
return response()->json(['summary' => $job->result->summary ?? null]);
}
/**
* @throws GuzzleException
*/
public function summarizeWithOptions(string $text)
{
// Options are positional: language (full name), max length, voice tone, context
$statusUrl = $this->summarizeService->summarize($text, 'English', 200, 'neutral');
$job = $this->summarizeService->fetchResults($statusUrl);
return response()->json(['summary' => $job->result->summary ?? null]);
}
}All requests are managed by Guzzle, so it's helpful to be familiar with Guzzle Exceptions.
Example:
use GuzzleHttp\Exception\ClientException;
try {
$statusUrl = $this->summarizeService->summarize($longText);
} catch (ClientException $e) {
echo $e->getMessage();
}You can customize the configuration by setting the following environment variables in your .env file:
SHARP_API_KEY=your_api_key_here
SHARP_API_BASE_URL=https://sharpapi.com/api/v1{
"data": {
"type": "api_job_result",
"id": "5fa45f0e-6680-4f64-8528-3f085a87bd2f",
"attributes": {
"status": "success",
"type": "content_summarize",
"result": {
"summary": "Max Verstappen thinks the Las Vegas Grand Prix is more showbiz than sport, while Lewis Hamilton and Fernando Alonso are soaking up the glitz. Expect hydraulic platforms, light shows, and maybe some racing. Don't knock it 'til you try it!"
}
}
}
}This package ships a Laravel Boost skill, sharpapi-content-summarize. It teaches AI coding agents the async submit-then-fetchResults() flow, the queued-job recipe, the result shape and the testing approach. Boost 2 or newer is required. In your app:
composer require laravel/boost --dev
php artisan boost:install # first time
php artisan boost:update --discover # already using BoostSelect sharpapi/laravel-content-summarize when Boost lists the packages it found. The skill loads on demand; no always-on guideline is added.
For issues or suggestions, please:
Please see CHANGELOG for a detailed list of changes.
- A2Z WEB LTD
- Dawid Makowski
- Enhance your Laravel AI capabilities!
The MIT License (MIT). Please see License File for more information.
Stay updated with news, tutorials, and case studies:
