-
Notifications
You must be signed in to change notification settings - Fork 815
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AI Assistant: Add image index information on caption generation reque…
…st (#42274) * Add getAllBlocks and getSerializedPostContent lib functions * add image index for caption requests * changelog * treat response for common parsing error * change indexes to positions * change positions to block clientId
- Loading branch information
Showing
7 changed files
with
84 additions
and
15 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
projects/js-packages/ai-client/changelog/update-jetpack-ai-image-extension-image-index
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Significance: patch | ||
Type: added | ||
Comment: Added utility functions | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { select } from '@wordpress/data'; | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { Block } from '../types.js'; | ||
|
||
/** | ||
* Recursively get all blocks from the post, including nested innerBlocks | ||
* @return {Array} Array of all blocks in the post | ||
*/ | ||
export const getAllBlocks = (): Array< Block > => { | ||
const topLevelBlocks = select( 'core/block-editor' ).getBlocks(); | ||
const allBlocks: Array< Block > = []; | ||
|
||
const processBlock = ( block: Block ) => { | ||
allBlocks.push( block ); | ||
|
||
if ( block.innerBlocks?.length ) { | ||
block.innerBlocks.forEach( processBlock ); | ||
} | ||
}; | ||
|
||
topLevelBlocks.forEach( processBlock ); | ||
|
||
return allBlocks; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
projects/plugins/jetpack/changelog/update-jetpack-ai-image-extension-image-index
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: other | ||
|
||
AI Assistant: Add image index information on caption generation request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 19 additions & 7 deletions
26
...plugins/jetpack/extensions/blocks/ai-assistant/extensions/lib/preprocess-image-content.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters