Check the details at SharpAPI's Content Summarize API page.
- PHP >= 8.1
- Laravel >= 9.0
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)
{
$result = $this->summarizeService->summarize($text);
return response()->json($result);
}
/**
* @throws GuzzleException
*/
public function summarizeWithOptions(string $text)
{
$options = [
'max_length' => 200,
'language' => 'en',
];
$result = $this->summarizeService->summarize($text, $options);
return response()->json($result);
}
}All requests are managed by Guzzle, so it's helpful to be familiar with Guzzle Exceptions.
Example:
use GuzzleHttp\Exception\ClientException;
try {
$result = $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!"
}
}
}
}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:
