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

Issue 1209/ implement fe changes to playground, eval and deployment view for prompt versioning #1237

Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b4e384a
added prompt versioning api
bekossy Jan 18, 2024
6af0f82
created types for prompt versioning
bekossy Jan 18, 2024
5f34d79
added prompt versioning context provider
bekossy Jan 18, 2024
0e31914
update types
bekossy Jan 18, 2024
e494553
pass down setOptParams prop
bekossy Jan 18, 2024
05a7174
setup historyStatus state
bekossy Jan 18, 2024
36a72b1
setup playground ui for versioning
bekossy Jan 18, 2024
4bfc872
setup endpoints tab
bekossy Jan 18, 2024
a4ebec7
setup deployment component
bekossy Jan 18, 2024
533edf3
init prompt version provider
bekossy Jan 18, 2024
0af0d51
minor adjustments
bekossy Jan 18, 2024
1d6d862
revert changes and fixed prettier
bekossy Jan 19, 2024
8e3239f
improve UI and format date
bekossy Jan 19, 2024
2b452dd
trigger unsaved changes alert when switching history
bekossy Jan 21, 2024
84c8cd0
Merge branch 'issue-1210/prompt-vesioning' into Issue-1209/-implement…
bekossy Jan 23, 2024
bf18633
minor BE fixes
bekossy Jan 24, 2024
5f5216b
updated types and added revision id to variant label
bekossy Jan 24, 2024
1b92071
move PromptVersioningProvider to top level scope, modified optParams
bekossy Jan 24, 2024
9d45d3e
improved drawer styles and refactoring
bekossy Jan 24, 2024
1e54f18
revert endpoint page UI changes
bekossy Jan 24, 2024
8c697cf
improve UI
bekossy Jan 24, 2024
5877bf3
filtered out revisions with empty inputs
bekossy Jan 24, 2024
b09d6de
fixed formatter
bekossy Jan 24, 2024
6a3e410
minor fix
bekossy Jan 24, 2024
9b75f0f
added variant_ids to return type
bekossy Jan 25, 2024
8ddd528
cleanup and refactoring
bekossy Jan 25, 2024
41b622e
feat: navigate to playground with revision
bekossy Jan 25, 2024
b5ab36a
revert changes and cleanup
bekossy Jan 25, 2024
af163f1
Merge branch 'issue-1210/prompt-vesioning' into Issue-1209/-implement…
bekossy Jan 25, 2024
5924909
type fix
bekossy Jan 25, 2024
f80c134
Update - fix failing tests
aybruhm Jan 25, 2024
2b53253
cleanup
bekossy Jan 25, 2024
c55c5c4
minor improvements
bekossy Jan 25, 2024
48f0c29
fixed dataset
bekossy Jan 25, 2024
63f00d6
hot fix
bekossy Jan 25, 2024
c46df64
limited history availability to cloud
bekossy Jan 25, 2024
d81abeb
filtered out revision 0
bekossy Jan 25, 2024
7d4f250
Merge branch 'main' into Issue-1209/-implement-fe-changes-to-playgrou…
aybruhm Jan 25, 2024
69b261c
:art: Format - ran black
aybruhm Jan 25, 2024
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
4 changes: 2 additions & 2 deletions agenta-web/cypress/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress", "node"]
"types": ["cypress", "node"],
},
"include": ["**/*.ts"]
"include": ["**/*.ts"],
}
260 changes: 260 additions & 0 deletions agenta-web/src/components/DeploymentHistory/DeploymentHistory.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
import {Button, Card, Divider, Result, Space, Typography} from "antd"
import React, {useEffect, useState} from "react"
import {createUseStyles} from "react-jss"
import {useAppTheme} from "../Layout/ThemeContextProvider"
import {LoadingOutlined} from "@ant-design/icons"
import {promptVersioning} from "@/lib/services/api"
import {IPromptRevisions, IPromptVersioning, Variant} from "@/lib/Types"
import dayjs from "dayjs"
import relativeTime from "dayjs/plugin/relativeTime"
import duration from "dayjs/plugin/duration"
dayjs.extend(relativeTime)
dayjs.extend(duration)

type StyleProps = {
themeMode: "dark" | "light"
}

type DeploymentHistoryProps = {
variant: Variant
}

const {Text} = Typography

const useStyles = createUseStyles({
container: {
display: "flex",
gap: 20,
},
historyItemsContainer: ({themeMode}: StyleProps) => ({
flex: 0.2,
backgroundColor: themeMode === "dark" ? "#333" : "#eceff1",
overflowY: "scroll",
padding: 10,
borderRadius: 10,
minWidth: 300,
height: "600px",
}),
historyItems: {
display: "flex",
flexDirection: "column",
padding: "10px 20px",
margin: "20px 0",
borderRadius: 10,
cursor: "pointer",
},
promptHistoryCard: {
margin: "30px",
},
promptHistoryInfo: ({themeMode}: StyleProps) => ({
flex: 0.8,
backgroundColor: themeMode === "dark" ? "#333" : "#eceff1",
padding: 20,
borderRadius: 10,
}),
promptHistoryInfoHeader: {
display: "flex",
alignItems: "center",
justifyContent: "space-between",
"& h1": {
fontSize: 32,
},
},
emptyContainer: {
display: "flex",
alignItems: "center",
justifyContent: "center",
margin: "30px auto",
fontSize: 20,
fontWeight: "bold",
},
divider: {
margin: "10px 0",
},
historyItemsTitle: ({themeMode}: StyleProps) => ({
fontSize: 14,
"& span": {
color: themeMode === "dark" ? "#f1f5f8" : "#656d76",
},
}),
})

