Skip to content

Commit 7774807

Browse files
committed
adding keywords/tags method
1 parent 6f8f159 commit 7774807

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

Diff for: README.md

+13-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ If you don't use Laravel then you can find
3333
- Easily translate text for a global audience.
3434
- Spam Content Detection: Identify and filter out spam content effectively.
3535
- Contact Information Extraction: Extract phone numbers and email addresses from non-standard formats for streamlined communication.
36-
- Generate concise summaries for improved content consumption.
36+
- Generate concise summaries and unique keywords/tags for improved content consumption.
3737
- Boost SEO efforts by automatically generating META tags based on content.
3838
* **HR Tech**
3939
- Generate complex job descriptions effortlessly, saving time in the hiring process.
@@ -89,7 +89,7 @@ and the process of checking the results, especially if you process bigger batche
8989
Typical use case require these steps:
9090

9191
1. Dispatch one of the available AI processing methods (this will return job processing status URL)
92-
2. Run `pollJobStatusAndFetchResults($statusUrl)` method which operates in polling mode, sending underneath
92+
2. Run `fetchResults($statusUrl)` method which operates in polling mode, sending underneath
9393
requests every 10 seconds for 180 seconds (these values [can be customized](#optional-custom-configuration)).
9494
3. `SharpApiJob` object will be returned.
9595
4. For a job finished with `success` return status you can obtain the results with one
@@ -137,7 +137,7 @@ class SharpTest extends Controller
137137
Call: 1800-394-7486 or our Singapore office +65 8888 8888'
138138
);
139139

140-
$result = $this->sharpApiService->pollJobStatusAndFetchResults($statusUrl);
140+
$result = $this->sharpApiService->fetchResults($statusUrl);
141141

142142
dd($result->getResultJson());
143143
/* returned:
@@ -173,7 +173,7 @@ try {
173173
}
174174

175175
// Step 2: request to check job status in polling mode and wait for the result
176-
$jobResult = \SharpApiService::pollJobStatusAndFetchResults($statusUrl);
176+
$jobResult = \SharpApiService::fetchResults($statusUrl);
177177

178178
// Step 3: get results of dispatched API job, f.e. this returns job result as a prettied JSON
179179
$jobResultJson = $jobResult->getResultJson();
@@ -373,6 +373,14 @@ or f.e. if you want to detect emails in places where they're not supposed to be.
373373
$statusUrl = \SharpApiService::detectEmails($text);
374374
```
375375

376+
#### Generate Keywords/Tags
377+
378+
Generates a list of unique keywords/tags based on the provided content.
379+
380+
```php
381+
$statusUrl = \SharpApiService::generateKeywords($text, 'English');
382+
```
383+
376384
#### Summarize Text
377385

378386
Generates a summarized version of the provided content. Perfect for generating
@@ -382,6 +390,7 @@ marketing introductions of longer texts.
382390
$statusUrl = \SharpApiService::summarizeText($text, 'English');
383391
```
384392

393+
385394
### SEO
386395

387396
#### Generate SEO Tags

Diff for: src/Enums/SharpApiJobTypeEnum.php

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ enum SharpApiJobTypeEnum: string
2525
case CONTENT_DETECT_EMAILS = 'content_detect_emails';
2626
case CONTENT_DETECT_SPAM = 'content_detect_spam';
2727
case CONTENT_SUMMARIZE = 'content_summarize';
28+
case CONTENT_KEYWORDS = 'content_keywords';
2829
case CONTENT_TRANSLATE = 'content_translate';
2930
case SEO_GENERATE_TAGS = 'seo_generate_tags';
3031

@@ -46,6 +47,7 @@ public function label(): string
4647
self::CONTENT_DETECT_EMAILS => 'Detect Emails',
4748
self::CONTENT_DETECT_SPAM => 'Detect Spam',
4849
self::CONTENT_SUMMARIZE => 'Summarize Content',
50+
self::CONTENT_KEYWORDS => 'Generate Keywords/Tags',
4951
self::CONTENT_TRANSLATE => 'Translate Text',
5052
self::SEO_GENERATE_TAGS => 'Generate SEO Tags',
5153
};
@@ -69,6 +71,7 @@ public function category(): string
6971
self::CONTENT_DETECT_EMAILS,
7072
self::CONTENT_DETECT_SPAM,
7173
self::CONTENT_TRANSLATE,
74+
self::CONTENT_KEYWORDS,
7275
self::CONTENT_SUMMARIZE => 'Content',
7376
self::SEO_GENERATE_TAGS => 'SEO',
7477
};

Diff for: src/SharpApiService.php

+19-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private function parseStatusUrl(ResponseInterface $response)
8484
*
8585
* @api
8686
*/
87-
public function pollJobStatusAndFetchResults(string $statusUrl): SharpApiJob
87+
public function fetchResults(string $statusUrl): SharpApiJob
8888
{
8989
$client = new Client();
9090
$waitingTime = 0;
@@ -382,6 +382,24 @@ public function summarizeText(string $text, string $language = 'English'): strin
382382
return $this->parseStatusUrl($response);
383383
}
384384

385+
/**
386+
* Generates a list of unique keywords/tags based on the provided content.
387+
*
388+
* @throws GuzzleException
389+
*
390+
* @api
391+
*/
392+
public function generateKeywords(string $text, string $language = 'English'): string
393+
{
394+
$url = $this->apiBaseUrl.'/content/keywords';
395+
$response = $this->makeRequest('POST', $url, [
396+
'content' => $text,
397+
'language' => $language,
398+
]);
399+
400+
return $this->parseStatusUrl($response);
401+
}
402+
385403
/**
386404
* Translates the provided text into selected language
387405
* Perfect for generating marketing introductions of longer texts.

0 commit comments

Comments
 (0)