Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move copy message button in the playground to the text input #1691

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions agenta-web/src/components/ChatInputs/ChatInputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {createUseStyles} from "react-jss"
import {useUpdateEffect} from "usehooks-ts"
import {v4 as uuidv4} from "uuid"
import {useAppTheme} from "../Layout/ThemeContextProvider"
import CopyButton from "../CopyButton/CopyButton"

const useStyles = createUseStyles({
root: {
Expand Down Expand Up @@ -50,6 +51,7 @@ interface Props {
disableEditRole?: boolean
disableEditContent?: boolean
readonly?: boolean
isLoading?: boolean
}

const ChatInputs: React.FC<Props> = ({
Expand All @@ -62,6 +64,7 @@ const ChatInputs: React.FC<Props> = ({
disableEditRole,
disableEditContent,
readonly,
isLoading,
}) => {
const {appTheme} = useAppTheme()
const classes = useStyles()
Expand Down Expand Up @@ -126,6 +129,8 @@ const ChatInputs: React.FC<Props> = ({
if (Array.isArray(value)) setMessages(cloneDeep(value))
}, [JSON.stringify(value)])

const lastAssistantMsg = messages.filter((msg) => msg.role === ChatRole.Assistant)

return (
<div className={classes.root}>
{messages.map((msg, ix) => (
Expand Down Expand Up @@ -160,16 +165,33 @@ const ChatInputs: React.FC<Props> = ({
onChange={(e) => handleInputChange(ix, e)}
readOnly={readonly}
/>
{messages.length > 1 && !disableRemove && (
<Tooltip title="Remove">
<Button
shape="circle"
size="small"
icon={<MinusOutlined />}
onClick={() => handleDelete(ix)}
<div className="flex items-center gap-2">
{lastAssistantMsg[lastAssistantMsg.length - 1]?.id === msg.id && (
<CopyButton
buttonText={null}
text={
!!lastAssistantMsg.length
? lastAssistantMsg[lastAssistantMsg.length - 1].content
: ""
}
disabled={
isLoading ||
!lastAssistantMsg[lastAssistantMsg.length - 1]?.content
}
icon={true}
/>
</Tooltip>
)}
)}
{messages.length > 1 && !disableRemove && (
<Tooltip title="Remove">
<Button
shape="circle"
size="small"
icon={<MinusOutlined />}
onClick={() => handleDelete(ix)}
/>
</Tooltip>
)}
</div>
</div>
))}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ interface Props {
form?: FormInstance<GenericObject>
imageSize?: "small" | "large"
isPlaygroundComponent?: boolean
isLoading?: boolean
}

const ParamsForm: React.FC<Props> = ({
Expand All @@ -59,6 +60,7 @@ const ParamsForm: React.FC<Props> = ({
form,
imageSize = "small",
isPlaygroundComponent = false,
isLoading,
}) => {
const classes = useStyles()
const imgHeight = imageSize === "small" ? 90 : 120
Expand All @@ -70,6 +72,7 @@ const ParamsForm: React.FC<Props> = ({
value={useChatDefaultValue ? undefined : chat}
defaultValue={useChatDefaultValue ? chat : undefined}
onChange={(val) => onParamChange?.("chat", val)}
isLoading={isLoading}
/>
) : (
<Form form={form} className={classes.form} onFinish={onFinish}>
Expand Down
15 changes: 9 additions & 6 deletions agenta-web/src/components/Playground/Views/TestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const useStylesBox = createUseStyles({
},
row3: {
margin: "16px 0",
position: "relative",
"& textarea": {
height: "100%",
width: "100%",
Expand Down Expand Up @@ -211,6 +212,7 @@ const BoxComponent: React.FC<BoxComponentProps> = ({
form={form}
imageSize="large"
isPlaygroundComponent={true}
isLoading={loading}
/>
</Row>
{additionalData?.cost || additionalData?.latency ? (
Expand Down Expand Up @@ -247,12 +249,6 @@ const BoxComponent: React.FC<BoxComponentProps> = ({
>
Add to Test Set
</Button>
<CopyButton
buttonText={isChatVariant ? "Copy last message" : "Copy result"}
text={result}
disabled={loading || !result}
shape="round"
/>
{loading ? (
<Button
icon={<CloseCircleOutlined />}
Expand Down Expand Up @@ -299,6 +295,13 @@ const BoxComponent: React.FC<BoxComponentProps> = ({
: "",
}}
/>
<CopyButton
buttonText={null}
text={result}
disabled={loading || !result}
icon={true}
className="absolute top-2 right-2 opacity-70"
/>
</Row>
)}
</Card>
Expand Down
Loading