const DeploymentHistory: React.FC<DeploymentHistoryProps> = ({variant}) => {
const {appTheme} = useAppTheme()
const classes = useStyles({themeMode: appTheme} as StyleProps)
const [deploymentRevisions, setDeploymentRevisions] = useState<IPromptVersioning>()
const [isLoading, setIsLoading] = useState(false)
const [filtered, setFiltered] = useState<IPromptRevisions[]>()

const [showDeployments, setShowDeployments] = useState<IPromptRevisions>()
const [activeItem, setActiveItem] = useState(0)

useEffect(() => {
const fetchData = async () => {
setIsLoading(true)
try {
const data = await promptVersioning(variant.variantId)
setDeploymentRevisions(data)

setFiltered(
data?.revisions.filter(
(item: IPromptRevisions) =>
Object.keys(item.config.parameters).length !== 0,
),
)
} catch (error) {
setIsLoading(false)
console.log(error)
} finally {
setIsLoading(false)
}
}

fetchData()
}, [variant.variantId])

useEffect(() => {
if (filtered && filtered.length) {
setShowDeployments(filtered[0])
}
}, [filtered])

const handleShowDeployments = (id: number, index: number) => {
setActiveItem(index)
const findPrompt = deploymentRevisions?.revisions.find((prompt) => prompt.revision === id)

setShowDeployments(findPrompt)
}

const handleRevert = (id: number) => {}

return (
<>
{isLoading ? (
<Result icon={<LoadingOutlined />} subTitle="Loading..." />
) : !!filtered?.length ? (
<div className={classes.container}>
<div className={classes.historyItemsContainer}>
{filtered?.map((item, index) => (
<div
key={item.revision}
style={{
backgroundColor:
activeItem === index
? appTheme === "dark"
? "#1668dc"
: "#b3e5fc"
: appTheme === "dark"
? "#1f1f1f"
: "#fff",
border:
activeItem === index
? "1px solid #2196f3"
: "1px solid transparent",
}}
className={classes.historyItems}
onClick={() => handleShowDeployments(item.revision, index)}
>
<Space style={{justifyContent: "space-between"}}>
<Text className={classes.historyItemsTitle}>
<b>Revision</b> <span>#{item.revision}</span>
</Text>
<Text className={classes.historyItemsTitle}>
<span style={{fontSize: 12}}>
{dayjs(item.created_at).fromNow()}
</span>
</Text>
</Space>

<Divider className={classes.divider} />

<Space direction="vertical">
<div>
<Text strong>Config Name: </Text>
<Text>{item.config.config_name}</Text>
</div>
<div>
<Text strong>Modified By: </Text>
<Text>{item.modified_by}</Text>
</div>
</Space>
</div>
))}
</div>

<div className={classes.promptHistoryInfo}>
<div className={classes.promptHistoryInfoHeader}>
<h1>Information</h1>

<Button
type="primary"
onClick={() => handleRevert(showDeployments?.revision!)}
>
Revert
</Button>
</div>

<div>{dayjs(showDeployments?.created_at).format("DD-MM-YYYY mm:ss")}</div>

<Card title="Prompt System" className={classes.promptHistoryCard}>
<div>{showDeployments?.config.parameters?.prompt_system}</div>
</Card>

<Card title="Model Parameters" className={classes.promptHistoryCard}>
<Space direction="vertical">
{showDeployments?.config.parameters?.temperature && (
<Typography.Text>
Temperature:{" "}
{showDeployments?.config.parameters?.temperature}
</Typography.Text>
)}

{showDeployments?.config.parameters?.model && (
<Typography.Text>
Model: {showDeployments?.config.parameters?.model}
</Typography.Text>
)}

{showDeployments?.config.parameters?.max_tokens && (
<Typography.Text>
Max tokens: {showDeployments?.config.parameters?.max_tokens}
</Typography.Text>
)}

{showDeployments?.config.parameters?.top_p && (
<Typography.Text>
Top p: {showDeployments?.config.parameters?.top_p}
</Typography.Text>
)}

{showDeployments?.config.parameters?.frequence_penalty ||
showDeployments?.config.parameters?.frequence_penalty == 0 ? (
<Typography.Text>
Frequence penalty:{" "}
{showDeployments?.config.parameters?.frequence_penalty}
</Typography.Text>
) : (
""
)}

{showDeployments?.config.parameters?.presence_penalty ||
showDeployments?.config.parameters?.presence_penalty == 0 ? (
<Typography.Text>
Presence penalty:{" "}
{showDeployments?.config.parameters?.presence_penalty}
</Typography.Text>
) : (
""
)}
</Space>
</Card>
</div>
</div>
) : (
<div className={classes.emptyContainer}>You have no saved prompts</div>
)}
</>
)
}

