Skip to content

Commit

Permalink
adding keywords/tags method
Browse files Browse the repository at this point in the history
  • Loading branch information
makowskid committed Jan 2, 2024
1 parent 3f403a2 commit 9f9109a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -77,15 +77,15 @@ $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());
```
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.
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/Enums/SharpApiJobTypeEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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',
};
Expand All @@ -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',
};
Expand Down
20 changes: 19 additions & 1 deletion src/SharpApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 9f9109a

Please sign in to comment.