Skip to content

Commit b345bb1

Browse files
authored
feat: toggle content on conversations (PostHog#28835)
1 parent 6d73d21 commit b345bb1

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

products/llm_observability/frontend/ConversationDisplay/ConversationMessagesDisplay.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { IconMarkdown, IconMarkdownFilled } from '@posthog/icons'
1+
import { IconEye, IconMarkdown, IconMarkdownFilled } from '@posthog/icons'
22
import { LemonButton } from '@posthog/lemon-ui'
33
import clsx from 'clsx'
44
import { CopyToClipboardInline } from 'lib/components/CopyToClipboard'
55
import { JSONViewer } from 'lib/components/JSONViewer'
6-
import { IconExclamation } from 'lib/lemon-ui/icons'
6+
import { IconExclamation, IconEyeHidden } from 'lib/lemon-ui/icons'
77
import { LemonMarkdown } from 'lib/lemon-ui/LemonMarkdown'
88
import { isObject } from 'lib/utils'
99
import React from 'react'
@@ -87,6 +87,7 @@ export const LLMMessageDisplay = React.memo(
8787
({ message, isOutput }: { message: CompatMessage; isOutput?: boolean }): JSX.Element => {
8888
const { role, content, ...additionalKwargs } = message
8989
const [isRenderingMarkdown, setIsRenderingMarkdown] = React.useState(true)
90+
const [show, setShow] = React.useState(true)
9091

9192
// Compute whether the content looks like Markdown.
9293
// (Heuristic: looks for code blocks, blockquotes, or headings)
@@ -128,7 +129,7 @@ export const LLMMessageDisplay = React.memo(
128129
}
129130

130131
// Fallback: render as plain text.
131-
return <span className="font-mono text-xs whitespace-pre-wrap">{content}</span>
132+
return <span className="text-xs whitespace-pre-wrap">{content}</span>
132133
}
133134

134135
return (
@@ -148,12 +149,19 @@ export const LLMMessageDisplay = React.memo(
148149
<span className="grow">{role}</span>
149150
{content && (
150151
<>
152+
<LemonButton
153+
size="small"
154+
noPadding
155+
icon={show ? <IconEyeHidden /> : <IconEye />}
156+
tooltip="Toggle message content"
157+
onClick={() => setShow((prev) => !prev)}
158+
/>
151159
{isMarkdownCandidate && (
152160
<LemonButton
153161
size="small"
154162
noPadding
155163
icon={isRenderingMarkdown ? <IconMarkdownFilled /> : <IconMarkdown />}
156-
tooltip="Toggle Markdown rendering"
164+
tooltip="Toggle markdown rendering"
157165
onClick={() => setIsRenderingMarkdown((prev) => !prev)}
158166
/>
159167
)}
@@ -165,8 +173,8 @@ export const LLMMessageDisplay = React.memo(
165173
</>
166174
)}
167175
</div>
168-
{!!content && <div className="p-2 border-t">{renderMessageContent(content)}</div>}
169-
{Object.keys(additionalKwargsEntries).length > 0 && (
176+
{show && !!content && <div className="p-2 border-t">{renderMessageContent(content)}</div>}
177+
{show && Object.keys(additionalKwargsEntries).length > 0 && (
170178
<div className="p-2 text-xs border-t">
171179
<JSONViewer src={additionalKwargsEntries} name={null} collapsed={5} />
172180
</div>

0 commit comments

Comments
 (0)