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

Content Generation UI #864

Draft
wants to merge 15 commits into
base: feature/841
Choose a base branch
from
6 changes: 3 additions & 3 deletions includes/Classifai/Features/ContentGeneration.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function register_endpoints() {
],
'title' => [
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'sanitize_callback' => 'wp_kses_post',
Copy link
Member Author

Choose a reason for hiding this comment

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

Very open to alternatives here. In my case I wanted to update my system prompt to something like:

Act as an experienced SEO copywriter tasked with writing an article based off of a given summary and an optionally provided title. Your goal is to craft a compelling, informative piece that adheres to SEO best practices, is well-researched, engaging to the target audience, and structured in a way that enhances readability. Incorporate relevant keywords naturally throughout the text, without compromising the flow or quality of the content. Ensure that the article provides value to the reader. 

You produce valid WordPress block markup of heading, paragraph, and list. Don't generate any other type of output and don't use Markdown formatting.

The markup of a heading looks like this: 

<!-- wp:heading -->
<h2 class="wp-block-heading">CONTENT</h2>
<!-- /wp:heading -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading">CONTENT</h3>
<!-- /wp:heading -->

<!-- wp:heading {"level":4} -->
<h4 class="wp-block-heading">CONTENT</h4>
<!-- /wp:heading -->

<!-- wp:heading {"level":5} -->
<h5 class="wp-block-heading">CONTENT</h5>
<!-- /wp:heading -->

The markup of a paragraph looks like this:
<!-- wp:paragraph -->
<p>CONTENT</p>
<!-- /wp:paragraph -->

The markup of a list looks like this: 
<!-- wp:list -->
<ul class="wp-block-list"><!-- wp:list-item -->
<li>CONTENT</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>CONTENT</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>CONTENT</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>CONTENT</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->

<!-- wp:list {"ordered":true} -->
<ol class="wp-block-list"><!-- wp:list-item -->
<li>CONTENT</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>CONTENT</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>CONTENT</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>CONTENT</li>
<!-- /wp:list-item --></ol>
<!-- /wp:list -->


Only return the contents of the article, not the title or other commentary.

Which failed unless I updated the sanizitation to allow for HTML tags...

'validate_callback' => 'rest_validate_request_arg',
'description' => esc_html__( 'The title of the article.', 'classifai' ),
],
Expand All @@ -104,13 +104,13 @@ public function register_endpoints() {
'properties' => [
'prompt' => [
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'sanitize_callback' => 'wp_kses_post',
'validate_callback' => 'rest_validate_request_arg',
'description' => esc_html__( 'The prompt a user sent.', 'classifai' ),
],
'response' => [
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'sanitize_callback' => 'wp_kses_post',
'validate_callback' => 'rest_validate_request_arg',
'description' => esc_html__( 'The response from the assistant to the prompt.', 'classifai' ),
],
Expand Down
2 changes: 1 addition & 1 deletion includes/Classifai/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ function ( $prompt ) use ( &$has_default ) {

return array(
'title' => sanitize_text_field( $prompt['title'] ),
'prompt' => sanitize_textarea_field( $prompt['prompt'] ),
'prompt' => wp_kses_post( $prompt['prompt'] ),
'default' => absint( $default ),
'original' => absint( $prompt['original'] ),
);
Expand Down
Loading
Loading