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

[Bug Fix]: Error while saving a new configuration for a newly created variant in the playground #1562

Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 17 additions & 5 deletions agenta-web/src/components/Playground/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, {useState, useEffect, useRef} from "react"
import {Button, Tabs, message} from "antd"
import ViewNavigation from "./ViewNavigation"
import NewVariantModal from "./NewVariantModal"
import {fetchEnvironments, fetchVariants} from "@/lib/services/api"
import {fetchEnvironments, fetchVariants, saveNewVariant} from "@/lib/services/api"
import {Variant, PlaygroundTabsItem, Environment} from "@/lib/Types"
import {AppstoreOutlined, SyncOutlined} from "@ant-design/icons"
import {useRouter} from "next/router"
Expand Down Expand Up @@ -35,7 +35,7 @@ const Playground: React.FC = () => {
const [compareMode, setCompareMode] = useLocalStorage("compareMode", false)
const tabID = useRef("")

const addTab = () => {
const addTab = async () => {
// Find the template variant
const templateVariant = variants.find(
(variant) => variant.variantName === templateVariantName,
Expand Down Expand Up @@ -77,8 +77,20 @@ const Playground: React.FC = () => {
configName: newVariantName,
}

setVariants((prevState: any) => [...prevState, newVariant])
setActiveKey(updateNewVariantName)
try {
await saveNewVariant(
newVariant.baseId!,
newVariant.variantName!,
newVariant.configName!,
[],
)
setVariants((prevState: any) => [...prevState, newVariant])
setActiveKey(updateNewVariantName)
setUnsavedVariants((prev) => ({...prev, [newVariant.variantName!]: false}))
} catch (error) {
message.error("Failed to add new variant. Please try again later.")
console.error("Error adding new variant:", error)
}
}

const removeTab = () => {
Expand Down Expand Up @@ -120,7 +132,7 @@ const Playground: React.FC = () => {

useEffect(() => {
fetchData()
}, [appId])
}, [appId, activeKey])

// Load environments
const [environments, setEnvironments] = useState<Environment[]>([])
Expand Down
4 changes: 0 additions & 4 deletions agenta-web/src/components/Playground/Views/ParametersView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ const ParametersView: React.FC<Props> = ({
const [revisionNum, setRevisionNum] = useQueryParam("revision")
const [promptRevisions, setPromptRevisions] = useState<IPromptRevisions[]>([])

useEffect(() => {
onStateChange(variant.persistent === false)
}, [])

const onChange = (param: Parameter, newValue: number | string) => {
handleParamChange(param.name, newValue)
}
Expand Down
Loading