-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement AI playground panel to allow customizing most commonly supp…
…orted AI model config parameters.
- Loading branch information
1 parent
33c54cc
commit 27ea03f
Showing
5 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
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
93 changes: 93 additions & 0 deletions
93
src/playground-page/components/PlaygroundModelConfigPanel/index.js
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,93 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { PanelBody, TextControl } from '@wordpress/components'; | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { useState } from '@wordpress/element'; | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as playgroundStore } from '../../store'; | ||
import './style.scss'; | ||
|
||
/** | ||
* Renders the playground sidebar panel for AI model configuration. | ||
* | ||
* @since n.e.x.t | ||
* | ||
* @return {Component} The component to be rendered. | ||
*/ | ||
export default function PlaygroundModelConfigPanel() { | ||
const [ panelOpened, setPanelOpened ] = useState( false ); | ||
|
||
const { maxOutputTokens, temperature, topP } = useSelect( ( select ) => { | ||
const { getModelParam } = select( playgroundStore ); | ||
|
||
return { | ||
maxOutputTokens: getModelParam( 'maxOutputTokens' ), | ||
temperature: getModelParam( 'temperature' ), | ||
topP: getModelParam( 'topP' ), | ||
}; | ||
} ); | ||
|
||
const { setModelParam } = useDispatch( playgroundStore ); | ||
|
||
return ( | ||
<PanelBody | ||
title={ __( 'Model configuration', 'ai-services' ) } | ||
opened={ panelOpened } | ||
onToggle={ () => setPanelOpened( ! panelOpened ) } | ||
className="ai-services-playground-model-config-panel" | ||
> | ||
<TextControl | ||
type="number" | ||
min="0" | ||
step="1" | ||
label={ __( 'Max output tokens', 'ai-services' ) } | ||
help={ __( | ||
'The maximum number of tokens to include in a response candidate.', | ||
'ai-services' | ||
) } | ||
value={ maxOutputTokens } | ||
onChange={ ( value ) => | ||
setModelParam( 'maxOutputTokens', value ) | ||
} | ||
__nextHasNoMarginBottom | ||
/> | ||
<TextControl | ||
type="number" | ||
min="0" | ||
max="1" | ||
step="0.01" | ||
label={ __( 'Temperature', 'ai-services' ) } | ||
help={ sprintf( | ||
/* translators: 1: Minimum value, 2: Maximum value */ | ||
__( | ||
'Floating point value to control the randomness of the output, between %1$s and %2$s.', | ||
'ai-services' | ||
), | ||
'0.0', | ||
'1.0' | ||
) } | ||
value={ temperature } | ||
onChange={ ( value ) => setModelParam( 'temperature', value ) } | ||
__nextHasNoMarginBottom | ||
/> | ||
<TextControl | ||
type="number" | ||
min="0" | ||
step="0.01" | ||
label={ __( 'Top P', 'ai-services' ) } | ||
help={ __( | ||
'The maximum cumulative probability of tokens to consider when sampling.', | ||
'ai-services' | ||
) } | ||
value={ topP } | ||
onChange={ ( value ) => setModelParam( 'topP', value ) } | ||
__nextHasNoMarginBottom | ||
/> | ||
</PanelBody> | ||
); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/playground-page/components/PlaygroundModelConfigPanel/style.scss
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,10 @@ | ||
.ai-services-playground-model-config-panel { | ||
|
||
> .components-base-control { | ||
margin-bottom: 16px; | ||
|
||
&:last-child { | ||
margin-bottom: 0; | ||
} | ||
} | ||
} |
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