diff --git a/packages/server/src/utils/hub.ts b/packages/server/src/utils/hub.ts index 79e7136f0..38e8a6c09 100644 --- a/packages/server/src/utils/hub.ts +++ b/packages/server/src/utils/hub.ts @@ -10,9 +10,17 @@ export function parsePrompt(prompt: string): any[] { : message.id.includes('AIMessagePromptTemplate') ? 'aiMessagePrompt' : 'template' + let messageTypeDisplay = message.id.includes('SystemMessagePromptTemplate') + ? 'System Message' + : message.id.includes('HumanMessagePromptTemplate') + ? 'Human Message' + : message.id.includes('AIMessagePromptTemplate') + ? 'AI Message' + : 'Message' let template = message.kwargs.prompt.kwargs.template response.push({ type: messageType, + typeDisplay: messageTypeDisplay, template: template }) }) diff --git a/packages/ui/src/ui-component/dialog/PromptLangsmithHubDialog.js b/packages/ui/src/ui-component/dialog/PromptLangsmithHubDialog.js index 4db61633e..e425dada9 100644 --- a/packages/ui/src/ui-component/dialog/PromptLangsmithHubDialog.js +++ b/packages/ui/src/ui-component/dialog/PromptLangsmithHubDialog.js @@ -8,6 +8,7 @@ import { CardContent, Chip, Dialog, + DialogActions, DialogContent, DialogTitle, Divider, @@ -28,8 +29,9 @@ import MenuItem from '@mui/material/MenuItem' import ReactMarkdown from 'react-markdown' import CredentialInputHandler from '../../views/canvas/CredentialInputHandler' import promptApi from '../../api/prompt' +import { StyledButton } from '../button/StyledButton' -const PromptLangsmithHubDialog = ({ promptType, show, onCancel }) => { +const PromptLangsmithHubDialog = ({ promptType, show, onCancel, onSubmit }) => { const portalElement = document.getElementById('portal') const dispatch = useDispatch() @@ -114,6 +116,7 @@ const PromptLangsmithHubDialog = ({ promptType, show, onCancel }) => { } } setSelectedPrompt(prompt) + await new Promise((resolve) => setTimeout(resolve, 500)) } const fetchPrompts = async () => { @@ -355,7 +358,10 @@ const PromptLangsmithHubDialog = ({ promptType, show, onCancel }) => { Readme - + {selectedPrompt?.readme} @@ -365,11 +371,11 @@ const PromptLangsmithHubDialog = ({ promptType, show, onCancel }) => { {selectedPrompt?.detailed?.map((item) => ( <> - {item.type} + {item.typeDisplay.toUpperCase()} + + +
{item.template}
- - {item.template} - ))} @@ -378,6 +384,12 @@ const PromptLangsmithHubDialog = ({ promptType, show, onCancel }) => { + + + onSubmit(selectedPrompt.detailed)} variant='contained'> + Submit + + ) : null @@ -387,7 +399,8 @@ const PromptLangsmithHubDialog = ({ promptType, show, onCancel }) => { PromptLangsmithHubDialog.propTypes = { promptType: PropTypes.string, show: PropTypes.bool, - onCancel: PropTypes.func + onCancel: PropTypes.func, + onSubmit: PropTypes.func } export default PromptLangsmithHubDialog diff --git a/packages/ui/src/views/canvas/NodeInputHandler.js b/packages/ui/src/views/canvas/NodeInputHandler.js index 162455dfd..24ba3c921 100644 --- a/packages/ui/src/views/canvas/NodeInputHandler.js +++ b/packages/ui/src/views/canvas/NodeInputHandler.js @@ -75,6 +75,14 @@ const NodeInputHandler = ({ inputAnchor, inputParam, data, disabled = false, isA const onShowPromptHubButtonClicked = () => { setShowPromptHubDialog(true) } + const onShowPromptHubButtonSubmit = (templates) => { + setShowPromptHubDialog(false) + for (const t of templates) { + if (Object.prototype.hasOwnProperty.call(data.inputs, t.type)) { + data.inputs[t.type] = t.template + } + } + } const onFormatPromptValuesClicked = (value, inputParam) => { // Preset values if the field is format prompt values let inputValue = value @@ -234,6 +242,7 @@ const NodeInputHandler = ({ inputAnchor, inputParam, data, disabled = false, isA promptType={inputParam.name} show={showPromptHubDialog} onCancel={() => setShowPromptHubDialog(false)} + onSubmit={onShowPromptHubButtonSubmit} > )}