Skip to content
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

Add WP-CLI command to bulk process excerpts #516

Merged
merged 6 commits into from
Jul 3, 2023
Merged

Add WP-CLI command to bulk process excerpts #516

merged 6 commits into from
Jul 3, 2023

Conversation

dkotter
Copy link
Collaborator

@dkotter dkotter commented Jun 29, 2023

Description of the Change

In #405 we added the ability to manually generate excerpts on individual items. This is a follow up that adds a WP-CLI command that can be used to process items in bulk, adding generated excerpts to those items.

One thing to note is that OpenAI has rate limits on their APIs, so you may run into that if processing too many items at a time. For instance, free accounts only get 3 requests per minute on the ChatGPT API, so very easy to hit that. Paid accounts go up to 3500 requests per minute, so unlikely to run into issues. We may want to explore adding rate limiting into ClassifAI at some point to ensure these limits aren't hit.

The new command looks like:

wp classifai generate_excerpt

and has the following options:

  • A comma-delimited list of post IDs to process
  • A post_type argument that will be used if no post IDs are passed in
  • A post_status argument that will be used along with the post_type argument. Defaults to publish
  • A per_page argument. This controls how many items we process in each batch. Defaults to 100. As an example, if you have 1000 items to process, all of these will be processed but will be done in batches of 100 for performance reasons
  • A force argument that defaults to false. Will only process items that don't have an excerpt set if set to false
  • A dry-run argument that defaults to true. You must pass false to actually run the command

Here are some example commands that can be run:

wp classifai generate_excerpt 1,2,3 --dry-run=false
wp classifai generate_excerpt --post_type=post --dry-run=false
wp classifai generate_excerpt --post_type=page --per_page=5 --force=true --dry-run=false

Closes #416

How to test the Change

Try running some of the WP-CLI commands as described above and ensure they all work as expected

Changelog Entry

Added - Custom WP-CLI command that can be used to generate excerpts in bulk

Credits

Props @dkotter

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

@dkotter dkotter added this to the 2.2.3 milestone Jun 29, 2023
@dkotter dkotter requested review from a team and jeffpaul as code owners June 29, 2023 19:26
@dkotter dkotter self-assigned this Jun 29, 2023
@dkotter dkotter requested review from a team and iamdharmesh and removed request for a team and jeffpaul June 29, 2023 19:26
iamdharmesh
iamdharmesh previously approved these changes Jun 30, 2023
Copy link
Member

@iamdharmesh iamdharmesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this @dkotter. This looks great and works well. I haven't tested with large dataset but looks great. 🚀

Added some nice to have notes, but not necessary to fix to merge this

Thanks.

includes/Classifai/Command/ClassifaiCommand.php Outdated Show resolved Hide resolved
includes/Classifai/Command/ClassifaiCommand.php Outdated Show resolved Hide resolved
…ge instead of a logged message but don't stop execution
iamdharmesh
iamdharmesh previously approved these changes Jul 3, 2023
Copy link
Member

@iamdharmesh iamdharmesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@dkotter dkotter merged commit 1262e95 into develop Jul 3, 2023
@dkotter dkotter deleted the feature/416 branch July 3, 2023 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add WP-CLI command to bulk generate excerpts
2 participants