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
41 changes: 12 additions & 29 deletions agenta-web/src/components/Evaluations/Evaluations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import EvaluationTable from '../EvaluationTable/EvaluationTable';
import EvaluationTableWithChat from '../EvaluationTable/EvaluationTableWithChat';
import { DownOutlined } from '@ant-design/icons';
import AppContext from '@/contexts/appContext';
import { listVariants } from '@/services/api';
import { listVariants, loadDatasetsList } from '@/services/api';
import { useRouter } from 'next/router';

import dataset from './dataset-startup-ideas.json';

export default function Evaluations() {
const { app } = useContext(AppContext);
const router = useRouter();
Expand All @@ -23,37 +21,36 @@ export default function Evaluations() {
const [comparisonTableId, setComparisonTableId] = useState("");
const [newEvaluationEnvironment, setNewEvaluationEnvironment] = useState(false);

const breadcrumbItems = [
{ title: 'Home' },
{ title: <a href="">{app}</a> },
{ title: <a href="">Evaluations</a> }
];

const { datasets, isDatasetsLoading, isDatasetsLoadingError } = loadDatasetsList();

useEffect(() => {
if (app == "") {
router.push("/");
}
}, [app]);


const breadcrumbItems = [
{ title: 'Home' },
{ title: <a href="">{app}</a> },
{ title: <a href="">Evaluations</a> }
];

useEffect(() => {
if (variants && Array.isArray(variants) && variants.length > 0) {
const appVariantsFromResponse = variants.map((item: any, index: number) => ({
id: index,
name: item.variant_name,
endpoint: item.variant_name
}));

setAppVariants(appVariantsFromResponse);

}

}, []);

useEffect(() => {
loadDatasetsList();
}, []);
if (!isDatasetsLoadingError && datasets) {
setDatasetsList(datasets);
}
}, [datasets, isDatasetsLoadingError]);

useEffect(() => {
if (newEvaluationEnvironment) {
Expand All @@ -62,7 +59,6 @@ export default function Evaluations() {
}
}, [newEvaluationEnvironment]);


const { variants, isLoading, isError } = listVariants(app);
if (isError) return <div>failed to load list of variants</div>
if (isLoading) return <div>loading variants</div>
Expand Down Expand Up @@ -128,19 +124,6 @@ export default function Evaluations() {
loadDataset()
};

const loadDatasetsList = () => {
fetch('http://localhost/api/datasets', {
headers: {
"Content-Type": "application/json",
}
})
.then((res) => res.json())
.then((data) => {
console.log(data)
setDatasetsList(data);
});
};

const loadDataset = () => {
fetch(`http://localhost/api/datasets/${selectedDataset._id}`, {
headers: {
Expand Down
42 changes: 0 additions & 42 deletions agenta-web/src/components/Evaluations/dataset-startup-ideas.json

This file was deleted.

27 changes: 20 additions & 7 deletions agenta-web/src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export function listVariants(app_name: string) {

/**
* This function runs a variant and returns the result. It calls the right api endpoint.
* and take care of specifying the right parameters if needed.
* @param app_name
* @param variantName
* @param inputs
* and take care of specifying the right parameters if needed.
* @param app_name
* @param variantName
* @param inputs
* @returns - the result of the variant as a json object
*/
export function runVariant(appName: string, variantName: string, inputs: any) {
Expand All @@ -35,9 +35,9 @@ export function runVariant(appName: string, variantName: string, inputs: any) {

/**
* Parses the openapi.json from a variant and returns the parameters as an array of objects.
* @param app
* @param variantName
* @returns
* @param app
* @param variantName
* @returns
*/
export const fetchVariantParameters = async (app: string, variantName: string) => {
try {
Expand All @@ -48,4 +48,17 @@ export const fetchVariantParameters = async (app: string, variantName: string) =
} catch (error) {
throw error;
}
};

/**
* Loads the list of datasets
* @returns
*/
export const loadDatasetsList = () => {
const { data, error } = useSWR(`${API_BASE_URL}/api/datasets`, fetcher)
return {
datasets: data,
isDatasetsLoading: !error && !data,
isDatasetsLoadingError: error
}
};