diff --git a/agenta-web/src/components/Playground/AddToTestSetDrawer/AddToTestSetDrawer.tsx b/agenta-web/src/components/Playground/AddToTestSetDrawer/AddToTestSetDrawer.tsx index 0d741edbf6..07d0098756 100644 --- a/agenta-web/src/components/Playground/AddToTestSetDrawer/AddToTestSetDrawer.tsx +++ b/agenta-web/src/components/Playground/AddToTestSetDrawer/AddToTestSetDrawer.tsx @@ -1,7 +1,7 @@ import AlertPopup from "@/components/AlertPopup/AlertPopup" import {useAppTheme} from "../../Layout/ThemeContextProvider" -import {GenericObject, testset} from "@/lib/Types" -import {renameVariables} from "@/lib/helpers/utils" +import {ChatMessage, GenericObject, testset} from "@/lib/Types" +import {removeKeys, renameVariables} from "@/lib/helpers/utils" import {createNewTestset, loadTestset, updateTestset, useLoadTestsetsList} from "@/lib/services/api" import {Button, Divider, Drawer, Form, Input, Modal, Select, Space, Typography, message} from "antd" import {useRouter} from "next/router" @@ -28,6 +28,11 @@ const useStyles = createUseStyles({ color: themeMode === "dark" ? "rgba(255, 255, 255, 0.85)" : "rgba(0, 0, 0, 0.88)", }, }), + chatContainer: { + display: "flex", + flexDirection: "column", + gap: "0.75rem", + }, }) type Props = React.ComponentProps & { @@ -81,11 +86,12 @@ const AddToTestSetDrawer: React.FC = ({params, isChatVariant, ...props}) const addToTestSet = useCallback( (name: string, csvdata: Record[], rowData: GenericObject) => { rowData = {...rowData} - Object.keys(rowData).forEach((key) => { - if (rowData[key] && typeof rowData[key] !== "string") { - rowData[key] = JSON.stringify(rowData[key]) - } - }) + if (isChatVariant) { + rowData.chat = JSON.stringify( + rowData.chat.map((item: ChatMessage) => removeKeys(item, ["id"])), + ) + rowData.correct_answer = JSON.stringify(removeKeys(rowData.correct_answer, ["id"])) + } setLoading(true) @@ -106,7 +112,7 @@ const AddToTestSetDrawer: React.FC = ({params, isChatVariant, ...props}) }) .finally(() => setLoading(false)) }, - [selectedTestset, props.onClose], + [selectedTestset, props.onClose, isChatVariant], ) const onFinish = useCallback( @@ -219,7 +225,7 @@ const AddToTestSetDrawer: React.FC = ({params, isChatVariant, ...props}) > {isChatVariant ? (
- +
Chat = ({params, isChatVariant, ...props}) dirty.current = true }} /> - +
- +
Correct Answer = ({params, isChatVariant, ...props}) disableAdd disableRemove /> - +
) : (
{ @@ -221,33 +220,31 @@ const Playground: React.FC = () => {
{contextHolder} - -
-
- { - setIsLoading(true) - fetchData() - }} - /> -
- { - if (action === "add") { - setIsModalOpen(true) - } else if (action === "remove") { - deleteVariant() - } +
+
+ { + setIsLoading(true) + fetchData() }} - items={tabItems} />
- + { + if (action === "add") { + setIsModalOpen(true) + } else if (action === "remove") { + deleteVariant() + } + }} + items={tabItems} + /> +
> -}>({testList: [{}], setTestList: () => {}}) - -const TestsetContextProvider: React.FC = (props) => { - const [testList, setTestList] = useState([{}]) - - return ( - - {props.children} - - ) -} - -export default TestsetContextProvider diff --git a/agenta-web/src/components/Playground/Views/TestView.tsx b/agenta-web/src/components/Playground/Views/TestView.tsx index 825b94a6e8..b9d969009b 100644 --- a/agenta-web/src/components/Playground/Views/TestView.tsx +++ b/agenta-web/src/components/Playground/Views/TestView.tsx @@ -1,4 +1,4 @@ -import React, {useContext, useState} from "react" +import React, {useState} from "react" import {Button, Input, Card, Row, Col, Space} from "antd" import {CaretRightOutlined, PlusOutlined} from "@ant-design/icons" import {callVariant} from "@/lib/services/api" @@ -10,7 +10,6 @@ import {DeleteOutlined} from "@ant-design/icons" import {getErrorMessage} from "@/lib/helpers/errorHandler" import {createUseStyles} from "react-jss" import CopyButton from "@/components/CopyButton/CopyButton" -import {TestContext} from "../TestsetContextProvider" import {useRouter} from "next/router" import ChatInputs, {getDefaultNewMessage} from "@/components/ChatInputs/ChatInputs" import {v4 as uuidv4} from "uuid" @@ -205,7 +204,7 @@ const BoxComponent: React.FC = ({ const App: React.FC = ({inputParams, optParams, variant, isChatVariant}) => { const router = useRouter() const appId = router.query.app_id as unknown as string - const {testList, setTestList} = useContext(TestContext) + const [testList, setTestList] = useState([{}]) const [resultsList, setResultsList] = useState(testList.map(() => "")) const [params, setParams] = useState | null>(null) const classes = useStylesApp() @@ -301,9 +300,9 @@ const App: React.FC = ({inputParams, optParams, variant, isChatVa ...test, ...(isChatVariant ? { - chat: safeParse(test.chat, []).concat([ - safeParse(test.correct_answer, getDefaultNewMessage()), - ]), + chat: safeParse(test.chat, []) + .concat([safeParse(test.correct_answer, getDefaultNewMessage())]) + .map((item: Partial) => ({...item, id: uuidv4()})), } : {}), _id: randString(6), diff --git a/agenta-web/src/pages/apps/[app_id]/endpoints/index.tsx b/agenta-web/src/pages/apps/[app_id]/endpoints/index.tsx index 6dff0977e5..4f900d2e00 100644 --- a/agenta-web/src/pages/apps/[app_id]/endpoints/index.tsx +++ b/agenta-web/src/pages/apps/[app_id]/endpoints/index.tsx @@ -96,7 +96,7 @@ export default function VariantEndpoint() { } }, [variants, appId]) - const {inputParams, optParams, isLoading, isError, error} = useVariant(appId, variant!) + const {inputParams, isChatVariant, isLoading, isError, error} = useVariant(appId, variant!) const createParams = ( inputParams: Parameter[] | null, environmentName: string, @@ -112,7 +112,14 @@ export default function VariantEndpoint() { secondaryParams[item.name] = item.default || value } }) - if (Object.keys(secondaryParams).length > 0) { + if (isChatVariant) { + mainParams["inputs"] = [ + { + role: "user", + content: "Example message", + }, + ] + } else if (Object.keys(secondaryParams).length > 0) { mainParams["inputs"] = secondaryParams } diff --git a/examples/experimental/startup_feature_ideas/.gitignore b/examples/experimental/startup_feature_ideas/.gitignore new file mode 100644 index 0000000000..003430f461 --- /dev/null +++ b/examples/experimental/startup_feature_ideas/.gitignore @@ -0,0 +1,7 @@ +# Environments +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ +myenv/