Skip to content

Commit

Permalink
1.2 wip
Browse files Browse the repository at this point in the history
  • Loading branch information
makowskid committed Aug 26, 2024
1 parent 60a6c7f commit 3aacee7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

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

## March 23, 2024 - v1.1.0 update

### 1. new methods added

Expand Down Expand Up @@ -115,4 +119,4 @@ SHARP_API_USER_AGENT="SharpAPILaravelAgent/1.1.0"
More info at https://sharpapi.com/affiliate_program

## December 10, 2023 - v1.0.2
- v1.0.2 initial release
- v1.0.2 initial release
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@

# SharpAPI Laravel Client SDK

### 🚀 Automate with AI in just two lines of code. Save countless hours and enhance your app effortlessly.
### 🚀 Automate workflows with AI-powered API

## Leverage AI API to streamline workflows in E-Commerce, Marketing, Content Management, HR Tech, Travel, and more.

[![Latest Version on Packagist](https://img.shields.io/packagist/v/sharpapi/sharpapi-laravel-client.svg?style=flat-square)](https://packagist.org/packages/sharpapi/sharpapi-laravel-client)
[![Total Downloads](https://img.shields.io/packagist/dt/sharpapi/sharpapi-laravel-client.svg?style=flat-square)](https://packagist.org/packages/sharpapi/sharpapi-laravel-client)

#### Save time on repetitive content analysis and generation tasks that your app users perform daily.

See more at [SharpAPI.com Website »](https://sharpapi.com/)

---
Expand Down Expand Up @@ -75,10 +73,9 @@ Please refer to the official:

```bash
composer require sharpapi/sharpapi-laravel-client
php artisan vendor:publish --tag=sharpapi-laravel-client
```

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

3. Set the API key inside `.env`

Expand Down Expand Up @@ -506,7 +503,8 @@ $statusUrl = \SharpApiService::generateKeywords(
$text,
'English', // optional language
5, // optional length
'Freaky & Curious' // optional voice tone
'Freaky & Curious', // optional voice tone
'add emojis!' // optional extra context instructions for content processing
);
```

Expand All @@ -526,7 +524,8 @@ It can be adjectives like `funny` or `joyous`, or even the name of a famous writ
$statusUrl = \SharpApiService::summarizeText(
$text,
'English', // optional language
'David Attenborough' // optional voice tone
'David Attenborough', // optional voice tone
'add emojis!' // optional extra context instructions for content processing
);
```

Expand Down
11 changes: 5 additions & 6 deletions src/Dto/SharpApiJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
class SharpApiJob extends Data
{
public function __construct(
public string $id,
public string $type,
public string $status,
public string $id,
public string $type,
public string $status,
public ?stdClass $result
) {
}
) {}

/**
* Returns SharpAPI job ID (UUID format)
Expand Down Expand Up @@ -66,7 +65,7 @@ public function getResultJson(): string|bool|null
*/
public function getResultArray(): ?array
{
return (array) $this->result;
return (array)$this->result;
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/SharpApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ private function makeRequest(

private function parseStatusUrl(ResponseInterface $response)
{
\Log::debug('DBG parseStatusUrl:', [json_decode($response->getBody()->__toString(), true)['status_url']]);
return json_decode($response->getBody()->__toString(), true)['status_url'];
}

Expand Down Expand Up @@ -187,14 +186,11 @@ public function fetchResults(string $statusUrl): SharpApiJob
} while (true);

$data = json_decode($response->getBody()->__toString(), true)['data'];
\Log::debug('DBG data:', $data);

$url = Url::fromString($statusUrl);
if(count($url->getSegments()) == 5) { // shared job result URL
\Log::debug('DBG 5 segments:'.$url);
$result = json_decode($data['attributes']['result']);
$result = (object) json_decode($data['attributes']['result']);
} else { // 7 segments, 1-to-1 job to result url
\Log::debug('DBG 7 segments:'.$url);
$result = (object)$data['attributes']['result'];
}

Expand Down

0 comments on commit 3aacee7

Please sign in to comment.