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 6f8f159 commit 7774807
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ If you don't use Laravel then you can find
- Easily translate text for a global audience.
- 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 @@ -89,7 +89,7 @@ and the process of checking the results, especially if you process bigger batche
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](#optional-custom-configuration)).
3. `SharpApiJob` object will be returned.
4. For a job finished with `success` return status you can obtain the results with one
Expand Down Expand Up @@ -137,7 +137,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 @@ -173,7 +173,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 @@ -373,6 +373,14 @@ 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 All @@ -382,6 +390,7 @@ marketing introductions of longer texts.
$statusUrl = \SharpApiService::summarizeText($text, 'English');
```


### SEO

#### Generate SEO Tags
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 @@ -84,7 +84,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 @@ -382,6 +382,24 @@ public function summarizeText(string $text, string $language = 'English'): strin
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);
}

/**
* Translates the provided text into selected language
* Perfect for generating marketing introductions of longer texts.
Expand Down

0 comments on commit 7774807

Please sign in to comment.