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/open ai useselect #28483

Merged
merged 41 commits into from
Jan 25, 2023
Merged

Add/open ai useselect #28483

merged 41 commits into from
Jan 25, 2023

Conversation

millerf
Copy link
Contributor

@millerf millerf commented Jan 20, 2023

Fixes #28389

Proposed changes:

  • It works with unsaved posts,
  • It handles multiple AI paragraph blocks at the same time
  • Updates nb of charcaters left dynamically
  • Takes into accounts categories and tags
  • Code is not spaghetti-based

Does this pull request change what data or activity we track or use?

No

Testing instructions:

Sandbox a WPCOM site and push this to your favorite sandbox with

$> ~/public_html/bin/jetpack-downloader test jetpack add/open-ai-useselect
  • create a new post
  • add a title only
  • create AI paragraph
  • it should tell you it misses characters. Enter some and voilà.
  • add another AI parapgrah blocks behind it, it should say it needs to wait for the previous block to fini

Screenshot 2023-01-20 at 20 15 13

  • Open the console and play with it, you can add/remove categories and tags, and it should send the right prompts.

@millerf millerf marked this pull request as draft January 20, 2023 10:06
@github-actions github-actions bot added [Block] AI Paragraph [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ labels Jan 20, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jan 20, 2023

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ⚠️ All commits were linted before commit.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team review" label and ask someone from your team review the code.
Once you’ve done so, switch to the "[Status] Needs Review" label; someone from Jetpack Crew will then review this PR and merge it to be included in the next Jetpack release.


Jetpack plugin:

  • Next scheduled release: February 7, 2023.
  • Scheduled code freeze: January 31, 2023.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 20, 2023

Are you an Automattician? You can now test your Pull Request on WordPress.com. On your sandbox, run bin/jetpack-downloader test jetpack add/open-ai-useselect to get started. More details: p9dueE-5Nn-p2

@github-actions github-actions bot added the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label Jan 20, 2023
@artpi
Copy link
Contributor

artpi commented Jan 20, 2023

This may be kind of relevant #28488

@millerf millerf force-pushed the add/open-ai-useselect branch from f5b43ca to e3977f2 Compare January 20, 2023 18:59
@millerf millerf self-assigned this Jan 20, 2023
@millerf millerf marked this pull request as ready for review January 20, 2023 19:16
Copy link
Contributor

@n3f n3f left a comment

Choose a reason for hiding this comment

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

Looks good to me. I added some comments that aren't necessarily blockers, but I would like others to look before I approved!

Comment on lines 207 to 242
const waitingState = completionFinished || loadingCompletion || loadingCategories;
const nbCharactersNeeded = numberOfCharactersNeeded - content.length;
if ( ! waitingState ) {
if ( containsAiUntriggeredParapgraph( contentBefore ) ) {
if ( ! errorMessage ) {
setErrorMessage(
/** translators: This will be an error message when multiple Open AI paragraph blocks are triggered on the same page. */
__( 'Waiting for the previous AI paragraph block to finish', 'jetpack' )
);
}
} else if (
content.length < numberOfCharactersNeeded &&
needsMoreCharacters !== nbCharactersNeeded
) {
setErrorMessage(
sprintf(
/** translators: First placeholder is a number of more characters we need */
__(
'Please write a longer title or a few more words in the opening preceding the AI block. Our AI model needs %1$d more characters.',
'jetpack'
),
nbCharactersNeeded
)
);
setNeedsMoreCharacters( nbCharactersNeeded );
} else if ( needsMoreCharacters !== 0 && content.length >= numberOfCharactersNeeded ) {
setErrorMessage(
/** translators: This is to retry to complete the text */
__( 'Ready to retry', 'jetpack' )
);
setShowRetry( true );
setNeedsMoreCharacters( 0 );
} else if ( needsMoreCharacters === 0 && ! showRetry ) {
getSuggestionFromOpenAI();
}
}, [ setAttributes, attributes ] ); // eslint-disable-line react-hooks/exhaustive-deps
}
Copy link
Contributor

@n3f n3f Jan 20, 2023

Choose a reason for hiding this comment

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

Should this all just go in a useEffect?

useEffect( () => {
	if ( completionFinished || loadingCompletion || loadingCategories ) {
		return;
	}
	// ...
}, [ completionFinished, loadingCompletion, loadingCategories ] );

Copy link
Contributor

@n3f n3f Jan 20, 2023

Choose a reason for hiding this comment

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

See my other comment above about the logic of that if not being correct...

@millerf millerf dismissed stale reviews from romarioraffington, n3f, and artpi via 19b7ec9 January 25, 2023 09:01
@millerf
Copy link
Contributor Author

millerf commented Jan 25, 2023

if it's an OpenAI caching issue and not the prompt changing either...

Should we have some sort of a timer/message saying that the response won't change for a minute...

Definitely. That will be in another PR, though.

@millerf millerf added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Jan 25, 2023
@artpi
Copy link
Contributor

artpi commented Jan 25, 2023

Definitely. That will be in another PR, though.

Yes, that should be another PR

artpi
artpi previously approved these changes Jan 25, 2023
Copy link
Contributor

@artpi artpi left a comment

Choose a reason for hiding this comment

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

This tests well, I think I have enough of this PR :D

Copy link
Contributor

@artpi artpi left a comment

Choose a reason for hiding this comment

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

Merged master, resolved conflicts and accepting again

@artpi artpi requested a review from jeherve January 25, 2023 14:48
@millerf
Copy link
Contributor Author

millerf commented Jan 25, 2023

This tests well, I think I have enough of this PR :D

So do I...

@millerf millerf merged commit 5772ba0 into trunk Jan 25, 2023
@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Jan 25, 2023
@millerf millerf deleted the add/open-ai-useselect branch January 25, 2023 15:32
@github-actions github-actions bot added this to the jetpack/11.8 milestone Jan 25, 2023
@github-actions github-actions bot removed the [Status] Ready to Merge Go ahead, you can push that green button! label Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] AI Paragraph [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Jetpack AI] Rewrite AI Paragraph block render flow
6 participants