-
Notifications
You must be signed in to change notification settings - Fork 42
Feature/ai abilities api #1204
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
base: develop
Are you sure you want to change the base?
Feature/ai abilities api #1204
Conversation
…es (list/create/update events & venues, calculate-dates). Enables natural language event management via WordPress REST API.
PR Summary
|
|
@jmarx quick notes:
This looks great! Thx! |
…ility Adds get_calculate_dates_ability() method that checks for ai/calculate-dates ability from external AI plugin and falls back to gatherpress/calculate-dates if not available. This allows GatherPress to use the external plugin's date calculator when available.
…s:ignore comments
| // Handle relative patterns first (next, last, this, tomorrow, yesterday). | ||
| $relative_weekday_pattern = '/^(next|last|this)\s+' | ||
| . '(monday|tuesday|wednesday|thursday|friday|saturday|sunday)$/i'; | ||
| if ( preg_match( $relative_weekday_pattern, $pattern_low, $matches ) ) { |
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.
Something like this would be a cleaner approach than this super long if/elseif statement.
private function get_pattern_handlers(): array {
return [
'/^(next|last|this)\s+(monday|tuesday|...)$/i' => 'handle_relative_weekday',
'/^(tomorrow|yesterday)$/i' => 'handle_relative_day',
// ...
];
}
private function calculate_recurring_dates( string $pattern, int $occurrences, \DateTime $start ): array {
foreach ( $this->get_pattern_handlers() as $regex => $method ) {
if ( preg_match( $regex, $pattern, $matches ) ) {
return $this->$method( $matches, $occurrences, $start );
}
}
return array();
}
| private function get_nth_weekday_of_month( int $year, int $month, string $weekday, int $nth ): string { | ||
| if ( -1 === $nth ) { | ||
| // Last occurrence. | ||
| $date = new \DateTime( "last {$weekday} of {$year}-{$month}" ); |
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.
Add use DateTime at top of file and call new DateTime (here and everywhere)
| private function get_gatherpress_functions() { | ||
| // Check if external AI plugin's calculate-dates ability is available. | ||
| // If so, use it instead of GatherPress's own implementation. | ||
| $calculate_dates_ability = Abilities_Integration::get_calculate_dates_ability(); |
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.
seems variable is only used once, so no need to set the variable, just include it in the array.
| 'tool_choice' => 'auto', | ||
| ); | ||
|
|
||
| $response = wp_remote_post( |
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.
Use wp_safe_remote_post here.
|
|
||
| // Max iterations reached. | ||
| return array( | ||
| 'response' => 'Task partially completed. Maximum iterations reached.', |
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.
Does this need translation function?
| ), | ||
| ); | ||
| } | ||
| } |
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.
I would make the AI Experiments plugin a dependency of this feature. Not sure when/if that code is making it into core eventually. But we should be utilizing core settings when we can and not including our own settings of the same thing. Maybe get some guidance here from @jeffpaul
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.
@mauteri very hard disagree. But just wait a bit for my latest stuff :) I'll explain what im doing
| $status.show(); | ||
|
|
||
| // Send to backend | ||
| $.ajax( { |
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.
Change to REST API and use apiFetch
| @@ -0,0 +1,168 @@ | |||
| .gp-ai-assistant { | |||
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.
Need to prepend with gatherpress- not gp-
| ), | ||
| utility_style: path.resolve( process.cwd(), 'src', 'utility.scss' ), | ||
| 'ai-assistant': path.resolve( process.cwd(), 'src/ai', 'index.js' ), | ||
| 'ai-assistant-style': path.resolve( process.cwd(), 'src/ai', 'style.scss' ), |
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.
use underscores to keep format.
- Extract and return model/provider metadata from AI responses - Display model info (provider and model name) in AI Assistant UI with styling - Add admin notice on wp-ai-client settings page recommending OpenAI - Update font size for model info display to 13px
- Test MAX_ITERATIONS constant - Test process_prompt with various error conditions - Test has_api_key method with different scenarios - Test get_gatherpress_abilities method - Test function_name_to_ability_name conversion - Test method existence for private methods using reflection - All 20 tests pass (3 skipped when dependencies not available)
- Fix line length issues by breaking long lines - Add @throws tag to process_conversation_loop method - Add phpcs:ignore for empty catch block with explanation - Add phpcs:ignore for translation strings that exceed line length - Fix inline comment punctuation - All errors resolved, warnings suppressed with appropriate comments
- Fix empty catch block by adding code (set provider_name to empty string) - Fix line length issues by shortening translation strings - Add @throws tag to process_conversation_loop method - Fix inline comment punctuation - All errors and warnings resolved (0 errors, 0 warnings)
- Break long translation string across multiple lines - All linting issues resolved for class-setup.php
…s test, remove old test files
…, init_wp_ai_client, increase_ai_request_timeout)
…comments for WP_Ability
Preview changes with PlaygroundYou can preview the recent changes for PR#1204 with the following PHP versions: PHP Version 8.4
PHP Version 8.2
PHP Version 7.4
Download Made with 💙 from GatherPress & a little bit of WordPress Playground. Changes will not persist between sessions. |
Description of the Change
Closes #
How to test the Change
Changelog Entry
Credits
Props @username, @username2, ...
Checklist: