Skip to content
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
53 changes: 42 additions & 11 deletions api/oss/src/services/db_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down Expand Up @@ -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


Expand All @@ -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:
Expand All @@ -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),
Expand All @@ -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


Expand Down
2 changes: 1 addition & 1 deletion api/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "api"
version = "0.59.6"
version = "0.59.7"
description = "Agenta API"
authors = [
{ name = "Mahmoud Mabrouk", email = "[email protected]" },
Expand Down
2 changes: 1 addition & 1 deletion docs/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
2 changes: 1 addition & 1 deletion sdk/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion web/ee/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@agenta/ee",
"version": "0.59.6",
"version": "0.59.7",
"private": true,
"engines": {
"node": ">=18"
Expand Down
2 changes: 1 addition & 1 deletion web/oss/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@agenta/oss",
"version": "0.59.6",
"version": "0.59.7",
"private": true,
"engines": {
"node": ">=18"
Expand Down
46 changes: 30 additions & 16 deletions web/oss/src/state/testset/atoms/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -17,17 +18,19 @@ interface TestsetsQueryOptions {
*/
export const testsetsQueryAtom = atomWithQuery<testset[]>((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,
}
})

Expand All @@ -41,6 +44,7 @@ export const previewTestsetsQueryAtomFamily = atomFamily(
}: {payload?: PreviewTestsetsQueryPayload; enabled?: boolean} = {}) =>
atomWithQuery<testset[]>((get) => {
const projectId = get(projectIdAtom)
const user = get(userAtom)

const payloadKey = JSON.stringify(payload || {})

Expand All @@ -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<testset[]>((get) => {
const projectId = get(projectIdAtom)
export const testsetsQueryAtomFamily = atomFamily(
({enabled = true}: TestsetsQueryOptions = {}) =>
atomWithQuery<testset[]>((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),
)

/**
Expand Down
13 changes: 4 additions & 9 deletions web/oss/src/state/testset/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import {useMemo} from "react"

import {useAtom} from "jotai"

import {PreviewTestsetsQueryPayload} from "@/oss/services/testsets/api/types"

import {
previewTestsetsQueryAtom,
previewTestsetsQueryAtomFamily,
testsetsQueryAtomFamily,
testsetsQueryAtom,
} from "../atoms/fetcher"

export {useTestset, testsetQueryAtomFamily} from "./useTestset"
Expand All @@ -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 ?? [],
Expand Down Expand Up @@ -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 ?? [],
Expand Down
11 changes: 4 additions & 7 deletions web/oss/src/state/testset/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Record<string, string[]>>({})
const [csvVersion, setCsvVersion] = useState(0)
Expand Down Expand Up @@ -114,20 +113,18 @@ 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
const q = (event as any)?.query
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 ?? [],
Expand Down
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "agenta-web",
"version": "0.59.6",
"version": "0.59.7",
"workspaces": [
"ee",
"oss",
Expand Down