Skip to content

Commit 5660b26

Browse files
committed
Initial commit - SharpAPI Laravel package
Laravel package for SharpAPI.com integration. Part of the SharpAPI Laravel SDK collection.
0 parents  commit 5660b26

File tree

8 files changed

+358
-0
lines changed

8 files changed

+358
-0
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.idea
2+
.phpunit.result.cache
3+
build
4+
composer.lock
5+
coverage
6+
docs
7+
phpunit.xml
8+
phpstan.neon
9+
testbench.yaml
10+
vendor
11+
node_modules

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Changelog
2+
3+
All notable changes to `laravel-content-paraphrase` will be documented in this file.

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# The MIT License (MIT)
2+
3+
Copyright (c) SharpAPI <contact@sharpapi.com>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# AI Content Paraphraser for Laravel
2+
3+
[![Latest Version on Packagist](https://img.shields.io/packagist/v/sharpapi/laravel-content-paraphrase.svg?style=flat-square)](https://packagist.org/packages/sharpapi/laravel-content-paraphrase)
4+
[![Total Downloads](https://img.shields.io/packagist/dt/sharpapi/laravel-content-paraphrase.svg?style=flat-square)](https://packagist.org/packages/sharpapi/laravel-content-paraphrase)
5+
6+
This package provides a Laravel integration for the SharpAPI Content Paraphrasing service. It allows you to rewrite text while maintaining its original meaning, which is perfect for creating unique content variations, avoiding plagiarism, and improving content readability.
7+
8+
## Installation
9+
10+
You can install the package via composer:
11+
12+
```bash
13+
composer require sharpapi/laravel-content-paraphrase
14+
```
15+
16+
## Configuration
17+
18+
Publish the config file with:
19+
20+
```bash
21+
php artisan vendor:publish --tag="sharpapi-content-paraphrase"
22+
```
23+
24+
This is the contents of the published config file:
25+
26+
```php
27+
return [
28+
'api_key' => env('SHARP_API_KEY'),
29+
'base_url' => env('SHARP_API_BASE_URL', 'https://sharpapi.com/api/v1'),
30+
'api_job_status_polling_wait' => env('SHARP_API_JOB_STATUS_POLLING_WAIT', 180),
31+
'api_job_status_polling_interval' => env('SHARP_API_JOB_STATUS_POLLING_INTERVAL', 10),
32+
'api_job_status_use_polling_interval' => env('SHARP_API_JOB_STATUS_USE_POLLING_INTERVAL', false),
33+
];
34+
```
35+
36+
Make sure to set your SharpAPI key in your .env file:
37+
38+
```
39+
SHARP_API_KEY=your-api-key
40+
```
41+
42+
## Usage
43+
44+
```php
45+
use SharpAPI\ContentParaphrase\ContentParaphraseService;
46+
47+
$service = new ContentParaphraseService();
48+
49+
// Paraphrase text
50+
$paraphrasedText = $service->paraphrase(
51+
'The quick brown fox jumps over the lazy dog.',
52+
'English', // optional language
53+
100, // optional max length
54+
'professional', // optional voice tone
55+
'blog post' // optional context
56+
);
57+
58+
// $paraphrasedText will contain the paraphrased text as a string
59+
```
60+
61+
## Parameters
62+
63+
- `text` (string): The text content to paraphrase
64+
- `language` (string|null): The language for the paraphrased text (default: English)
65+
- `maxLength` (int|null): Maximum length of the paraphrased text
66+
- `voiceTone` (string|null): The tone of voice for the paraphrased text (e.g., professional, casual, friendly)
67+
- `context` (string|null): Additional context to improve paraphrasing quality
68+
69+
## Response Format
70+
71+
```json
72+
{
73+
"data": {
74+
"type": "api_job_result",
75+
"id": "385fec60-e73e-458c-a6c9-6e76e5a76661",
76+
"attributes": {
77+
"status": "success",
78+
"type": "content_paraphrase",
79+
"result": {
80+
"paraphrase": "Max Verstappen of Red Bull remarks that the Las Vegas Grand Prix is '99% show and 1% sport.' The triple world champion isn't thrilled about the spectacle, marking the first F1 race on the city's Strip. Other drivers, like Fernando Alonso, acknowledge the unique investment and setting. The event began with a grand ceremony featuring stars like Kylie Minogue. Bob Hamilton expressed excitement about the iconic city, noting the blend of show and sport, and praised F1's direction under Stefano Domenicali and Liberty."
81+
}
82+
}
83+
}
84+
}
85+
86+
## Features
87+
88+
- Maintains the original meaning of the text
89+
- Adjusts the writing style based on the specified voice tone
90+
- Supports multiple languages
91+
- Can limit the length of the output text
92+
- Provides context-aware paraphrasing for better results
93+
94+
## Credits
95+
96+
- [Dawid Makowski](https://github.com/dawidmakowski)
97+
- [All Contributors](../../contributors)
98+
99+
## License
100+
101+
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

composer.json

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"name": "sharpapi/laravel-content-paraphrase",
3+
"description": "AI Content Paraphrasing for Laravel powered by SharpAPI.com",
4+
"keywords": [
5+
"sharpapi",
6+
"ai-powered",
7+
"ai capabilities",
8+
"api",
9+
"ai api",
10+
"api integration",
11+
"artificial intelligence",
12+
"natural language processing",
13+
"restful api",
14+
"php",
15+
"laravel",
16+
"software development",
17+
"content generation",
18+
"content analysis",
19+
"paraphrase",
20+
"rewrite",
21+
"plagiarism"
22+
],
23+
"homepage": "https://github.com/sharpapi/laravel-content-paraphrase",
24+
"license": "MIT",
25+
"authors": [
26+
{
27+
"name": "Dawid Makowski",
28+
"email": "contact@sharpapi.com",
29+
"role": "Developer"
30+
}
31+
],
32+
"require": {
33+
"php": "^8.1",
34+
"ext-json": "*",
35+
"guzzlehttp/guzzle": "^7.0",
36+
"laravel/framework": "^9.0|^10.0|^11.0|^12.0",
37+
"kongulov/interact-with-enum": "^1.0",
38+
"sharpapi/php-core": "^1.0",
39+
"spatie/laravel-data": "^3.0|^4.0",
40+
"spatie/url": "^2.4"
41+
},
42+
"require-dev": {
43+
"laravel/pint": "^1.0"
44+
},
45+
"autoload": {
46+
"psr-4": {
47+
"SharpAPI\\ContentParaphrase\\": "src/"
48+
}
49+
},
50+
"autoload-dev": {
51+
"psr-4": {
52+
"SharpAPI\\ContentParaphrase\\Tests\\": "tests/"
53+
}
54+
},
55+
"scripts": {
56+
"post-autoload-dump": "",
57+
"build": [
58+
],
59+
"start": [
60+
"Composer\\Config::disableProcessTimeout",
61+
"@composer run build"
62+
],
63+
"analyse": "vendor/bin/phpstan analyse",
64+
"test": "vendor/bin/pest",
65+
"test-coverage": "vendor/bin/pest --coverage",
66+
"format": "vendor/bin/pint"
67+
},
68+
"config": {
69+
"sort-packages": true,
70+
"allow-plugins": {
71+
"pestphp/pest-plugin": true,
72+
"phpstan/extension-installer": true
73+
}
74+
},
75+
"extra": {
76+
"laravel": {
77+
"providers": [
78+
"SharpAPI\\ContentParaphrase\\ContentParaphraseProvider"
79+
]
80+
}
81+
},
82+
"minimum-stability": "dev",
83+
"prefer-stable": true
84+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
return [
6+
'api_key' => env('SHARP_API_KEY'),
7+
'base_url' => env('SHARP_API_BASE_URL', 'https://sharpapi.com/api/v1'), // as ENV is mock server needed
8+
// how long (in seconds) the client should wait in polling mode for results
9+
'api_job_status_polling_wait' => env('SHARP_API_JOB_STATUS_POLLING_WAIT', 180),
10+
// how many seconds the client should wait between each result request
11+
// usually Retry-After header is used (default 10s), this value won't have an effect unless
12+
// api_job_status_use_polling_interval is set to TRUE
13+
'api_job_status_polling_interval' => env('SHARP_API_JOB_STATUS_POLLING_INTERVAL', 10),
14+
'api_job_status_use_polling_interval' => env('SHARP_API_JOB_STATUS_USE_POLLING_INTERVAL', false),
15+
// for affiliate program members use
16+
];

src/ContentParaphraseProvider.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SharpAPI\ContentParaphrase;
6+
7+
use Illuminate\Support\ServiceProvider;
8+
9+
/**
10+
* @api
11+
*/
12+
class ContentParaphraseProvider extends ServiceProvider
13+
{
14+
/**
15+
* Bootstrap the application services.
16+
*/
17+
public function boot(): void
18+
{
19+
if ($this->app->runningInConsole()) {
20+
$this->publishes([
21+
__DIR__.'/../config/sharpapi-content-paraphrase.php' => config_path('sharpapi-content-paraphrase.php'),
22+
], 'sharpapi-content-paraphrase');
23+
}
24+
}
25+
26+
/**
27+
* Register the application services.
28+
*/
29+
public function register(): void
30+
{
31+
// Merge the package configuration with the app configuration.
32+
$this->mergeConfigFrom(
33+
__DIR__.'/../config/sharpapi-content-paraphrase.php', 'sharpapi-content-paraphrase'
34+
);
35+
}
36+
}

src/ContentParaphraseService.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SharpAPI\ContentParaphrase;
6+
7+
use GuzzleHttp\Exception\GuzzleException;
8+
use InvalidArgumentException;
9+
use SharpAPI\Core\Client\SharpApiClient;
10+
11+
/**
12+
* @api
13+
*/
14+
class ContentParaphraseService extends SharpApiClient
15+
{
16+
/**
17+
* Initializes a new instance of the class.
18+
*
19+
* @throws InvalidArgumentException if the API key is empty.
20+
*/
21+
public function __construct()
22+
{
23+
parent::__construct(config('sharpapi-content-paraphrase.api_key'));
24+
$this->setApiBaseUrl(
25+
config(
26+
'sharpapi-content-paraphrase.base_url',
27+
'https://sharpapi.com/api/v1'
28+
)
29+
);
30+
$this->setApiJobStatusPollingInterval(
31+
(int) config(
32+
'sharpapi-content-paraphrase.api_job_status_polling_interval',
33+
5)
34+
);
35+
$this->setApiJobStatusPollingWait(
36+
(int) config(
37+
'sharpapi-content-paraphrase.api_job_status_polling_wait',
38+
180)
39+
);
40+
$this->setUserAgent('SharpAPILaravelContentParaphrase/1.0.0');
41+
}
42+
43+
/**
44+
* Paraphrases the provided text while maintaining its meaning.
45+
* Perfect for creating unique content variations or avoiding plagiarism.
46+
*
47+
* Only the `content` parameter is required. You can define the output language,
48+
* maximum character length, and tone of voice. Additional instructions
49+
* on how to process the text can be provided in the context parameter.
50+
* Please keep in mind that `max_length` serves as a strong suggestion
51+
* for the Language Model, rather than a strict requirement,
52+
* to maintain the general sense of the outcome.
53+
*
54+
* @param string $text The text to paraphrase
55+
* @param string|null $language The language for the paraphrased text (optional)
56+
* @param int|null $maxLength Maximum length of the paraphrased text (optional)
57+
* @param string|null $voiceTone The tone of voice for the paraphrased text (optional)
58+
* @param string|null $context Additional context for better paraphrasing (optional)
59+
* @return string The paraphrased text or an error message
60+
*
61+
* @throws GuzzleException
62+
*
63+
* @api
64+
*/
65+
public function paraphrase(
66+
string $text,
67+
?string $language = null,
68+
?int $maxLength = null,
69+
?string $voiceTone = null,
70+
?string $context = null
71+
): string {
72+
$response = $this->makeRequest(
73+
'POST',
74+
'/content/paraphrase',
75+
[
76+
'content' => $text,
77+
'language' => $language,
78+
'max_length' => $maxLength,
79+
'voice_tone' => $voiceTone,
80+
'context' => $context,
81+
]
82+
);
83+
84+
return $this->parseStatusUrl($response);
85+
}
86+
}

0 commit comments

Comments
 (0)