Skip to content

Commit

Permalink
Consider more parameters to take a decision
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentIsai authored Nov 22, 2024
1 parent d4ffb98 commit 54928b4
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 5 deletions.
46 changes: 43 additions & 3 deletions includes/Jobs/RequestWikiRemoteAIJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ class RequestWikiRemoteAIJob extends Job {
private string $reason;
private string $sitename;
private string $subdomain;
private string $username;
private string $language;
private bool $bio;
private bool $private;
private string $category;
private bool $nsfw;
private string $nsfwtext;

public function __construct(
array $params,
Expand All @@ -54,6 +61,13 @@ public function __construct(
$this->reason = $params['reason'];
$this->sitename = $params['sitename'];
$this->subdomain = $params['subdomain'];
$this->username = $params['username'];
$this->language = $params['language'];
$this->bio = $params['bio'];
$this->private = $params['private'];
$this->category = $params['category'];
$this->nsfw = $params['nsfw'];
$this->nsfwtext = $params['nsfwtext'];
}

public function run(): bool {
Expand Down Expand Up @@ -93,7 +107,18 @@ public function run(): bool {
]
);

$apiResponse = $this->queryOpenAI( $this->sitename, $this->subdomain, $this->reason );
$apiResponse = $this->queryOpenAI(
$this->sitename,
$this->subdomain,
$this->reason,
$this->username,
$this->language,
$this->bio,
$this->private,
$this->category,
$this->nsfw,
$this->nsfwtext
);

if ( !$apiResponse ) {
return true;
Expand Down Expand Up @@ -249,10 +274,25 @@ private function handleLiveRun( string $outcome, string $comment ): bool {
private function queryOpenAI(
string $sitename,
string $subdomain,
string $reason
string $reason,
string $username,
string $language,
bool $bio,
bool $private,
string $category,
bool $nsfw,
string $nsfwtext
): ?array {
try {
$sanitizedReason = "Wiki name: $sitename. Subdomain: $subdomain. Wiki request reason: " .
$isBio = $bio ? "Yes" : "No";
$isPrivate = $private ? "Yes" : "No";
$isNsfw = $nsfw ? "Yes" . $nsfwtext : "No";
$nsfwReasonText = $nsfw ? "What type of NSFW content will it feature? '$nsfwtext'. " : "";

$sanitizedReason = "Wiki name: '$sitename'. Subdomain: '$subdomain'. Requester: '$username'. " .
"Language: '$language'. Focuses on real people/groups? '$isBio'. Private wiki? '$isPrivate'. " .
"Category: '$category'. Contains content that is not safe for work? '$isNsfw'. " .
$nsfwReasonText . "Wiki request reason: " .
trim( str_replace( [ "\r\n", "\r" ], "\n", $reason ) );

// Step 1: Create a new thread
Expand Down
28 changes: 26 additions & 2 deletions includes/Services/WikiRequestManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,17 @@ public function createNewRequestAndLog(
$this->options->get( ConfigNames::OpenAIConfig )['apikey'] &&
$this->options->get( ConfigNames::OpenAIConfig )['assistantid']
) {
$this->evaluateWithOpenAI( $data['sitename'], $data['subdomain'], $data['reason'] );
$this->evaluateWithOpenAI( $data['sitename'],
$data['subdomain'],
$data['reason'],
$user->getName(),
$data['language'],
$data['bio'],
$data['private'] ?? 0,
$data['category'] ?? '',
$extraData['nsfw'] ?? 0,
$extraData['nsfwtext'] ?? ''
);
}

$this->logNewRequest( $data, $user );
Expand Down Expand Up @@ -975,7 +985,14 @@ private function tryAutoCreate( string $reason ): void {
private function evaluateWithOpenAI(
string $sitename,
string $subdomain,
string $reason
string $reason,
string $username,
string $language,
bool $bio,
bool $private,
string $category,
bool $nsfw,
string $nsfwtext
): void {
$jobQueueGroup = $this->jobQueueGroupFactory->makeJobQueueGroup();
$jobQueueGroup->push(
Expand All @@ -986,6 +1003,13 @@ private function evaluateWithOpenAI(
'sitename' => $sitename,
'subdomain' => $subdomain,
'reason' => $reason,
'username' => $username,
'language' => $language,
'bio' => $bio,
'private' => $private,
'category' => $category,
'nsfw' => $nsfw,
'nswftext' => $nsfwtext
]
)
);
Expand Down

0 comments on commit 54928b4

Please sign in to comment.