export default DeploymentHistory
29 changes: 17 additions & 12 deletions agenta-web/src/components/Playground/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {arrayMove, SortableContext, horizontalListSortingStrategy} from "@dnd-ki
import DraggableTabNode from "../DraggableTabNode/DraggableTabNode"
import {useLocalStorage} from "usehooks-ts"
import TestContextProvider from "./TestContextProvider"
import PromptVersioningProvider from "./PromptVersioningProvider"

const Playground: React.FC = () => {
const router = useRouter()
Expand Down Expand Up @@ -239,18 +240,22 @@ const Playground: React.FC = () => {
key: variant.variantName,
label: `Variant ${variant.variantName}`,
children: (
<ViewNavigation
compareMode={compareMode}
variant={variant}
handlePersistVariant={handlePersistVariant}
environments={environments}
deleteVariant={deleteVariant}
onStateChange={(isDirty) =>
setUnsavedVariants((prev) => ({...prev, [variant.variantName]: isDirty}))
}
getHelpers={(helpers) => (variantHelpers.current[variant.variantName] = helpers)}
tabID={tabID}
/>
<PromptVersioningProvider>
<ViewNavigation
compareMode={compareMode}
variant={variant}
handlePersistVariant={handlePersistVariant}
environments={environments}
deleteVariant={deleteVariant}
onStateChange={(isDirty) =>
setUnsavedVariants((prev) => ({...prev, [variant.variantName]: isDirty}))
}
getHelpers={(helpers) =>
(variantHelpers.current[variant.variantName] = helpers)
}
tabID={tabID}
/>
</PromptVersioningProvider>
),
closable: !variant.persistent,
}))
Expand Down
49 changes: 49 additions & 0 deletions agenta-web/src/components/Playground/PromptVersioningProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {IPromptVersioning} from "@/lib/Types"
import {Dispatch, PropsWithChildren, SetStateAction, createContext, useState} from "react"

export const PromptVersioningContext = createContext<{
promptRevisions: IPromptVersioning | undefined
setPromptRevisions: Dispatch<SetStateAction<IPromptVersioning | undefined>>
isDrawerOpen: boolean
setIsDrawerOpen: Dispatch<SetStateAction<boolean>>
historyStatus: {
loading: boolean
error: boolean
}
setHistoryStatus: Dispatch<
SetStateAction<{
loading: boolean
error: boolean
}>
>
}>({
promptRevisions: undefined,
setPromptRevisions: () => {},
isDrawerOpen: false,
setIsDrawerOpen: () => {},
historyStatus: {loading: false, error: false},
setHistoryStatus: () => {},
})

const PromptVersioningProvider: React.FC<PropsWithChildren> = ({children}) => {
const [promptRevisions, setPromptRevisions] = useState<IPromptVersioning>()
const [isDrawerOpen, setIsDrawerOpen] = useState(false)
const [historyStatus, setHistoryStatus] = useState({loading: false, error: false})

return (
<PromptVersioningContext.Provider
value={{
promptRevisions,
setPromptRevisions,
isDrawerOpen,
setIsDrawerOpen,
historyStatus,
setHistoryStatus,
}}
>
{children}
</PromptVersioningContext.Provider>
)
}

export default PromptVersioningProvider
2 changes: 2 additions & 0 deletions agenta-web/src/components/Playground/ViewNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const ViewNavigation: React.FC<Props> = ({
saveOptParams,
isLoading,
isChatVariant,
setOptParams,
} = useVariant(appId, variant)
const [retrying, setRetrying] = useState(false)
const [isParamsCollapsed, setIsParamsCollapsed] = useState("1")
Expand Down Expand Up @@ -249,6 +250,7 @@ const ViewNavigation: React.FC<Props> = ({
variant={variant}
isChatVariant={!!isChatVariant}
compareMode={compareMode}
setOptParams={setOptParams}
/>
</Col>
</Row>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const ModelParameters: React.FC<ModelParametersProps> = ({
)}
{param.type === "array" && (
<Select
defaultValue={param.default}
value={param.default}
onChange={(value) =>
handleParamChange(param.name, value)
}
Expand Down Expand Up @@ -197,7 +197,7 @@ export const StringParameters: React.FC<StringParametersProps> = ({
<Card className={classes.card} title={renameVariables(param.name)}>
<Input.TextArea
rows={5}
defaultValue={param.default}
value={param.default}
onChange={(e) => handleParamChange(param.name, e.target.value)}
bordered={false}
className={classes.textarea}
Expand Down
Loading
Loading