From d15a218b73a02b155a856eea38c179c250ae5bcd Mon Sep 17 00:00:00 2001 From: Dawid Makowski Date: Fri, 3 May 2024 17:55:48 +0700 Subject: [PATCH 1/5] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b642a9d..44a479c 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ ![SharpAPI GitHub cover](https://sharpapi.com/sharpapi-github-php-bg.jpg "SharpAPI Laravel Client") -# SharpAPI PHP Client - #AI Programming Interface +# SharpAPI PHP Client -### 🚀 AI-Powered Swiss Army Knife API +### 🚀 Automate with AI in just two lines of code. Save countless hours and enhance your app effortlessly. -## Save countless hours and supercharge your app with AI capabilities in just 2 lines of code. +## Leverage AI API to streamline workflows in E-Commerce, Marketing, Content Management, HR Tech, Travel, and more. [![Latest Version on Packagist](https://img.shields.io/packagist/v/sharpapi/sharpapi-php-client.svg?style=flat-square)](https://packagist.org/packages/sharpapi/sharpapi-php-client) [![Total Downloads](https://img.shields.io/packagist/dt/sharpapi/sharpapi-php-client.svg?style=flat-square)](https://packagist.org/packages/sharpapi/sharpapi-php-client) From e612a724cd133f7c59515453ef4fbf396c49e446 Mon Sep 17 00:00:00 2001 From: Dawid Makowski Date: Fri, 3 May 2024 18:02:40 +0700 Subject: [PATCH 2/5] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 44a479c..7b11210 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ ![SharpAPI GitHub cover](https://sharpapi.com/sharpapi-github-php-bg.jpg "SharpAPI Laravel Client") -# SharpAPI PHP Client +# SharpAPI PHP Client SDK -### 🚀 Automate with AI in just two lines of code. Save countless hours and enhance your app effortlessly. +## 🚀 Automate with AI in just two lines of code. Save countless hours and enhance your app effortlessly. -## Leverage AI API to streamline workflows in E-Commerce, Marketing, Content Management, HR Tech, Travel, and more. +### Leverage AI API to streamline workflows in E-Commerce, Marketing, Content Management, HR Tech, Travel, and more. [![Latest Version on Packagist](https://img.shields.io/packagist/v/sharpapi/sharpapi-php-client.svg?style=flat-square)](https://packagist.org/packages/sharpapi/sharpapi-php-client) [![Total Downloads](https://img.shields.io/packagist/dt/sharpapi/sharpapi-php-client.svg?style=flat-square)](https://packagist.org/packages/sharpapi/sharpapi-php-client) From e7901288ba506c2d5a9597aa43a69841f3596eb4 Mon Sep 17 00:00:00 2001 From: Dawid Makowski Date: Mon, 26 Aug 2024 19:16:05 +0200 Subject: [PATCH 3/5] release 1.2 --- CHANGELOG.md | 6 +++++- README.md | 12 +++++++----- composer.json | 3 ++- src/Dto/SharpApiJob.php | 8 ++++---- src/SharpApiService.php | 20 +++++++++++++++----- 5 files changed, 33 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 794fe50..f988dde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog -## March 23, 2023 - v1.1.0 update +## August 26, 2024 - v1.2.0 update +- Generate Keywords/Tags & Summarize methods aquired optional `context` that allows to pass additional processing instructions for the provided `content` +- API useage optimized internall, switched to AI job dispatch/result endpoint pairing mode + +## March 23, 2024 - v1.1.0 update ### 1. new methods added diff --git a/README.md b/README.md index b642a9d..e87cfdf 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ # SharpAPI PHP Client - #AI Programming Interface -### 🚀 AI-Powered Swiss Army Knife API +### 🚀 Automate workflows with AI-powered API -## Save countless hours and supercharge your app with AI capabilities in just 2 lines of code. +## Leverage AI API to streamline workflows in E-Commerce, Marketing, Content Management, HR Tech, Travel, and more. [![Latest Version on Packagist](https://img.shields.io/packagist/v/sharpapi/sharpapi-php-client.svg?style=flat-square)](https://packagist.org/packages/sharpapi/sharpapi-php-client) [![Total Downloads](https://img.shields.io/packagist/dt/sharpapi/sharpapi-php-client.svg?style=flat-square)](https://packagist.org/packages/sharpapi/sharpapi-php-client) @@ -64,7 +64,7 @@ Please refer to the official: composer require sharpapi/sharpapi-php-client ``` -2. Register at [SharpApi.com](https://sharpapi.com/) and get the API key. +2. Register at [SharpAPI.com](https://sharpapi.com/) and get the API key. 3. **That's it!** @@ -483,7 +483,8 @@ $statusUrl = \SharpApiService::generateKeywords( $text, 'English', // optional language 5, // optional length - 'Freaky & Curious' // optional voice tone + 'Freaky & Curious', // optional voice tone + 'add emojis!' // optional extra context instructions for content processing ); ``` @@ -503,7 +504,8 @@ It can be adjectives like `funny` or `joyous`, or even the name of a famous writ $statusUrl = \SharpApiService::summarizeText( $text, 'English', // optional language - 'David Attenborough' // optional voice tone + 'David Attenborough', // optional voice tone + 'add emojis!' // optional extra context instructions for content processing ); ``` diff --git a/composer.json b/composer.json index a26ef36..212d659 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,8 @@ "php": "^8.1", "guzzlehttp/guzzle": "^7.8", "kongulov/interact-with-enum": "^1.0", - "nesbot/carbon": "^3.0" + "nesbot/carbon": "^3.0", + "spatie/url": "^2.4" }, "autoload": { "psr-4": { diff --git a/src/Dto/SharpApiJob.php b/src/Dto/SharpApiJob.php index 315cf0d..b2f0b08 100644 --- a/src/Dto/SharpApiJob.php +++ b/src/Dto/SharpApiJob.php @@ -14,7 +14,7 @@ public function __construct( public string $id, public string $type, public string $status, - public ?string $result + public ?stdClass $result ) { } @@ -66,7 +66,7 @@ public function getStatus(): SharpApiJobStatusEnum */ public function getResultJson(): string|bool|null { - return $this->result ? json_encode(json_decode($this->result), JSON_PRETTY_PRINT) : null; + return $this->result ? json_encode($this->result, JSON_PRETTY_PRINT) : null; } /** @@ -76,7 +76,7 @@ public function getResultJson(): string|bool|null */ public function getResultArray(): ?array { - return $this->result ? json_decode($this->result, true) : null; + return (array) $this->result; } /** @@ -86,6 +86,6 @@ public function getResultArray(): ?array */ public function getResultObject(): ?stdClass { - return $this->result ? json_decode($this->result) : null; + return $this->result; } } diff --git a/src/SharpApiService.php b/src/SharpApiService.php index fde115e..21b590d 100644 --- a/src/SharpApiService.php +++ b/src/SharpApiService.php @@ -15,6 +15,7 @@ use SharpAPI\SharpApiService\Dto\SharpApiSubscriptionInfo; use SharpAPI\SharpApiService\Enums\SharpApiJobStatusEnum; use SharpAPI\SharpApiService\Enums\SharpApiJobTypeEnum; +use Spatie\Url\Url; /** * Main Service to dispatch AI jobs to SharpAPI.com @@ -49,7 +50,7 @@ public function __construct(string $apiKey, ?string $apiBaseUrl = null, ?string throw new InvalidArgumentException('API key is required.'); } $this->setApiBaseUrl($apiBaseUrl ?? 'https://sharpapi.com/api/v1'); - $this->setUserAgent($userAgent ?? 'SharpAPIPHPAgent/1.1.0'); + $this->setUserAgent($userAgent ?? 'SharpAPIPHPAgent/1.2.0'); } /** @@ -220,12 +221,17 @@ public function fetchResults(string $statusUrl): SharpApiJob sleep($retryAfter); } while (true); $data = json_decode($response->getBody()->__toString(), true)['data']; - + $url = Url::fromString($statusUrl); + if (count($url->getSegments()) == 5) { // shared job result URL + $result = (object) json_decode($data['attributes']['result']); + } else { // 7 segments, 1-to-1 job to result url + $result = (object) $data['attributes']['result']; + } return new SharpApiJob( id: $data['id'], type: $data['attributes']['type'], status: $data['attributes']['status'], - result: $data['attributes']['result'] ?? null + result: $result ?? null ); } @@ -581,7 +587,8 @@ public function summarizeText( string $text, ?string $language = null, ?int $maxLength = null, - ?string $voiceTone = null + ?string $voiceTone = null, + ?string $context = null ): string { $response = $this->makeRequest( @@ -592,6 +599,7 @@ public function summarizeText( 'language' => $language, 'max_length' => $maxLength, 'voice_tone' => $voiceTone, + 'context' => $context, ]); return $this->parseStatusUrl($response); @@ -608,7 +616,8 @@ public function generateKeywords( string $text, ?string $language = null, ?int $maxQuantity = null, - ?string $voiceTone = null + ?string $voiceTone = null, + ?string $context = null ): string { $response = $this->makeRequest( @@ -619,6 +628,7 @@ public function generateKeywords( 'language' => $language, 'max_quantity' => $maxQuantity, 'voice_tone' => $voiceTone, + 'context' => $context, ]); return $this->parseStatusUrl($response); From 267ef4fd22371932b420734e6deab7330553be79 Mon Sep 17 00:00:00 2001 From: Dawid Makowski Date: Mon, 26 Aug 2024 19:23:14 +0200 Subject: [PATCH 4/5] readme update --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d7093c6..7cb7842 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ # SharpAPI PHP Client SDK -### 🚀 AI-Powered Swiss Army Knife API +### 🚀 Automate workflows with AI-powered API -## Save countless hours and supercharge your app with AI capabilities in just 2 lines of code. +## Leverage AI API to streamline workflows in E-Commerce, Marketing, Content Management, HR Tech, Travel, and more. [![Latest Version on Packagist](https://img.shields.io/packagist/v/sharpapi/sharpapi-php-client.svg?style=flat-square)](https://packagist.org/packages/sharpapi/sharpapi-php-client) [![Total Downloads](https://img.shields.io/packagist/dt/sharpapi/sharpapi-php-client.svg?style=flat-square)](https://packagist.org/packages/sharpapi/sharpapi-php-client) From e6efb02b7d62d91c20ceee8a2006da5db21ab237 Mon Sep 17 00:00:00 2001 From: Dawid Makowski Date: Tue, 27 Aug 2024 13:34:11 +0200 Subject: [PATCH 5/5] Update CHANGELOG.md --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f988dde..9bb0ac5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## August 26, 2024 - v1.2.0 update - Generate Keywords/Tags & Summarize methods aquired optional `context` that allows to pass additional processing instructions for the provided `content` -- API useage optimized internall, switched to AI job dispatch/result endpoint pairing mode +- API usege optimized internally, switched to AI job dispatch/result endpoint pairing mode ## March 23, 2024 - v1.1.0 update @@ -119,4 +119,4 @@ SHARP_API_USER_AGENT="SharpAPIPHPAgent/1.1.0" More info at https://sharpapi.com/affiliate_program ## December 10, 2023 - v1.0.2 -- v1.0.2 initial release \ No newline at end of file +- v1.0.2 initial release