diff --git a/api/oss/src/services/db_manager.py b/api/oss/src/services/db_manager.py index 2639f29711..2eae87f25c 100644 --- a/api/oss/src/services/db_manager.py +++ b/api/oss/src/services/db_manager.py @@ -2608,8 +2608,18 @@ async def remove_testsets(testset_ids: List[str]): query = select(TestSetDB).where(TestSetDB.id.in_(testset_ids)) result = await session.execute(query) testsets = result.scalars().all() - for testset in testsets: + + for i, testset in enumerate(testsets): + log.info( + f"[TESTSET] DELETE ({i}):", + project_id=testset.project_id, + testset_id=testset.id, + count=len(testset.csvdata), + size=len(dumps(testset.csvdata).encode("utf-8")), + ) + await session.delete(testset) + await session.commit() @@ -2772,8 +2782,18 @@ async def fetch_testset_by_id(testset_id: str) -> Optional[TestSetDB]: async with engine.core_session() as session: result = await session.execute(select(TestSetDB).filter_by(id=testset_uuid)) testset = result.scalars().first() + if not testset: raise NoResultFound(f"Testset with id {testset_id} not found") + + log.info( + "[TESTSET] READ:", + project_id=testset.project_id, + testset_id=testset.id, + count=len(testset.csvdata), + size=len(dumps(testset.csvdata).encode("utf-8")), + ) + return testset @@ -2791,21 +2811,21 @@ async def create_testset(project_id: str, testset_data: Dict[str, Any]): """ async with engine.core_session() as session: - testset_db = TestSetDB(**testset_data, project_id=uuid.UUID(project_id)) + testset = TestSetDB(**testset_data, project_id=uuid.UUID(project_id)) log.info( - "Saving testset:", - project_id=testset_db.project_id, - testset_id=testset_db.id, - count=len(testset_db.csvdata), - size=len(dumps(testset_db.csvdata).encode("utf-8")), + "[TESTSET] CREATE:", + project_id=testset.project_id, + testset_id=testset.id, + count=len(testset.csvdata), + size=len(dumps(testset.csvdata).encode("utf-8")), ) - session.add(testset_db) + session.add(testset) await session.commit() - await session.refresh(testset_db) + await session.refresh(testset) - return testset_db + return testset async def update_testset(testset_id: str, values_to_update: dict) -> None: @@ -2824,11 +2844,12 @@ async def update_testset(testset_id: str, values_to_update: dict) -> None: # Validate keys in values_to_update and update attributes valid_keys = [key for key in values_to_update.keys() if hasattr(testset, key)] + for key in valid_keys: setattr(testset, key, values_to_update[key]) log.info( - "Saving testset:", + "[TESTSET] UPDATE:", project_id=testset.project_id, testset_id=testset.id, count=len(testset.csvdata), @@ -2854,6 +2875,16 @@ async def fetch_testsets_by_project_id(project_id: str): select(TestSetDB).filter_by(project_id=uuid.UUID(project_id)) ) testsets = result.scalars().all() + + for i, testset in enumerate(testsets): + log.info( + f"[TESTSET] READ ({i}):", + project_id=testset.project_id, + testset_id=testset.id, + count=len(testset.csvdata), + size=len(dumps(testset.csvdata).encode("utf-8")), + ) + return testsets diff --git a/api/pyproject.toml b/api/pyproject.toml index 077421a328..c1bd003b24 100644 --- a/api/pyproject.toml +++ b/api/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "api" -version = "0.59.6" +version = "0.59.7" description = "Agenta API" authors = [ { name = "Mahmoud Mabrouk", email = "mahmoud@agenta.ai" }, diff --git a/docs/docusaurus.config.ts b/docs/docusaurus.config.ts index b2c8624b97..acc6417bfc 100644 --- a/docs/docusaurus.config.ts +++ b/docs/docusaurus.config.ts @@ -23,7 +23,7 @@ const config: Config = { titleDelimiter: "-", // Even if you don't use internationalization, you can use this field to set // useful metadata like html lang. For example, if your site is Chinese, you - // may want to replace "en" with "zh-Hans". + // may want to replace "en" with "zh-Hans". i18n: { defaultLocale: "en", locales: ["en"], diff --git a/sdk/pyproject.toml b/sdk/pyproject.toml index 4aca92445f..72a0c1303a 100644 --- a/sdk/pyproject.toml +++ b/sdk/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "agenta" -version = "0.59.6" +version = "0.59.7" description = "The SDK for agenta is an open-source LLMOps platform." readme = "README.md" authors = [ diff --git a/web/ee/package.json b/web/ee/package.json index f797fe335c..39f418661f 100644 --- a/web/ee/package.json +++ b/web/ee/package.json @@ -1,6 +1,6 @@ { "name": "@agenta/ee", - "version": "0.59.6", + "version": "0.59.7", "private": true, "engines": { "node": ">=18" diff --git a/web/oss/package.json b/web/oss/package.json index 6de474ffea..aabe09effa 100644 --- a/web/oss/package.json +++ b/web/oss/package.json @@ -1,6 +1,6 @@ { "name": "@agenta/oss", - "version": "0.59.6", + "version": "0.59.7", "private": true, "engines": { "node": ">=18" diff --git a/web/oss/src/state/testset/atoms/fetcher.ts b/web/oss/src/state/testset/atoms/fetcher.ts index 46727a9c11..6bc9f08412 100644 --- a/web/oss/src/state/testset/atoms/fetcher.ts +++ b/web/oss/src/state/testset/atoms/fetcher.ts @@ -6,6 +6,7 @@ import {fetchTestsets, fetchPreviewTestsets} from "@/oss/services/testsets/api" import {PreviewTestsetsQueryPayload} from "@/oss/services/testsets/api/types" import {projectIdAtom} from "../../project" +import {userAtom} from "../../profile" // Local options type for enabling/disabling queries interface TestsetsQueryOptions { @@ -17,17 +18,19 @@ interface TestsetsQueryOptions { */ export const testsetsQueryAtom = atomWithQuery((get) => { const projectId = get(projectIdAtom) + const user = get(userAtom) return { queryKey: ["testsets", projectId], queryFn: () => { return fetchTestsets() }, - staleTime: 1000 * 60, + staleTime: 5 * 60 * 1000, + gcTime: 30 * 60 * 1000, refetchOnWindowFocus: false, refetchOnReconnect: false, refetchOnMount: false, - enabled: !!projectId, + enabled: !!user?.id && !!projectId, } }) @@ -41,6 +44,7 @@ export const previewTestsetsQueryAtomFamily = atomFamily( }: {payload?: PreviewTestsetsQueryPayload; enabled?: boolean} = {}) => atomWithQuery((get) => { const projectId = get(projectIdAtom) + const user = get(userAtom) const payloadKey = JSON.stringify(payload || {}) @@ -51,25 +55,35 @@ export const previewTestsetsQueryAtomFamily = atomFamily( refetchOnWindowFocus: false, refetchOnReconnect: false, refetchOnMount: false, - enabled: enabled && !!projectId, + enabled: !!user?.id && enabled && !!projectId, } }), + (a, b) => { + const aEnabled = a?.enabled ?? true + const bEnabled = b?.enabled ?? true + const aKey = JSON.stringify(a?.payload ?? {}) + const bKey = JSON.stringify(b?.payload ?? {}) + return aEnabled === bEnabled && aKey === bKey + }, ) -export const testsetsQueryAtomFamily = atomFamily(({enabled = true}: TestsetsQueryOptions = {}) => - atomWithQuery((get) => { - const projectId = get(projectIdAtom) +export const testsetsQueryAtomFamily = atomFamily( + ({enabled = true}: TestsetsQueryOptions = {}) => + atomWithQuery((get) => { + const projectId = get(projectIdAtom) + const user = get(userAtom) - return { - queryKey: ["testsets", projectId], - queryFn: fetchTestsets, - staleTime: 1000 * 60, - refetchOnWindowFocus: false, - refetchOnReconnect: false, - refetchOnMount: false, - enabled: enabled && !!projectId, - } - }), + return { + queryKey: ["testsets", projectId], + queryFn: fetchTestsets, + staleTime: 1000 * 60, + refetchOnWindowFocus: false, + refetchOnReconnect: false, + refetchOnMount: false, + enabled: !!user?.id && enabled && !!projectId, + } + }), + (a, b) => (a?.enabled ?? true) === (b?.enabled ?? true), ) /** diff --git a/web/oss/src/state/testset/hooks/index.ts b/web/oss/src/state/testset/hooks/index.ts index 52e5ad05f5..b79600080d 100644 --- a/web/oss/src/state/testset/hooks/index.ts +++ b/web/oss/src/state/testset/hooks/index.ts @@ -1,5 +1,3 @@ -import {useMemo} from "react" - import {useAtom} from "jotai" import {PreviewTestsetsQueryPayload} from "@/oss/services/testsets/api/types" @@ -7,7 +5,7 @@ import {PreviewTestsetsQueryPayload} from "@/oss/services/testsets/api/types" import { previewTestsetsQueryAtom, previewTestsetsQueryAtomFamily, - testsetsQueryAtomFamily, + testsetsQueryAtom, } from "../atoms/fetcher" export {useTestset, testsetQueryAtomFamily} from "./useTestset" @@ -19,8 +17,7 @@ export {useTestset, testsetQueryAtomFamily} from "./useTestset" * @returns Object with `testsets`, `isError`, `error`, `isLoading`, `mutate` */ export const useTestsetsData = ({enabled = true} = {}) => { - const stableAtom = useMemo(() => testsetsQueryAtomFamily({enabled}), [enabled]) - const [{data: testsets, isPending, refetch, error, isError}] = useAtom(stableAtom) + const [{data: testsets, isPending, refetch, error, isError}] = useAtom(testsetsQueryAtom) return { testsets: testsets ?? [], @@ -61,11 +58,9 @@ export const usePreviewTestsetsDataWithFilters = ( payload: PreviewTestsetsQueryPayload = {}, {enabled = true}: {enabled?: boolean} = {}, ) => { - const stableAtom = useMemo( - () => previewTestsetsQueryAtomFamily({payload, enabled}), - [payload, enabled], + const [{data: testsets, isPending, refetch, error, isError}] = useAtom( + previewTestsetsQueryAtomFamily({payload, enabled}), ) - const [{data: testsets, isPending, refetch, error, isError}] = useAtom(stableAtom) return { testsets: testsets ?? [], diff --git a/web/oss/src/state/testset/index.tsx b/web/oss/src/state/testset/index.tsx index f03d061c82..1a018f9dd8 100644 --- a/web/oss/src/state/testset/index.tsx +++ b/web/oss/src/state/testset/index.tsx @@ -7,15 +7,14 @@ import axios from "@/oss/lib/api/assets/axiosConfig" import {getAgentaApiUrl} from "@/oss/lib/helpers/api" import {TestSet} from "@/oss/lib/Types" -import {previewTestsetsQueryAtom, testsetsQueryAtomFamily} from "./atoms/fetcher" +import {previewTestsetsQueryAtom, testsetsQueryAtom} from "./atoms/fetcher" import {useTestset} from "./hooks/useTestset" /** * Hook for regular/legacy testsets */ export const useTestsetsData = ({enabled = true} = {}) => { - const stableAtom = useMemo(() => testsetsQueryAtomFamily({enabled}), [enabled]) - const [{data: testsets, isPending, refetch, error, isError}] = useAtom(stableAtom) + const [{data: testsets, isPending, refetch, error, isError}] = useAtom(testsetsQueryAtom) const queryClient = useQueryClient() const [columnsFallback, setColumnsFallback] = useState>({}) const [csvVersion, setCsvVersion] = useState(0) @@ -114,7 +113,7 @@ export const useTestsetsData = ({enabled = true} = {}) => { return () => controller.abort() }, [testsets, columnsByTestsetId, columnsFallback]) - // When any testsetCsvData query updates, bump csvVersion and optionally refetch testsets + // When any testsetCsvData query updates, bump csvVersion useEffect(() => { const unsubscribe = queryClient.getQueryCache().subscribe((event) => { // Only react to updates of our csv data queries @@ -122,12 +121,10 @@ export const useTestsetsData = ({enabled = true} = {}) => { const key0 = q?.queryKey?.[0] if (key0 === "testsetCsvData") { setCsvVersion((v) => v + 1) - // Optionally refetch to propagate other derived server info - refetch() } }) return unsubscribe - }, [queryClient, refetch]) + }, [queryClient]) return { testsets: testsets ?? [], diff --git a/web/package.json b/web/package.json index 161af00a0c..919c256ae9 100644 --- a/web/package.json +++ b/web/package.json @@ -1,6 +1,6 @@ { "name": "agenta-web", - "version": "0.59.6", + "version": "0.59.7", "workspaces": [ "ee", "oss",