Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

chore(ui): toggle json editor for text prompts (#4807)

marliessophie0e5cade9e743
diff --git a/web/src/features/prompts/components/NewPromptForm/index.tsx b/web/src/features/prompts/components/NewPromptForm/index.tsx
index f3ba06250e..09e6148f32 100644
--- a/web/src/features/prompts/components/NewPromptForm/index.tsx
+++ b/web/src/features/prompts/components/NewPromptForm/index.tsx
@@ -48,6 +48,7 @@ import { PRODUCTION_LABEL } from "@/src/features/prompts/constants";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
import usePlaygroundCache from "@/src/ee/features/playground/page/hooks/usePlaygroundCache";
import { useQueryParam } from "use-query-params";
+import { Switch } from "@/src/components/ui/switch";
type NewPromptFormProps = {
initialPrompt?: Prompt | null;
@@ -61,6 +62,7 @@ export const NewPromptForm: React.FC<NewPromptFormProps> = (props) => {
const [formError, setFormError] = useState<string | null>(null);
const { playgroundCache } = usePlaygroundCache();
const [initialMessages, setInitialMessages] = useState<unknown>([]);
+ const [showJsonEditor, setShowJsonEditor] = useState(false);
const utils = api.useUtils();
const capture = usePostHogClientCapture();
@@ -250,7 +252,24 @@ export const NewPromptForm: React.FC<NewPromptFormProps> = (props) => {
{/* Prompt content field - text vs. chat */}
<>
<FormItem>
- <FormLabel>Prompt</FormLabel>
+ <FormLabel className="flex flex-row items-center justify-between">
+ <div>Prompt</div>
+ {form.watch("type") === PromptType.Text ? (
+ <div className="flex flex-row items-center">
+ <p className="mr-1 text-xs text-muted-foreground">
+ JSON editor
+ </p>
+
+ <Switch
+ checked={showJsonEditor}
+ className={
+ showJsonEditor ? "data-[state=checked]:bg-dark-green" : ""
+ }
+ onCheckedChange={setShowJsonEditor}
+ />
+ </div>
+ ) : null}
+ </FormLabel>
<Tabs
value={form.watch("type")}
onValueChange={(e) => {
@@ -288,10 +307,18 @@ export const NewPromptForm: React.FC<NewPromptFormProps> = (props) => {
render={({ field }) => (
<>
<FormControl>
- <Textarea
- {...field}
- className="min-h-[200px] flex-1 font-mono text-xs"
- />
+ {showJsonEditor ? (
+ <JsonEditor
+ defaultValue={field.value}
+ onChange={field.onChange}
+ editable
+ />
+ ) : (
+ <Textarea
+ {...field}
+ className="min-h-[200px] flex-1 font-mono text-xs"
+ />
+ )}
</FormControl>
<FormMessage />
</>