Skip to content

Commit

Permalink
fix: use last conversation as default prompt value
Browse files Browse the repository at this point in the history
  • Loading branch information
Soare-Robert-Daniel committed Jul 31, 2024
1 parent a1d463c commit 76199a0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/blocks/components/prompt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,24 @@ const PromptPlaceholder = ( props: PromptPlaceholderProps ) => {
getEmbeddedPrompt();
}, []);

/**
* Use the last conversation as the default prompt value for the text transformation actions.
*/
useEffect( () => {
if (
! props.promptID ||
'textTransformation' !== props.promptID ||
! props.resultHistory
) {
return;
}

const lastConversation = resultHistory?.[ resultHistory.length - 1 ]?.meta?.prompt;
if ( lastConversation ) {
onValueChange( lastConversation );
}
}, []);

useEffect( () => {
if ( 'loading' === status || 'present' === apiKeyStatus ) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/components/prompt/prompt-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ const PromptInput = ( props: PromptInputProps ) => {
placeholder={ props.placeholder }
rows={1}
onKeyDown={ handleKeyDown }
value={ props.value }
>
{ props.value }
</textarea>
<div className="prompt-input__submit__container">
<Button
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/plugins/ai-content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ const AIToolbar = ({
result: response?.choices?.[0]?.message.content ?? '',
meta: {
usedToken: response?.usage.total_tokens,
prompt: ''
prompt: embeddedPrompt.messages?.[ embeddedPrompt.messages.length - 1 ]?.content
}
}],
replaceTargetBlock: {
Expand Down

0 comments on commit 76199a0

Please sign in to comment.