Skip to content

Commit e790128

Browse files
committed
release 1.2
1 parent d9fcba1 commit e790128

File tree

5 files changed

+33
-16
lines changed

5 files changed

+33
-16
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22

3-
## March 23, 2023 - v1.1.0 update
3+
## August 26, 2024 - v1.2.0 update
4+
- Generate Keywords/Tags & Summarize methods aquired optional `context` that allows to pass additional processing instructions for the provided `content`
5+
- API useage optimized internall, switched to AI job dispatch/result endpoint pairing mode
6+
7+
## March 23, 2024 - v1.1.0 update
48

59
### 1. new methods added
610

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
# SharpAPI PHP Client - #AI Programming Interface
44

5-
### 🚀 AI-Powered Swiss Army Knife API
5+
### 🚀 Automate workflows with AI-powered API
66

7-
## Save countless hours and supercharge your app with AI capabilities in just 2 lines of code.
7+
## Leverage AI API to streamline workflows in E-Commerce, Marketing, Content Management, HR Tech, Travel, and more.
88

99
[![Latest Version on Packagist](https://img.shields.io/packagist/v/sharpapi/sharpapi-php-client.svg?style=flat-square)](https://packagist.org/packages/sharpapi/sharpapi-php-client)
1010
[![Total Downloads](https://img.shields.io/packagist/dt/sharpapi/sharpapi-php-client.svg?style=flat-square)](https://packagist.org/packages/sharpapi/sharpapi-php-client)
@@ -64,7 +64,7 @@ Please refer to the official:
6464
composer require sharpapi/sharpapi-php-client
6565
```
6666

67-
2. Register at [SharpApi.com](https://sharpapi.com/) and get the API key.
67+
2. Register at [SharpAPI.com](https://sharpapi.com/) and get the API key.
6868

6969
3. **That's it!**
7070

@@ -483,7 +483,8 @@ $statusUrl = \SharpApiService::generateKeywords(
483483
$text,
484484
'English', // optional language
485485
5, // optional length
486-
'Freaky & Curious' // optional voice tone
486+
'Freaky & Curious', // optional voice tone
487+
'add emojis!' // optional extra context instructions for content processing
487488
);
488489
```
489490

@@ -503,7 +504,8 @@ It can be adjectives like `funny` or `joyous`, or even the name of a famous writ
503504
$statusUrl = \SharpApiService::summarizeText(
504505
$text,
505506
'English', // optional language
506-
'David Attenborough' // optional voice tone
507+
'David Attenborough', // optional voice tone
508+
'add emojis!' // optional extra context instructions for content processing
507509
);
508510
```
509511

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"php": "^8.1",
3737
"guzzlehttp/guzzle": "^7.8",
3838
"kongulov/interact-with-enum": "^1.0",
39-
"nesbot/carbon": "^3.0"
39+
"nesbot/carbon": "^3.0",
40+
"spatie/url": "^2.4"
4041
},
4142
"autoload": {
4243
"psr-4": {

src/Dto/SharpApiJob.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function __construct(
1414
public string $id,
1515
public string $type,
1616
public string $status,
17-
public ?string $result
17+
public ?stdClass $result
1818
)
1919
{
2020
}
@@ -66,7 +66,7 @@ public function getStatus(): SharpApiJobStatusEnum
6666
*/
6767
public function getResultJson(): string|bool|null
6868
{
69-
return $this->result ? json_encode(json_decode($this->result), JSON_PRETTY_PRINT) : null;
69+
return $this->result ? json_encode($this->result, JSON_PRETTY_PRINT) : null;
7070
}
7171

7272
/**
@@ -76,7 +76,7 @@ public function getResultJson(): string|bool|null
7676
*/
7777
public function getResultArray(): ?array
7878
{
79-
return $this->result ? json_decode($this->result, true) : null;
79+
return (array) $this->result;
8080
}
8181

8282
/**
@@ -86,6 +86,6 @@ public function getResultArray(): ?array
8686
*/
8787
public function getResultObject(): ?stdClass
8888
{
89-
return $this->result ? json_decode($this->result) : null;
89+
return $this->result;
9090
}
9191
}

src/SharpApiService.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use SharpAPI\SharpApiService\Dto\SharpApiSubscriptionInfo;
1616
use SharpAPI\SharpApiService\Enums\SharpApiJobStatusEnum;
1717
use SharpAPI\SharpApiService\Enums\SharpApiJobTypeEnum;
18+
use Spatie\Url\Url;
1819

1920
/**
2021
* Main Service to dispatch AI jobs to SharpAPI.com
@@ -49,7 +50,7 @@ public function __construct(string $apiKey, ?string $apiBaseUrl = null, ?string
4950
throw new InvalidArgumentException('API key is required.');
5051
}
5152
$this->setApiBaseUrl($apiBaseUrl ?? 'https://sharpapi.com/api/v1');
52-
$this->setUserAgent($userAgent ?? 'SharpAPIPHPAgent/1.1.0');
53+
$this->setUserAgent($userAgent ?? 'SharpAPIPHPAgent/1.2.0');
5354
}
5455

5556
/**
@@ -220,12 +221,17 @@ public function fetchResults(string $statusUrl): SharpApiJob
220221
sleep($retryAfter);
221222
} while (true);
222223
$data = json_decode($response->getBody()->__toString(), true)['data'];
223-
224+
$url = Url::fromString($statusUrl);
225+
if (count($url->getSegments()) == 5) { // shared job result URL
226+
$result = (object) json_decode($data['attributes']['result']);
227+
} else { // 7 segments, 1-to-1 job to result url
228+
$result = (object) $data['attributes']['result'];
229+
}
224230
return new SharpApiJob(
225231
id: $data['id'],
226232
type: $data['attributes']['type'],
227233
status: $data['attributes']['status'],
228-
result: $data['attributes']['result'] ?? null
234+
result: $result ?? null
229235
);
230236
}
231237

@@ -581,7 +587,8 @@ public function summarizeText(
581587
string $text,
582588
?string $language = null,
583589
?int $maxLength = null,
584-
?string $voiceTone = null
590+
?string $voiceTone = null,
591+
?string $context = null
585592
): string
586593
{
587594
$response = $this->makeRequest(
@@ -592,6 +599,7 @@ public function summarizeText(
592599
'language' => $language,
593600
'max_length' => $maxLength,
594601
'voice_tone' => $voiceTone,
602+
'context' => $context,
595603
]);
596604

597605
return $this->parseStatusUrl($response);
@@ -608,7 +616,8 @@ public function generateKeywords(
608616
string $text,
609617
?string $language = null,
610618
?int $maxQuantity = null,
611-
?string $voiceTone = null
619+
?string $voiceTone = null,
620+
?string $context = null
612621
): string
613622
{
614623
$response = $this->makeRequest(
@@ -619,6 +628,7 @@ public function generateKeywords(
619628
'language' => $language,
620629
'max_quantity' => $maxQuantity,
621630
'voice_tone' => $voiceTone,
631+
'context' => $context,
622632
]);
623633

624634
return $this->parseStatusUrl($response);

0 commit comments

Comments
 (0)