-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[editor] Support Toggling Raw JSON for Output (#656)
# [editor] Support Toggling Raw JSON for Output Adding a button to toggle to the output to show/hide the raw JSON output (for outputs that are not already JSON output): https://github.com/lastmile-ai/aiconfig/assets/5060851/d0ba07a6-167f-481f-9161-8b94ebf57076 --- Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/lastmile-ai/aiconfig/pull/656). * __->__ #656 * #654 * #652
- Loading branch information
Showing
5 changed files
with
122 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
python/src/aiconfig/editor/client/src/components/prompt/prompt_outputs/JSONOutput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Prism } from "@mantine/prism"; | ||
import { JSONValue } from "aiconfig"; | ||
import { memo } from "react"; | ||
|
||
export default memo(function JSONOutput({ content }: { content: JSONValue }) { | ||
return ( | ||
<Prism language="json" styles={{ code: { textWrap: "pretty" } }}> | ||
{JSON.stringify(content, null, 2)} | ||
</Prism> | ||
); | ||
}); |
59 changes: 59 additions & 0 deletions
59
...n/src/aiconfig/editor/client/src/components/prompt/prompt_outputs/PromptOutputWrapper.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { ActionIcon, CopyButton, Flex, Tooltip } from "@mantine/core"; | ||
import { | ||
IconBraces, | ||
IconBracesOff, | ||
IconCheck, | ||
IconCopy, | ||
} from "@tabler/icons-react"; | ||
import { Output } from "aiconfig"; | ||
import { memo, useState } from "react"; | ||
import JSONOutput from "./JSONOutput"; | ||
|
||
type Props = { | ||
children: React.ReactNode; | ||
copyContent?: string; | ||
output: Output; | ||
withRawJSONToggle?: boolean; | ||
}; | ||
|
||
export default memo(function PromptOutputWrapper({ | ||
children, | ||
copyContent, | ||
output, | ||
withRawJSONToggle = false, | ||
}: Props) { | ||
const [isRawJSON, setIsRawJSON] = useState(false); | ||
return ( | ||
<> | ||
<Flex justify="flex-end"> | ||
{copyContent && ( | ||
<CopyButton value={copyContent} timeout={2000}> | ||
{({ copied, copy }) => ( | ||
<Tooltip label={copied ? "Copied" : "Copy"} withArrow> | ||
<ActionIcon color={copied ? "teal" : "gray"} onClick={copy}> | ||
{copied ? ( | ||
<IconCheck size="1rem" /> | ||
) : ( | ||
<IconCopy size="1rem" /> | ||
)} | ||
</ActionIcon> | ||
</Tooltip> | ||
)} | ||
</CopyButton> | ||
)} | ||
{withRawJSONToggle && ( | ||
<Tooltip label="Toggle raw JSON" withArrow> | ||
<ActionIcon onClick={() => setIsRawJSON((curr) => !curr)}> | ||
{isRawJSON ? ( | ||
<IconBracesOff size="1rem" /> | ||
) : ( | ||
<IconBraces size="1rem" /> | ||
)} | ||
</ActionIcon> | ||
</Tooltip> | ||
)} | ||
</Flex> | ||
{isRawJSON ? <JSONOutput content={output} /> : <>{children}</>} | ||
</> | ||
); | ||
}); |
53 changes: 44 additions & 9 deletions
53
...src/aiconfig/editor/client/src/components/prompt/prompt_outputs/PromptOutputsRenderer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters