Skip to content

Commit

Permalink
use AI helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
mslinnea committed Nov 14, 2024
1 parent 8f27450 commit 62afd23
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
7 changes: 3 additions & 4 deletions src/components/metaDescription/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useSelect } from '@wordpress/data';
import { usePostMetaValue } from '@alleyinteractive/block-editor-tools';
import generatePrompt from './prompt';

const { store: aiStore } = window.aiServices.ai;
const { store: aiStore, helpers: aiHelpers } = window.aiServices.ai;

function MetaDescriptionField() {
const [metaDescription, setMetaDescription] = usePostMetaValue('_meta_description');
Expand Down Expand Up @@ -59,9 +59,8 @@ function MetaDescriptionField() {
return;
}

const description = candidates[0].content.parts[0].text.replaceAll(
'\n\n\n\n',
'\n\n',
const description = aiHelpers.getTextFromContents(
aiHelpers.getCandidateContents(candidates),
);

setMetaDescription(description);
Expand Down
9 changes: 4 additions & 5 deletions src/components/metaKeywords/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
} from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { usePostMetaValue } from '@alleyinteractive/block-editor-tools';
import generateKeywordsPrompt from './prompt'; // Adjust this if you have a separate function for keywords
import generateKeywordsPrompt from './prompt';

const { store: aiStore } = window.aiServices.ai;
const { store: aiStore, helpers: aiHelpers } = window.aiServices.ai;

function MetaKeywordsField() {
const [metaKeywords, setMetaKeywords] = usePostMetaValue('_meta_keywords');
Expand Down Expand Up @@ -58,9 +58,8 @@ function MetaKeywordsField() {
return;
}

const keywords = candidates[0].content.parts[0].text.replaceAll(
'\n\n\n\n',
'\n\n',
const keywords = aiHelpers.getTextFromContents(
aiHelpers.getCandidateContents(candidates),
);

setMetaKeywords(keywords);
Expand Down

0 comments on commit 62afd23

Please sign in to comment.