Skip to content

Commit 9f9109a

Browse files
committed
adding keywords/tags method
1 parent 3f403a2 commit 9f9109a

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

README.md

+14-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ See more at [SharpAPI.com Website »](https://sharpapi.com/)
3131
- Spam Content Detection: Identify and filter out spam content effectively.
3232
- Contact Information Extraction: Extract phone numbers and email addresses from non-standard formats for
3333
streamlined communication.
34-
- Generate concise summaries for improved content consumption.
34+
- Generate concise summaries and unique keywords/tags for improved content consumption.
3535
- Boost SEO efforts by automatically generating META tags based on content.
3636
* **HR Tech**
3737
- Generate complex job descriptions effortlessly, saving time in the hiring process.
@@ -77,15 +77,15 @@ $sharpApi = new \SharpAPI\SharpApiService\SharpApiService('8bKzQl3cwckfVsnsN8T8p
7777
7878
$statusUrl = $sharpApi->productCategories('Lenovo Chromebook Laptop (2023), 14" FHD Touchscreen Slim 3, 8-Core MediaTek Kompanio 520 CPU, 4GB RAM, 128GB Storage');
7979
80-
$resultSharpApiJob = $sharpApi->pollJobStatusAndFetchResults($statusUrl);
80+
$resultSharpApiJob = $sharpApi->fetchResults($statusUrl);
8181
8282
var_dump($resultSharpApiJob->getResultJson());
8383
```
8484
8585
Typical use case require these steps:
8686
8787
1. Dispatch one of the available AI processing methods (this will return job processing status URL)
88-
2. Run `pollJobStatusAndFetchResults($statusUrl)` method which operates in polling mode, sending underneath
88+
2. Run `fetchResults($statusUrl)` method which operates in polling mode, sending underneath
8989
requests every 10 seconds for 180 seconds (these values can be customized,
9090
check `SharpApiService` source code).
9191
3. `SharpApiJob` object will be returned.
@@ -126,7 +126,7 @@ try {
126126
}
127127
128128
// Step 2: request to check job status in polling mode and wait for the result
129-
$jobResult = \SharpApiService::pollJobStatusAndFetchResults($statusUrl);
129+
$jobResult = \SharpApiService::fetchResults($statusUrl);
130130
131131
// Step 3: get results of dispatched API job, f.e. this returns job result as a prettied JSON
132132
$jobResultJson = $jobResult->getResultJson();
@@ -162,7 +162,7 @@ class SharpTest extends Controller
162162
Call: 1800-394-7486 or our Singapore office +65 8888 8888'
163163
);
164164
165-
$result = $this->sharpApiService->pollJobStatusAndFetchResults($statusUrl);
165+
$result = $this->sharpApiService->fetchResults($statusUrl);
166166
167167
dd($result->getResultJson());
168168
/* returned:
@@ -335,6 +335,15 @@ or f.e. if you want to detect emails in places where they're not supposed to be.
335335
$statusUrl = \SharpApiService::detectEmails($text);
336336
```
337337
338+
#### Generate Keywords/Tags
339+
340+
Generates a list of unique keywords/tags based on the provided content.
341+
342+
```php
343+
$statusUrl = \SharpApiService::generateKeywords($text, 'English');
344+
```
345+
346+
338347
#### Summarize Text
339348
340349
Generates a summarized version of the provided content. Perfect for generating

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
};

src/SharpApiService.php

+19-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ private function parseStatusUrl(ResponseInterface $response)
150150
*
151151
* @api
152152
*/
153-
public function pollJobStatusAndFetchResults(string $statusUrl): SharpApiJob
153+
public function fetchResults(string $statusUrl): SharpApiJob
154154
{
155155
$client = new Client();
156156
$waitingTime = 0;
@@ -429,6 +429,24 @@ public function detectSpam(string $text): string
429429
return $this->parseStatusUrl($response);
430430
}
431431

432+
/**
433+
* Generates a list of unique keywords/tags based on the provided content.
434+
*
435+
* @throws GuzzleException
436+
*
437+
* @api
438+
*/
439+
public function generateKeywords(string $text, string $language = 'English'): string
440+
{
441+
$url = $this->apiBaseUrl . '/content/keywords';
442+
$response = $this->makeRequest('POST', $url, [
443+
'content' => $text,
444+
'language' => $language,
445+
]);
446+
447+
return $this->parseStatusUrl($response);
448+
}
449+
432450
/**
433451
* Generates a summarized version of the provided content.
434452
* Perfect for generating marketing introductions of longer texts.

0 commit comments

Comments
 (0)