From 9f9109a2e93339000a23d0802b3522da6f22ee87 Mon Sep 17 00:00:00 2001 From: Dawid Makowski Date: Tue, 2 Jan 2024 19:09:46 +0800 Subject: [PATCH] adding keywords/tags method --- README.md | 19 ++++++++++++++----- src/Enums/SharpApiJobTypeEnum.php | 3 +++ src/SharpApiService.php | 20 +++++++++++++++++++- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0da133d..40039b1 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ See more at [SharpAPI.com Website »](https://sharpapi.com/) - Spam Content Detection: Identify and filter out spam content effectively. - Contact Information Extraction: Extract phone numbers and email addresses from non-standard formats for streamlined communication. - - Generate concise summaries for improved content consumption. + - Generate concise summaries and unique keywords/tags for improved content consumption. - Boost SEO efforts by automatically generating META tags based on content. * **HR Tech** - Generate complex job descriptions effortlessly, saving time in the hiring process. @@ -77,7 +77,7 @@ $sharpApi = new \SharpAPI\SharpApiService\SharpApiService('8bKzQl3cwckfVsnsN8T8p $statusUrl = $sharpApi->productCategories('Lenovo Chromebook Laptop (2023), 14" FHD Touchscreen Slim 3, 8-Core MediaTek Kompanio 520 CPU, 4GB RAM, 128GB Storage'); -$resultSharpApiJob = $sharpApi->pollJobStatusAndFetchResults($statusUrl); +$resultSharpApiJob = $sharpApi->fetchResults($statusUrl); var_dump($resultSharpApiJob->getResultJson()); ``` @@ -85,7 +85,7 @@ var_dump($resultSharpApiJob->getResultJson()); Typical use case require these steps: 1. Dispatch one of the available AI processing methods (this will return job processing status URL) -2. Run `pollJobStatusAndFetchResults($statusUrl)` method which operates in polling mode, sending underneath +2. Run `fetchResults($statusUrl)` method which operates in polling mode, sending underneath requests every 10 seconds for 180 seconds (these values can be customized, check `SharpApiService` source code). 3. `SharpApiJob` object will be returned. @@ -126,7 +126,7 @@ try { } // Step 2: request to check job status in polling mode and wait for the result -$jobResult = \SharpApiService::pollJobStatusAndFetchResults($statusUrl); +$jobResult = \SharpApiService::fetchResults($statusUrl); // Step 3: get results of dispatched API job, f.e. this returns job result as a prettied JSON $jobResultJson = $jobResult->getResultJson(); @@ -162,7 +162,7 @@ class SharpTest extends Controller Call: 1800-394-7486 or our Singapore office +65 8888 8888' ); - $result = $this->sharpApiService->pollJobStatusAndFetchResults($statusUrl); + $result = $this->sharpApiService->fetchResults($statusUrl); dd($result->getResultJson()); /* returned: @@ -335,6 +335,15 @@ or f.e. if you want to detect emails in places where they're not supposed to be. $statusUrl = \SharpApiService::detectEmails($text); ``` +#### Generate Keywords/Tags + +Generates a list of unique keywords/tags based on the provided content. + +```php +$statusUrl = \SharpApiService::generateKeywords($text, 'English'); +``` + + #### Summarize Text Generates a summarized version of the provided content. Perfect for generating diff --git a/src/Enums/SharpApiJobTypeEnum.php b/src/Enums/SharpApiJobTypeEnum.php index 0a4b7e3..f5d2c3d 100644 --- a/src/Enums/SharpApiJobTypeEnum.php +++ b/src/Enums/SharpApiJobTypeEnum.php @@ -25,6 +25,7 @@ enum SharpApiJobTypeEnum: string case CONTENT_DETECT_EMAILS = 'content_detect_emails'; case CONTENT_DETECT_SPAM = 'content_detect_spam'; case CONTENT_SUMMARIZE = 'content_summarize'; + case CONTENT_KEYWORDS = 'content_keywords'; case CONTENT_TRANSLATE = 'content_translate'; case SEO_GENERATE_TAGS = 'seo_generate_tags'; @@ -46,6 +47,7 @@ public function label(): string self::CONTENT_DETECT_EMAILS => 'Detect Emails', self::CONTENT_DETECT_SPAM => 'Detect Spam', self::CONTENT_SUMMARIZE => 'Summarize Content', + self::CONTENT_KEYWORDS => 'Generate Keywords/Tags', self::CONTENT_TRANSLATE => 'Translate Text', self::SEO_GENERATE_TAGS => 'Generate SEO Tags', }; @@ -69,6 +71,7 @@ public function category(): string self::CONTENT_DETECT_EMAILS, self::CONTENT_DETECT_SPAM, self::CONTENT_TRANSLATE, + self::CONTENT_KEYWORDS, self::CONTENT_SUMMARIZE => 'Content', self::SEO_GENERATE_TAGS => 'SEO', }; diff --git a/src/SharpApiService.php b/src/SharpApiService.php index b0511cb..a8c29d8 100644 --- a/src/SharpApiService.php +++ b/src/SharpApiService.php @@ -150,7 +150,7 @@ private function parseStatusUrl(ResponseInterface $response) * * @api */ - public function pollJobStatusAndFetchResults(string $statusUrl): SharpApiJob + public function fetchResults(string $statusUrl): SharpApiJob { $client = new Client(); $waitingTime = 0; @@ -429,6 +429,24 @@ public function detectSpam(string $text): string return $this->parseStatusUrl($response); } + /** + * Generates a list of unique keywords/tags based on the provided content. + * + * @throws GuzzleException + * + * @api + */ + public function generateKeywords(string $text, string $language = 'English'): string + { + $url = $this->apiBaseUrl . '/content/keywords'; + $response = $this->makeRequest('POST', $url, [ + 'content' => $text, + 'language' => $language, + ]); + + return $this->parseStatusUrl($response); + } + /** * Generates a summarized version of the provided content. * Perfect for generating marketing introductions of longer texts.