diff --git a/agenta-web/src/components/AppSelector/AppCard.tsx b/agenta-web/src/components/AppSelector/AppCard.tsx index 0da35d2e97..80e7b422d1 100644 --- a/agenta-web/src/components/AppSelector/AppCard.tsx +++ b/agenta-web/src/components/AppSelector/AppCard.tsx @@ -1,6 +1,6 @@ import {Modal, Card, Avatar} from "antd" import {DeleteOutlined} from "@ant-design/icons" -import {removeApp} from "@/services/api" +import {deleteApp} from "@/services/api" import {useState} from "react" import Link from "next/link" import {renameVariablesCapitalizeAll} from "@/lib/helpers/utils" @@ -86,7 +86,7 @@ const AppCard: React.FC<{ const handleDeleteOk = async () => { setConfirmLoading(true) try { - await removeApp(app.app_id) + await deleteApp(app.app_id) mutate() } catch (error) { console.error(error) diff --git a/agenta-web/src/components/AppSelector/AppSelector.tsx b/agenta-web/src/components/AppSelector/AppSelector.tsx index 7b432b7904..60e97582a3 100644 --- a/agenta-web/src/components/AppSelector/AppSelector.tsx +++ b/agenta-web/src/components/AppSelector/AppSelector.tsx @@ -7,7 +7,12 @@ import {useAppTheme} from "../Layout/ThemeContextProvider" import TipsAndFeatures from "./TipsAndFeatures" import Welcome from "./Welcome" import {isAppNameInputValid, isDemo, redirectIfNoLLMKeys} from "@/lib/helpers/utils" -import {createAndStartTemplate, getTemplates, removeApp, waitForAppToStart} from "@/services/api" +import { + createAndStartTemplate, + fetchAllTemplates, + deleteApp, + waitForAppToStart, +} from "@/services/api" import AddNewAppModal from "./modals/AddNewAppModal" import AddAppFromTemplatedModal from "./modals/AddAppFromTemplateModal" import MaxAppModal from "./modals/MaxAppModal" @@ -17,7 +22,7 @@ import {useAppsData} from "@/contexts/app.context" import {useProfileData} from "@/contexts/profile.context" import CreateAppStatusModal from "./modals/CreateAppStatusModal" import {usePostHogAg} from "@/hooks/usePostHogAg" -import {LlmProvider, getAllProviderLlmKeys, getApikeys} from "@/lib/helpers/llmProviders" +import {LlmProvider, getAllProviderLlmKeys} from "@/lib/helpers/llmProviders" import ResultComponent from "../ResultComponent/ResultComponent" import {dynamicContext} from "@/lib/helpers/dynamic" @@ -170,7 +175,7 @@ const AppSelector: React.FC = () => { useEffect(() => { if (!isLoading) mutate() const fetchTemplates = async () => { - const data = await getTemplates() + const data = await fetchAllTemplates() if (typeof data == "object") { setTemplates(data) } else { @@ -221,7 +226,7 @@ const AppSelector: React.FC = () => { const onErrorRetry = async () => { if (statusData.appId) { setStatusData((prev) => ({...prev, status: "cleanup", details: undefined})) - await removeApp(statusData.appId).catch(console.error) + await deleteApp(statusData.appId).catch(console.error) mutate() } handleTemplateCardClick(templateId as string) diff --git a/agenta-web/src/components/Evaluations/AutomaticEvaluationResult.tsx b/agenta-web/src/components/Evaluations/AutomaticEvaluationResult.tsx index 8b1120d316..a6803746d1 100644 --- a/agenta-web/src/components/Evaluations/AutomaticEvaluationResult.tsx +++ b/agenta-web/src/components/Evaluations/AutomaticEvaluationResult.tsx @@ -1,7 +1,7 @@ import { deleteEvaluations, fetchEvaluationResults, - loadEvaluations, + fetchAllLoadEvaluations, } from "@/services/human-evaluations" import {Button, Spin, Statistic, Table, Typography} from "antd" import {useRouter} from "next/router" @@ -105,7 +105,7 @@ export default function AutomaticEvaluationResult({ const fetchEvaluations = async () => { try { setFetchingEvaluations(true) - const evals: Evaluation[] = (await loadEvaluations(app_id)).map( + const evals: Evaluation[] = (await fetchAllLoadEvaluations(app_id)).map( fromEvaluationResponseToEvaluation, ) const results = await Promise.all(evals.map((e) => fetchEvaluationResults(e.id))) diff --git a/agenta-web/src/components/Playground/AddToTestSetDrawer/AddToTestSetDrawer.tsx b/agenta-web/src/components/Playground/AddToTestSetDrawer/AddToTestSetDrawer.tsx index 1edb7ff247..ad12f55dde 100644 --- a/agenta-web/src/components/Playground/AddToTestSetDrawer/AddToTestSetDrawer.tsx +++ b/agenta-web/src/components/Playground/AddToTestSetDrawer/AddToTestSetDrawer.tsx @@ -4,7 +4,7 @@ import {ChatMessage, ChatRole, GenericObject, testset} from "@/lib/Types" import {removeKeys, renameVariables} from "@/lib/helpers/utils" import { createNewTestset, - loadTestset, + fetchTestset, updateTestset, useLoadTestsetsList, } from "@/services/testsets" @@ -184,7 +184,7 @@ const AddToTestSetDrawer: React.FC = ({params, isChatVariant, ...props}) if (isNew) { setNewTestsetModalOpen(true) } else { - loadTestset(selectedTestset!).then((data) => { + fetchTestset(selectedTestset!).then((data) => { const testsetCols = Object.keys(data.csvdata?.[0] || {}) const playgroundCols = Object.keys(values[0]) const missingColsTestset = testsetCols.filter( diff --git a/agenta-web/src/components/Playground/LoadTestsModal.tsx b/agenta-web/src/components/Playground/LoadTestsModal.tsx index ea2d9de76d..ed301ae3e5 100644 --- a/agenta-web/src/components/Playground/LoadTestsModal.tsx +++ b/agenta-web/src/components/Playground/LoadTestsModal.tsx @@ -1,4 +1,4 @@ -import {loadTestset, useLoadTestsetsList} from "@/services/testsets" +import {fetchTestset, useLoadTestsetsList} from "@/services/testsets" import {Button, Divider, Modal, Select} from "antd" import {useRouter} from "next/router" import {PropsWithChildren, useState} from "react" @@ -38,7 +38,7 @@ const LoadTestsModal: React.FC = (props) => { })) const handleClick = (shouldReplace: boolean) => { - loadTestset(selectedSet).then((data) => { + fetchTestset(selectedSet).then((data) => { onLoad(data.csvdata, shouldReplace) }) setIsOpen(false) diff --git a/agenta-web/src/components/Playground/Playground.tsx b/agenta-web/src/components/Playground/Playground.tsx index 207d5eb43e..e88789570f 100644 --- a/agenta-web/src/components/Playground/Playground.tsx +++ b/agenta-web/src/components/Playground/Playground.tsx @@ -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 {fetchVariants, saveNewVariant} from "@/services/api" +import {fetchVariants, createNewVariant} from "@/services/api" import {fetchEnvironments} from "@/services/deployment" import {Variant, PlaygroundTabsItem, Environment} from "@/lib/Types" import {AppstoreOutlined, SyncOutlined} from "@ant-design/icons" @@ -79,7 +79,7 @@ const Playground: React.FC = () => { } try { - await saveNewVariant( + await createNewVariant( newVariant.baseId!, newVariant.variantName!, newVariant.configName!, diff --git a/agenta-web/src/components/Playground/ViewNavigation.tsx b/agenta-web/src/components/Playground/ViewNavigation.tsx index f9ec7e4a42..5cdba5be68 100644 --- a/agenta-web/src/components/Playground/ViewNavigation.tsx +++ b/agenta-web/src/components/Playground/ViewNavigation.tsx @@ -9,8 +9,8 @@ import {useState} from "react" import axios from "axios" import {createUseStyles} from "react-jss" import { - getAppContainerURL, - removeVariant, + fetchAppContainerURL, + deleteSingleVariant, restartAppVariantContainer, waitForAppToStart, } from "@/services/api" @@ -125,7 +125,7 @@ const ViewNavigation: React.FC = ({ } const variantContainerPath = async () => { - const url = await getAppContainerURL(appId, variant.variantId, variant.baseId) + const url = await fetchAppContainerURL(appId, variant.variantId, variant.baseId) setContainerURI(url) } if (!containerURI) { @@ -210,7 +210,7 @@ const ViewNavigation: React.FC = ({ type="primary" danger onClick={() => { - deleteVariant(() => removeVariant(variant.variantId)) + deleteVariant(() => deleteSingleVariant(variant.variantId)) }} > diff --git a/agenta-web/src/components/Playground/Views/ParametersView.tsx b/agenta-web/src/components/Playground/Views/ParametersView.tsx index e91ed7b423..c110ac572c 100644 --- a/agenta-web/src/components/Playground/Views/ParametersView.tsx +++ b/agenta-web/src/components/Playground/Views/ParametersView.tsx @@ -5,7 +5,7 @@ import React, {useEffect, useState} from "react" import {createUseStyles} from "react-jss" import {ModelParameters, ObjectParameters, StringParameters} from "./ParametersCards" import PublishVariantModal from "./PublishVariantModal" -import {removeVariant} from "@/services/api" +import {deleteSingleVariant} from "@/services/api" import {CloudUploadOutlined, DeleteOutlined, HistoryOutlined, SaveOutlined} from "@ant-design/icons" import {usePostHogAg} from "@/hooks/usePostHogAg" import {isDemo} from "@/lib/helpers/utils" @@ -134,7 +134,7 @@ const ParametersView: React.FC = ({ const handleDelete = () => { deleteVariant(() => { if (variant.persistent) { - return removeVariant(variant.variantId).then(() => { + return deleteSingleVariant(variant.variantId).then(() => { onStateChange(false) }) } diff --git a/agenta-web/src/components/Playground/Views/PublishVariantModal.tsx b/agenta-web/src/components/Playground/Views/PublishVariantModal.tsx index 819899a9c1..263691f6d1 100644 --- a/agenta-web/src/components/Playground/Views/PublishVariantModal.tsx +++ b/agenta-web/src/components/Playground/Views/PublishVariantModal.tsx @@ -1,7 +1,7 @@ import {usePostHogAg} from "@/hooks/usePostHogAg" import {Environment, Variant} from "@/lib/Types" import {variantNameWithRev} from "@/lib/helpers/variantHelper" -import {fetchEnvironments, publishVariant} from "@/services/deployment" +import {fetchEnvironments, createPublishVariant} from "@/services/deployment" import {Button, Checkbox, Modal, Space, Typography, message} from "antd" import type {CheckboxChangeEvent} from "antd/es/checkbox" import {useRouter} from "next/router" @@ -54,7 +54,7 @@ const PublishVariantModal: React.FC = ({ const publishVariants = async () => { selectedEnvs.forEach(async (envName) => { - await publishVariant(variant.variantId, envName) + await createPublishVariant(variant.variantId, envName) closeModal() await loadEnvironments() message.success(`Published ${variant.variantName} to ${envName}`) diff --git a/agenta-web/src/components/TestSetTable/TestsetTable.tsx b/agenta-web/src/components/TestSetTable/TestsetTable.tsx index 733300e638..46a5498106 100644 --- a/agenta-web/src/components/TestSetTable/TestsetTable.tsx +++ b/agenta-web/src/components/TestSetTable/TestsetTable.tsx @@ -5,7 +5,7 @@ import {Button, Input, Tooltip, Typography, message} from "antd" import TestsetMusHaveNameModal from "./InsertTestsetNameModal" import {DeleteOutlined, EditOutlined, PlusOutlined} from "@ant-design/icons" import {fetchVariants} from "@/services/api" -import {createNewTestset, loadTestset, updateTestset} from "@/services/testsets" +import {createNewTestset, fetchTestset, updateTestset} from "@/services/testsets" import {useRouter} from "next/router" import {useAppTheme} from "../Layout/ThemeContextProvider" import useBlockNavigation from "@/hooks/useBlockNavigation" @@ -208,7 +208,7 @@ const TestsetTable: React.FC = ({mode}) => { if (mode === "edit" && testset_id) { setLoading(true) - loadTestset(testset_id as string).then((data) => { + fetchTestset(testset_id as string).then((data) => { setTestsetName(data.name) setRowData(data.csvdata) applyColData( diff --git a/agenta-web/src/contexts/profile.context.tsx b/agenta-web/src/contexts/profile.context.tsx index 2e945db611..a59ffa4229 100644 --- a/agenta-web/src/contexts/profile.context.tsx +++ b/agenta-web/src/contexts/profile.context.tsx @@ -2,7 +2,7 @@ import {usePostHogAg} from "@/hooks/usePostHogAg" import {useSession} from "@/hooks/useSession" import useStateCallback from "@/hooks/useStateCallback" import {isDemo} from "@/lib/helpers/utils" -import {getProfile} from "@/services/api" +import {fetchProfile} from "@/services/api" import {User} from "@/lib/Types" import {PropsWithChildren, createContext, useState, useContext, useEffect, useCallback} from "react" @@ -36,7 +36,7 @@ const ProfileContextProvider: React.FC = ({children}) => { const fetcher = useCallback((onSuccess?: () => void) => { setLoading(true) - getProfile() + fetchProfile() .then((profile) => { posthog.identify() setUser(profile.data, onSuccess) diff --git a/agenta-web/src/lib/helpers/variantHelper.ts b/agenta-web/src/lib/helpers/variantHelper.ts index ab380a53ad..d95e14eb59 100644 --- a/agenta-web/src/lib/helpers/variantHelper.ts +++ b/agenta-web/src/lib/helpers/variantHelper.ts @@ -1,5 +1,5 @@ import {Variant, Parameter, InputParameter} from "@/lib/Types" -import {getVariantParametersFromOpenAPI} from "@/services/api" +import {fetchVariantParametersFromOpenAPI} from "@/services/api" const inputParamsToParameters = (additionalInputs: InputParameter[]): Parameter[] => { return additionalInputs.map((value) => ({ @@ -48,7 +48,7 @@ export const getAllVariantParameters = async (appId: string, variant: Variant) = let parameters: Parameter[] = [] let inputs: Parameter[] = [] try { - const {initOptParams, inputParams, isChatVariant} = await getVariantParametersFromOpenAPI( + const {initOptParams, inputParams, isChatVariant} = await fetchVariantParametersFromOpenAPI( appId, variant.variantId, variant.baseId, diff --git a/agenta-web/src/lib/hooks/useVariant.ts b/agenta-web/src/lib/hooks/useVariant.ts index 6509f5bdcb..87b3e178c8 100644 --- a/agenta-web/src/lib/hooks/useVariant.ts +++ b/agenta-web/src/lib/hooks/useVariant.ts @@ -1,5 +1,5 @@ import {useState, useEffect} from "react" -import {saveNewVariant, updateVariantParams} from "@/services/api" +import {createNewVariant, updateVariantParams} from "@/services/api" import {Variant, Parameter} from "@/lib/Types" import {getAllVariantParameters, updateInputParams} from "@/lib/helpers/variantHelper" import {PERMISSION_ERR_MSG} from "../helpers/axiosConfig" @@ -74,7 +74,7 @@ export function useVariant(appId: string, variant: Variant) { try { if (persist) { if (!updateVariant) { - await saveNewVariant( + await createNewVariant( variant.baseId, variant.variantName, variant.configName, @@ -185,7 +185,7 @@ export function useVariants(appId: string, variants: Variant[]) { try { if (persist) { if (!updateVariant) { - await saveNewVariant( + await createNewVariant( variant.baseId, variant.variantName, variant.configName, diff --git a/agenta-web/src/pages/apps/[app_id]/annotations/human_a_b_testing/[evaluation_id]/index.tsx b/agenta-web/src/pages/apps/[app_id]/annotations/human_a_b_testing/[evaluation_id]/index.tsx index 46f5ccd411..8f55088960 100644 --- a/agenta-web/src/pages/apps/[app_id]/annotations/human_a_b_testing/[evaluation_id]/index.tsx +++ b/agenta-web/src/pages/apps/[app_id]/annotations/human_a_b_testing/[evaluation_id]/index.tsx @@ -1,7 +1,7 @@ import ABTestingEvaluationTable from "@/components/EvaluationTable/ABTestingEvaluationTable" import {Evaluation} from "@/lib/Types" -import {loadEvaluation, loadEvaluationsScenarios} from "@/services/human-evaluations" -import {loadTestset} from "@/services/testsets" +import {fetchLoadEvaluation, fetchAllLoadEvaluationsScenarios} from "@/services/human-evaluations" +import {fetchTestset} from "@/services/testsets" import {useRouter} from "next/router" import {useEffect, useState} from "react" import {fetchVariants} from "@/services/api" @@ -27,7 +27,7 @@ export default function Evaluation() { const init = async () => { setIsLoading(true) try { - const data = await loadEvaluationsScenarios(evaluationTableId, evaluation) + const data = await fetchAllLoadEvaluationsScenarios(evaluationTableId, evaluation) setEvaluationScenarios(data) } finally { setTimeout(() => setIsLoading(false), 1000) @@ -41,9 +41,9 @@ export default function Evaluation() { return } const init = async () => { - const evaluation: Evaluation = await loadEvaluation(evaluationTableId) + const evaluation: Evaluation = await fetchLoadEvaluation(evaluationTableId) const backendVariants = await fetchVariants(appId) - const testset = await loadTestset(evaluation.testset._id) + const testset = await fetchTestset(evaluation.testset._id) // Create a map for faster access to first array elements let backendVariantsMap = new Map() backendVariants.forEach((obj) => backendVariantsMap.set(obj.variantId, obj)) diff --git a/agenta-web/src/pages/apps/[app_id]/annotations/single_model_test/[evaluation_id]/index.tsx b/agenta-web/src/pages/apps/[app_id]/annotations/single_model_test/[evaluation_id]/index.tsx index cbef57c88c..5a9988a468 100644 --- a/agenta-web/src/pages/apps/[app_id]/annotations/single_model_test/[evaluation_id]/index.tsx +++ b/agenta-web/src/pages/apps/[app_id]/annotations/single_model_test/[evaluation_id]/index.tsx @@ -1,6 +1,6 @@ import {Evaluation, EvaluationScenario, GenericObject} from "@/lib/Types" -import {loadEvaluation, loadEvaluationsScenarios} from "@/services/human-evaluations" -import {loadTestset} from "@/services/testsets" +import {fetchLoadEvaluation, fetchAllLoadEvaluationsScenarios} from "@/services/human-evaluations" +import {fetchTestset} from "@/services/testsets" import {useRouter} from "next/router" import {useEffect, useState} from "react" import {fetchVariants} from "@/services/api" @@ -24,7 +24,7 @@ export default function Evaluation() { const init = async () => { setIsLoading(true) try { - const data = await loadEvaluationsScenarios(evaluationTableId, evaluation) + const data = await fetchAllLoadEvaluationsScenarios(evaluationTableId, evaluation) setEvaluationScenarios( data.map((item: GenericObject) => { const numericScore = parseInt(item.score) @@ -43,9 +43,9 @@ export default function Evaluation() { return } const init = async () => { - const evaluation: Evaluation = await loadEvaluation(evaluationTableId) + const evaluation: Evaluation = await fetchLoadEvaluation(evaluationTableId) const backendVariants = await fetchVariants(appId) - const testset = await loadTestset(evaluation.testset._id) + const testset = await fetchTestset(evaluation.testset._id) // Create a map for faster access to first array elements let backendVariantsMap = new Map() backendVariants.forEach((obj) => backendVariantsMap.set(obj.variantId, obj)) 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 6ff2fc9761..01833c9eab 100644 --- a/agenta-web/src/pages/apps/[app_id]/endpoints/index.tsx +++ b/agenta-web/src/pages/apps/[app_id]/endpoints/index.tsx @@ -10,7 +10,7 @@ import {Environment, GenericObject, JSSTheme, Parameter, Variant} from "@/lib/Ty import {isDemo} from "@/lib/helpers/utils" import {dynamicComponent} from "@/lib/helpers/dynamic" import {useVariant} from "@/lib/hooks/useVariant" -import {fetchVariants, getAppContainerURL} from "@/services/api" +import {fetchVariants, fetchAppContainerURL} from "@/services/api" import {fetchEnvironments} from "@/services/deployment" import {ApiOutlined, AppstoreOutlined, HistoryOutlined} from "@ant-design/icons" import {Alert, Collapse, CollapseProps, Empty, Radio, Tabs, Tooltip, Typography} from "antd" @@ -51,7 +51,7 @@ export default function VariantEndpoint() { const [uri, setURI] = useState(null) const loadURL = async (environment: Environment) => { if (environment.deployed_app_variant_id) { - const url = await getAppContainerURL(appId, environment.deployed_app_variant_id) + const url = await fetchAppContainerURL(appId, environment.deployed_app_variant_id) setURI(`${url}/generate_deployed`) } } diff --git a/agenta-web/src/services/api.ts b/agenta-web/src/services/api.ts index a2882bc312..d4127f4214 100644 --- a/agenta-web/src/services/api.ts +++ b/agenta-web/src/services/api.ts @@ -8,6 +8,13 @@ import { import {getAgentaApiUrl, removeKeys, shortPoll} from "@/lib/helpers/utils" import {Variant, Parameter, AppTemplate, ChatMessage, KeyValuePair} from "@/lib/Types" +//Prefix convention: +// - fetch: GET single entity from server +// - fetchAll: GET all entities from server +// - create: POST data to server +// - update: PUT data to server +// - delete: DELETE data from server + /** * Raw interface for the parameters parsed from the openapi.json */ @@ -100,7 +107,7 @@ export async function callVariant( : secondaryInputParams, } - const appContainerURI = await getAppContainerURL(appId, undefined, baseId) + const appContainerURI = await fetchAppContainerURL(appId, undefined, baseId) return axios .post(`${appContainerURI}/generate`, requestBody, { @@ -118,13 +125,13 @@ export async function callVariant( * @param variantName * @returns */ -export const getVariantParametersFromOpenAPI = async ( +export const fetchVariantParametersFromOpenAPI = async ( appId: string, variantId?: string, baseId?: string, ignoreAxiosError: boolean = false, ) => { - const appContainerURI = await getAppContainerURL(appId, variantId, baseId) + const appContainerURI = await fetchAppContainerURL(appId, variantId, baseId) const url = `${appContainerURI}/openapi.json` const response = await axios.get(url, {_ignoreError: ignoreAxiosError} as any) const isChatVariant = detectChatVariantFromOpenAISchema(response.data) @@ -160,7 +167,7 @@ export const getVariantParametersFromOpenAPI = async ( * @returns {Promise} - Returns the URL path or an empty string * @throws {Error} - Throws an error if the request fails */ -export const getAppContainerURL = async ( +export const fetchAppContainerURL = async ( appId: string, variantId?: string, baseId?: string, @@ -188,7 +195,7 @@ export const getAppContainerURL = async ( /** * Saves a new variant to the database based on previous */ -export async function saveNewVariant( +export async function createNewVariant( baseId: string, newVariantName: string, newConfigName: string, @@ -212,23 +219,23 @@ export async function updateVariantParams(variantId: string, parameters: Paramet }) } -export async function removeApp(appId: string) { +export async function deleteApp(appId: string) { await axios.delete(`${getAgentaApiUrl()}/api/apps/${appId}/`, { data: {app_id: appId}, }) } -export async function removeVariant(variantId: string) { +export async function deleteSingleVariant(variantId: string) { await axios.delete(`${getAgentaApiUrl()}/api/variants/${variantId}/`) } -export const getProfile = async (ignoreAxiosError: boolean = false) => { +export const fetchProfile = async (ignoreAxiosError: boolean = false) => { return axios.get(`${getAgentaApiUrl()}/api/profile/`, { _ignoreError: ignoreAxiosError, } as any) } -export const getTemplates = async () => { +export const fetchAllTemplates = async () => { const response = await axios.get(`${getAgentaApiUrl()}/api/containers/templates/`) return response.data } @@ -265,7 +272,7 @@ export const waitForAppToStart = async ({ if (_variant) { const {stopper, promise} = shortPoll( () => - getVariantParametersFromOpenAPI( + fetchVariantParametersFromOpenAPI( appId, _variant.variantId, _variant.baseId, diff --git a/agenta-web/src/services/deployment/index.ts b/agenta-web/src/services/deployment/index.ts index d9f4b35376..5a1f94b98e 100644 --- a/agenta-web/src/services/deployment/index.ts +++ b/agenta-web/src/services/deployment/index.ts @@ -2,6 +2,13 @@ import {Environment} from "@/lib/Types" import axios from "@/lib/helpers/axiosConfig" import {getAgentaApiUrl} from "@/lib/helpers/utils" +//Prefix convention: +// - fetch: GET single entity from server +// - fetchAll: GET all entities from server +// - create: POST data to server +// - update: PUT data to server +// - delete: DELETE data from server + export const fetchEnvironments = async (appId: string): Promise => { const response = await fetch(`${getAgentaApiUrl()}/api/apps/${appId}/environments/`) @@ -13,7 +20,7 @@ export const fetchEnvironments = async (appId: string): Promise = return data } -export const publishVariant = async (variantId: string, environmentName: string) => { +export const createPublishVariant = async (variantId: string, environmentName: string) => { await axios.post(`${getAgentaApiUrl()}/api/environments/deploy/`, { environment_name: environmentName, variant_id: variantId, diff --git a/agenta-web/src/services/evaluations/index.ts b/agenta-web/src/services/evaluations/index.ts index afe62ba70c..8ec48a3106 100644 --- a/agenta-web/src/services/evaluations/index.ts +++ b/agenta-web/src/services/evaluations/index.ts @@ -21,7 +21,7 @@ import webhookImg from "@/media/link.png" import aiImg from "@/media/artificial-intelligence.png" import codeImg from "@/media/browser.png" import bracketCurlyImg from "@/media/bracket-curly.png" -import {loadTestset} from "@/services/testsets" +import {fetchTestset} from "@/services/testsets" import {calcEvalDuration} from "@/lib/helpers/evaluate" //Prefix convention: @@ -210,7 +210,7 @@ export const updateAnnotationScenario = async ( // Comparison export const fetchAllComparisonResults = async (evaluationIds: string[]) => { const scenarioGroups = await Promise.all(evaluationIds.map(fetchAllEvaluationScenarios)) - const testset: TestSet = await loadTestset(scenarioGroups[0][0].evaluation?.testset?.id) + const testset: TestSet = await fetchTestset(scenarioGroups[0][0].evaluation?.testset?.id) const inputsNameSet = new Set() scenarioGroups.forEach((group) => { diff --git a/agenta-web/src/services/human-evaluations/index.ts b/agenta-web/src/services/human-evaluations/index.ts index d361797ede..a5c98a6be1 100644 --- a/agenta-web/src/services/human-evaluations/index.ts +++ b/agenta-web/src/services/human-evaluations/index.ts @@ -14,7 +14,14 @@ import { import {EvaluationFlow, EvaluationType} from "@/lib/enums" import {getAgentaApiUrl} from "@/lib/helpers/utils" -export const loadEvaluations = async (appId: string, ignoreAxiosError: boolean = false) => { +//Prefix convention: +// - fetch: GET single entity from server +// - fetchAll: GET all entities from server +// - create: POST data to server +// - update: PUT data to server +// - delete: DELETE data from server + +export const fetchAllLoadEvaluations = async (appId: string, ignoreAxiosError: boolean = false) => { const response = await axios.get( `${getAgentaApiUrl()}/api/human-evaluations/?app_id=${appId}`, { @@ -24,7 +31,7 @@ export const loadEvaluations = async (appId: string, ignoreAxiosError: boolean = return response.data } -export const loadEvaluation = async (evaluationId: string) => { +export const fetchLoadEvaluation = async (evaluationId: string) => { return await axios .get(`${getAgentaApiUrl()}/api/human-evaluations/${evaluationId}/`) .then((responseData) => { @@ -41,7 +48,7 @@ export const deleteEvaluations = async (ids: string[]) => { return response.data } -export const loadEvaluationsScenarios = async ( +export const fetchAllLoadEvaluationsScenarios = async ( evaluationTableId: string, evaluation: Evaluation, ) => { @@ -121,7 +128,7 @@ export const updateEvaluationScenario = async ( return response.data } -export const postEvaluationScenario = async (evaluationTableId: string, data: GenericObject) => { +export const createEvaluationScenario = async (evaluationTableId: string, data: GenericObject) => { const response = await axios.post( `${getAgentaApiUrl()}/api/human-evaluations/${evaluationTableId}/evaluation_scenario/`, data, @@ -129,7 +136,7 @@ export const postEvaluationScenario = async (evaluationTableId: string, data: Ge return response.data } -export const evaluateAICritiqueForEvalScenario = async ( +export const createEvaluateAICritiqueForEvalScenario = async ( data: AICritiqueCreate, ignoreAxiosError: boolean = false, ) => { @@ -161,7 +168,7 @@ export const fetchEvaluationScenarioResults = async (evaluation_scenario_id: str return response } -export const saveCustomCodeEvaluation = async ( +export const createCustomCodeEvaluation = async ( payload: CreateCustomEvaluation, ignoreAxiosError: boolean = false, ) => { @@ -173,7 +180,7 @@ export const saveCustomCodeEvaluation = async ( return response } -export const editCustomEvaluationDetail = async ( +export const updateCustomEvaluationDetail = async ( id: string, payload: CreateCustomEvaluation, ignoreAxiosError: boolean = false, @@ -216,7 +223,7 @@ export const fetchCustomEvaluationNames = async ( return response } -export const executeCustomEvaluationCode = async ( +export const createExecuteCustomEvaluationCode = async ( payload: ExecuteCustomEvalCode, ignoreAxiosError: boolean = false, ) => { diff --git a/agenta-web/src/services/testsets/index.ts b/agenta-web/src/services/testsets/index.ts index 2848db8d75..b4806ccc1f 100644 --- a/agenta-web/src/services/testsets/index.ts +++ b/agenta-web/src/services/testsets/index.ts @@ -3,6 +3,13 @@ import axios from "@/lib/helpers/axiosConfig" import {getAgentaApiUrl} from "@/lib/helpers/utils" import {axiosFetcher} from "@/services/api" +//Prefix convention: +// - fetch: GET single entity from server +// - fetchAll: GET all entities from server +// - create: POST data to server +// - update: PUT data to server +// - delete: DELETE data from server + export const useLoadTestsetsList = (appId: string) => { const {data, error, mutate, isLoading} = useSWR( `${getAgentaApiUrl()}/api/testsets/?app_id=${appId}`, @@ -39,7 +46,7 @@ export async function updateTestset(testsetId: String, testsetName: string, test return response } -export const loadTestset = async (testsetId: string | null) => { +export const fetchTestset = async (testsetId: string | null) => { if (!testsetId) { return { id: undefined,