-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug(SK): Fixed issues with Utilities & Refactored
- Loading branch information
1 parent
938029d
commit 653ef03
Showing
5 changed files
with
144 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace PapaRascalDev\Sidekick\Utilities; | ||
|
||
use Illuminate\Http\Client\ConnectionException; | ||
use PapaRascalDev\Sidekick\Drivers\OpenAi; | ||
use PapaRascalDev\Sidekick\Sidekick; | ||
|
||
/**************************************************************** | ||
* * | ||
* OpenAi Helper * | ||
* * | ||
* This is a set of helper functions for people using * | ||
* OpenAi models * | ||
* * | ||
****************************************************************/ | ||
|
||
class OpenAiExtras extends Utilities | ||
{ | ||
/** | ||
* @param string $content | ||
* @param string $model | ||
* @param array $exclusions | ||
* @return bool | ||
*/ | ||
public function isContentFlagged ( | ||
string $content, | ||
string $model = 'text-moderation-latest', | ||
array $exclusions = []) : bool | ||
{ | ||
$response = $this->sidekick->moderate() | ||
->text( model: $model, | ||
content: $content); | ||
|
||
if(!isset($response['results']['categories'])) return false; | ||
|
||
foreach($response['results']['categories'] as $category => $bool) { | ||
if (!in_array($category, $exclusions) && $bool) return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters