Skip to content

Commit

Permalink
🗨️ fix: respect line breaks in prompt variables (#3459)
Browse files Browse the repository at this point in the history
* fix: always display new lines in PromptEditor

* fix: allow multiline inputs in prompt template
  • Loading branch information
jacobcolyvan authored Jul 27, 2024
1 parent 14eff23 commit d4d5628
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions client/src/components/Prompts/Groups/VariableForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useForm, useFieldArray, Controller, useWatch } from 'react-hook-form';
import type { TPromptGroup } from 'librechat-data-provider';
import { extractVariableInfo, wrapVariable, replaceSpecialVars } from '~/utils';
import { useAuthContext, useLocalize, useSubmitMessage } from '~/hooks';
import { Input } from '~/components/ui';
import { Textarea } from '~/components/ui';

type FormValues = {
fields: { variable: string; value: string }[];
Expand Down Expand Up @@ -103,11 +103,18 @@ export default function VariableForm({
name={`fields.${index}.value`}
control={control}
render={({ field }) => (
<Input
<Textarea
{...field}
id={`fields.${index}.value`}
className="input text-grey-darker rounded border px-3 py-2 focus:bg-white dark:border-gray-500 dark:focus:bg-gray-700"
className="input text-grey-darker h-10 rounded border px-3 py-2 focus:bg-white dark:border-gray-500 dark:focus:bg-gray-700"
placeholder={uniqueVariables[index]}
onKeyDown={(e) => {
// Submit the form on enter like you would with an Input component
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
handleSubmit((data) => onSubmit(data))();
}
}}
/>
)}
/>
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Prompts/PromptEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const PromptEditor: React.FC<Props> = ({ name, isEditing, setIsEditing }) => {
onBlur={() => setIsEditing(false)}
/>
) : (
<span className="block break-words px-2 py-1 dark:text-gray-200">{field.value}</span>
<pre className="block break-words px-2 py-1 dark:text-gray-200">{field.value}</pre>
)
}
/>
Expand Down

0 comments on commit d4d5628

Please sign in to comment.