-
-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce improvements to AI process #651
base: master
Are you sure you want to change the base?
Conversation
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe pull request introduces a significant refactoring of the wiki request management system, focusing on data handling and error reporting. The changes consolidate multiple individual parameters into a single Changes
Sequence DiagramsequenceDiagram
participant User
participant WikiRequestManager
participant RequestWikiRemoteAIJob
participant OpenAI
User->>WikiRequestManager: Submit Wiki Request
WikiRequestManager->>RequestWikiRemoteAIJob: Create Job with extraData
RequestWikiRemoteAIJob->>OpenAI: Query AI Evaluation
OpenAI-->>RequestWikiRemoteAIJob: Return Decision
RequestWikiRemoteAIJob->>WikiRequestManager: Process AI Decision
WikiRequestManager-->>User: Provide Feedback
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@coderabbitai review
@coderabbitai review |
Check commit and GitHub actions for more details
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 7
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
i18n/en.json
(1 hunks)includes/Jobs/RequestWikiRemoteAIJob.php
(9 hunks)includes/Services/WikiRequestManager.php
(4 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
includes/Services/WikiRequestManager.php (1)
Pattern **/*.php
: Follow MediaWiki PHP Coding Standards:
Indentation:
- Use tabs for indentation, not spaces.
Spaces:
- Use spaces on either side of binary operators.
Example: $a = $b + $c; (Correct) $a=$b+$c; (Incorrect) - Add spaces inside parentheses, except where they are empty.
Example: $a = getFoo( $b ); (Correct) $a = getFoo($b); (Incorrect) - Do not add a space after a function name.
Example: $c = getBar(); (Correct) $c = getBar (); (Incorrect)
Function Return Type Hint:
- Add a space after the colon in the function return type hint.
Example: function square( int $x ): int { return $x * $x; }
Arrays:
- Use spaces in brackets when declaring an array, except where the array is empty.
Example: $a = [ 'foo', 'bar' ]; (Correct) $a = ['foo', 'bar']; (Incorrect) - Do not put spaces in brackets when accessing array elements.
Example: $c = $a[0]; (Correct) $c = $a[ 0 ]; (Incorrect)
Control Structures:
- Add a space after control structure keywords.
Example: if ( isFoo() ) { ... } (Correct) if(isFoo()){ ... } (Incorrect)
Type Casting:
- Do not use a space within or after the cast operator.
Example: (int)$foo; (Correct) (int) $bar; (Incorrect)
Comments:
- In comments, there should be one space between the # or // and the comment text.
Example: // This is a comment. (Correct) //This is a comment. (Incorrect)
Ternary Operator:
- Keep ternary operator expressions short and obvious.
- For multi-line ternary expressions, place the '?' and ':' at the beginning of the new lines.
File Formatting:
- Avoid trailing whitespace on lines.
includes/Jobs/RequestWikiRemoteAIJob.php (1)
Pattern **/*.php
: Follow MediaWiki PHP Coding Standards:
Indentation:
- Use tabs for indentation, not spaces.
Spaces:
- Use spaces on either side of binary operators.
Example: $a = $b + $c; (Correct) $a=$b+$c; (Incorrect) - Add spaces inside parentheses, except where they are empty.
Example: $a = getFoo( $b ); (Correct) $a = getFoo($b); (Incorrect) - Do not add a space after a function name.
Example: $c = getBar(); (Correct) $c = getBar (); (Incorrect)
Function Return Type Hint:
- Add a space after the colon in the function return type hint.
Example: function square( int $x ): int { return $x * $x; }
Arrays:
- Use spaces in brackets when declaring an array, except where the array is empty.
Example: $a = [ 'foo', 'bar' ]; (Correct) $a = ['foo', 'bar']; (Incorrect) - Do not put spaces in brackets when accessing array elements.
Example: $c = $a[0]; (Correct) $c = $a[ 0 ]; (Incorrect)
Control Structures:
- Add a space after control structure keywords.
Example: if ( isFoo() ) { ... } (Correct) if(isFoo()){ ... } (Incorrect)
Type Casting:
- Do not use a space within or after the cast operator.
Example: (int)$foo; (Correct) (int) $bar; (Incorrect)
Comments:
- In comments, there should be one space between the # or // and the comment text.
Example: // This is a comment. (Correct) //This is a comment. (Incorrect)
Ternary Operator:
- Keep ternary operator expressions short and obvious.
- For multi-line ternary expressions, place the '?' and ':' at the beginning of the new lines.
File Formatting:
- Avoid trailing whitespace on lines.
🔇 Additional comments (1)
includes/Services/WikiRequestManager.php (1)
993-993
: 🛠️ Refactor suggestionRemove trailing comma in function parameter list
Trailing commas in function parameter lists are only supported in PHP 7.3 and above. Remove the trailing comma to ensure compatibility with earlier PHP versions.
Apply this diff to remove the trailing comma:
private function evaluateWithOpenAI( array $extraData, string $subdomain, - string $username, + string $username ): void {Likely invalid or redundant comment.
Check commit and GitHub actions for more details
Check commit and GitHub actions for more details
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
includes/Jobs/RequestWikiRemoteAIJob.php (1)
171-171
: Add validation for confidence scores.While the confidence score implementation is good, it would be safer to validate the confidence value to ensure it's within expected bounds (0-100).
Apply this diff to add validation:
+ private function validateConfidence( int $confidence ): int { + return max(0, min(100, $confidence)); + } private function handleDryRun( string $outcome, string $comment, int $confidence ): bool { + $confidence = $this->validateConfidence($confidence); $outcomeMessage = $this->context->msg( 'requestwikiqueue-' . $outcome )->text(); private function handleLiveRun( string $outcome, string $comment, int $confidence ): bool { + $confidence = $this->validateConfidence($confidence); $systemUser = User::newSystemUser( 'CreateWiki AI' );Also applies to: 174-174, 177-177, 211-211, 227-228
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
i18n/en.json
(1 hunks)i18n/qqq.json
(1 hunks)includes/Jobs/RequestWikiRemoteAIJob.php
(8 hunks)includes/Services/WikiRequestManager.php
(4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- i18n/en.json
🧰 Additional context used
📓 Path-based instructions (2)
includes/Services/WikiRequestManager.php (1)
Pattern **/*.php
: Follow MediaWiki PHP Coding Standards:
Indentation:
- Use tabs for indentation, not spaces.
Spaces:
- Use spaces on either side of binary operators.
Example: $a = $b + $c; (Correct) $a=$b+$c; (Incorrect) - Add spaces inside parentheses, except where they are empty.
Example: $a = getFoo( $b ); (Correct) $a = getFoo($b); (Incorrect) - Do not add a space after a function name.
Example: $c = getBar(); (Correct) $c = getBar (); (Incorrect)
Function Return Type Hint:
- Add a space after the colon in the function return type hint.
Example: function square( int $x ): int { return $x * $x; }
Arrays:
- Use spaces in brackets when declaring an array, except where the array is empty.
Example: $a = [ 'foo', 'bar' ]; (Correct) $a = ['foo', 'bar']; (Incorrect) - Do not put spaces in brackets when accessing array elements.
Example: $c = $a[0]; (Correct) $c = $a[ 0 ]; (Incorrect)
Control Structures:
- Add a space after control structure keywords.
Example: if ( isFoo() ) { ... } (Correct) if(isFoo()){ ... } (Incorrect)
Type Casting:
- Do not use a space within or after the cast operator.
Example: (int)$foo; (Correct) (int) $bar; (Incorrect)
Comments:
- In comments, there should be one space between the # or // and the comment text.
Example: // This is a comment. (Correct) //This is a comment. (Incorrect)
Ternary Operator:
- Keep ternary operator expressions short and obvious.
- For multi-line ternary expressions, place the '?' and ':' at the beginning of the new lines.
File Formatting:
- Avoid trailing whitespace on lines.
includes/Jobs/RequestWikiRemoteAIJob.php (1)
Pattern **/*.php
: Follow MediaWiki PHP Coding Standards:
Indentation:
- Use tabs for indentation, not spaces.
Spaces:
- Use spaces on either side of binary operators.
Example: $a = $b + $c; (Correct) $a=$b+$c; (Incorrect) - Add spaces inside parentheses, except where they are empty.
Example: $a = getFoo( $b ); (Correct) $a = getFoo($b); (Incorrect) - Do not add a space after a function name.
Example: $c = getBar(); (Correct) $c = getBar (); (Incorrect)
Function Return Type Hint:
- Add a space after the colon in the function return type hint.
Example: function square( int $x ): int { return $x * $x; }
Arrays:
- Use spaces in brackets when declaring an array, except where the array is empty.
Example: $a = [ 'foo', 'bar' ]; (Correct) $a = ['foo', 'bar']; (Incorrect) - Do not put spaces in brackets when accessing array elements.
Example: $c = $a[0]; (Correct) $c = $a[ 0 ]; (Incorrect)
Control Structures:
- Add a space after control structure keywords.
Example: if ( isFoo() ) { ... } (Correct) if(isFoo()){ ... } (Incorrect)
Type Casting:
- Do not use a space within or after the cast operator.
Example: (int)$foo; (Correct) (int) $bar; (Incorrect)
Comments:
- In comments, there should be one space between the # or // and the comment text.
Example: // This is a comment. (Correct) //This is a comment. (Incorrect)
Ternary Operator:
- Keep ternary operator expressions short and obvious.
- For multi-line ternary expressions, place the '?' and ':' at the beginning of the new lines.
File Formatting:
- Avoid trailing whitespace on lines.
🔇 Additional comments (6)
includes/Jobs/RequestWikiRemoteAIJob.php (2)
40-40
: LGTM! Good consolidation of properties.The addition of
extraData
array property helps consolidate multiple individual properties, improving code maintainability.
115-126
: Well-structured error handling implementation!The error handling has been improved with:
- User-friendly error messages using i18n
- Proper logging of errors
- History tracking for debugging
- Clear separation between public and internal error messages
Also applies to: 130-153
i18n/qqq.json (1)
125-127
: LGTM! Clear and well-documented i18n messages.The new error message entries are well-documented, providing clear context for translators about when each message is used.
includes/Services/WikiRequestManager.php (3)
677-679
: LGTM! Useful convenience method.The
getRequesterUsername
method provides a convenient way to get the username string directly, reducing the need for chained method calls.
985-994
: LGTM! Good simplification of the API.The
evaluateWithOpenAI
method has been simplified to only pass the request ID, which is a cleaner approach as all other data can be retrieved from the database using this ID.
370-374
: LGTM! Correct user comparison.The method now properly compares the username using
getName()
instead of comparing the UserIdentity object directly to a string.
Check commit and GitHub actions for more details
"Category: '$category'. Contains content that is not safe for work? '$isNsfw'. " . | ||
$nsfwReasonText . "Wiki request reason: " . | ||
trim( str_replace( [ "\r\n", "\r" ], "\n", $reason ) ); | ||
$forkText = !empty( $extraData['sourceurl'] ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we bringing html into this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra security against inputs in RequestWiki. Do you think this is not necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use str_replace( '\'', '\\\'', $text )
(and escape backslashes, newlines, potentially control characters, etc)
Though, even escaping is not enough (for example, clearly delinated user input can be interpreted as instructions, and this still can apply to the chat API)
// Extract response details with default fallbacks | ||
$confidence = $apiResponse['recommendation']['confidence'] ?? '0'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be casted to an int, otherwise the functions that take this in will die if they're type hinted
This change introduces:
Summary by CodeRabbit
Release Notes
New Features
Improvements
Bug Fixes
The update provides more transparent and user-friendly AI-assisted wiki request processing, with clearer communication about evaluation outcomes and potential issues.