Skip to content

Commit

Permalink
Wd/pp template (Chainlit#408)
Browse files Browse the repository at this point in the history
* enable template mode if at least one prompt has a template

* has to update to set module resolution nodenext or precommit fails

* revert module resolution change

* fix warning
  • Loading branch information
willydouhard authored Sep 21, 2023
1 parent 3893cf0 commit 6d9a910
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 22 deletions.
12 changes: 4 additions & 8 deletions frontend/src/components/organisms/playground/basic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ interface Props {
restoredTime: number;
}

export default function BasicPromptPlayground({
hasTemplate,
prompt,
restoredTime
}: Props) {
export default function BasicPromptPlayground({ prompt, restoredTime }: Props) {
const mode = useRecoilValue(modeState);
const setPlayground = useSetRecoilState(playgroundState);

Expand Down Expand Up @@ -55,19 +51,19 @@ export default function BasicPromptPlayground({
return (
<TemplateEditor
showTitle={true}
template={prompt.template || ''}
template={prompt.template || prompt.formatted || ''}
prompt={prompt}
onChange={onTemplateChange}
/>
);
};

const renderFormatted = () => {
if (hasTemplate) {
if (typeof prompt.template === 'string') {
return (
<FormattedEditor
showTitle={true}
template={prompt.template!}
template={prompt.template}
prompt={prompt}
readOnly
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function PromptMessage({
<TemplateEditor
{...templateProps}
showTitle={false}
template={message.template!}
template={message.template || message.formatted || ''}
onChange={(state) => onChange(index, state)}
/>
);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/organisms/playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function _PromptPlayground({ prompt }: Props) {
};

const hasTemplate = prompt?.messages
? prompt.messages.every((m) => typeof m.template === 'string')
? !!prompt.messages.find((m) => typeof m.template === 'string')
: typeof prompt?.template === 'string';

if (!data || error) {
Expand Down
15 changes: 3 additions & 12 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
{
"compilerOptions": {
"target": "es2020",
"lib": [
"ESNext",
"dom"
],
"types": [
"cypress",
"node"
]
"lib": ["ESNext", "dom"],
"types": ["cypress", "node"]
},
"include": [
"cypress/**/*.ts"
]
"include": ["cypress/**/*.ts"]
}

0 comments on commit 6d9a910

Please sign in to comment.