From 5e6faf0a5bb9482e0975ae26b110a21392237aeb Mon Sep 17 00:00:00 2001 From: Mikyo King Date: Tue, 8 Oct 2024 23:37:12 -0600 Subject: [PATCH] feat(playground): make chat messages match style in traces (#4931) * feat(playground): make chat messages match style in traces * small fixes * WIP --- app/src/hooks/useChatMessageStyles.ts | 35 +++++++++ app/src/pages/playground/Playground.tsx | 6 +- .../playground/PlaygroundChatTemplate.tsx | 75 +++++++++++++------ .../pages/playground/SpanPlaygroundPage.tsx | 8 +- app/src/pages/trace/SpanDetails.tsx | 30 +------- app/src/store/playgroundStore.tsx | 24 +++--- 6 files changed, 112 insertions(+), 66 deletions(-) create mode 100644 app/src/hooks/useChatMessageStyles.ts diff --git a/app/src/hooks/useChatMessageStyles.ts b/app/src/hooks/useChatMessageStyles.ts new file mode 100644 index 0000000000..3ccfb43b54 --- /dev/null +++ b/app/src/hooks/useChatMessageStyles.ts @@ -0,0 +1,35 @@ +import { useMemo } from "react"; + +import { ViewStyleProps } from "@arizeai/components"; + +export function useChatMessageStyles( + role: string +): Pick { + return useMemo(() => { + if (role === "user" || role === "human") { + return { + backgroundColor: "grey-100", + borderColor: "grey-500", + }; + } else if (role === "assistant" || role === "ai") { + return { + backgroundColor: "blue-100", + borderColor: "blue-700", + }; + } else if (role === "system") { + return { + backgroundColor: "indigo-100", + borderColor: "indigo-700", + }; + } else if (["function", "tool"].includes(role)) { + return { + backgroundColor: "yellow-100", + borderColor: "yellow-700", + }; + } + return { + backgroundColor: "grey-100", + borderColor: "grey-700", + }; + }, [role]); +} diff --git a/app/src/pages/playground/Playground.tsx b/app/src/pages/playground/Playground.tsx index 0b45b1cd1e..2cd0dd93a0 100644 --- a/app/src/pages/playground/Playground.tsx +++ b/app/src/pages/playground/Playground.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { Fragment } from "react"; import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels"; import { Button, Flex, Heading, View } from "@arizeai/components"; @@ -48,12 +48,12 @@ function PlaygroundInstances() { {instances.map((instance, i) => ( - <> + {i !== 0 && } - + ))} diff --git a/app/src/pages/playground/PlaygroundChatTemplate.tsx b/app/src/pages/playground/PlaygroundChatTemplate.tsx index 7263eb7b47..021d3f9516 100644 --- a/app/src/pages/playground/PlaygroundChatTemplate.tsx +++ b/app/src/pages/playground/PlaygroundChatTemplate.tsx @@ -1,9 +1,10 @@ -import React from "react"; +import React, { PropsWithChildren } from "react"; import { css } from "@emotion/react"; -import { Card, TextArea } from "@arizeai/components"; +import { Card, CardProps, TextArea } from "@arizeai/components"; import { usePlaygroundContext } from "@phoenix/contexts/PlaygroundContext"; +import { useChatMessageStyles } from "@phoenix/hooks/useChatMessageStyles"; import { MessageRolePicker } from "./MessageRolePicker"; import { PlaygroundInstanceProps } from "./types"; @@ -35,7 +36,8 @@ export function PlaygroundChatTemplate(props: PlaygroundChatTemplateProps) { {template.messages.map((message, index) => { return (
  • - } - variant="compact" - backgroundColor="light" - borderColor="light" > -