Skip to content

Commit

Permalink
refactor: modify apis variable to ensure consistent naming convention
Browse files Browse the repository at this point in the history
  • Loading branch information
bekossy committed May 14, 2024
1 parent ccbdcd2 commit a6ce210
Show file tree
Hide file tree
Showing 21 changed files with 98 additions and 65 deletions.
4 changes: 2 additions & 2 deletions agenta-web/src/components/AppSelector/AppCard.tsx
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 9 additions & 4 deletions agenta-web/src/components/AppSelector/AppSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -184,7 +184,7 @@ const AddToTestSetDrawer: React.FC<Props> = ({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(
Expand Down
4 changes: 2 additions & 2 deletions agenta-web/src/components/Playground/LoadTestsModal.tsx
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -38,7 +38,7 @@ const LoadTestsModal: React.FC<Props> = (props) => {
}))

const handleClick = (shouldReplace: boolean) => {
loadTestset(selectedSet).then((data) => {
fetchTestset(selectedSet).then((data) => {
onLoad(data.csvdata, shouldReplace)
})
setIsOpen(false)
Expand Down
4 changes: 2 additions & 2 deletions agenta-web/src/components/Playground/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -79,7 +79,7 @@ const Playground: React.FC = () => {
}

try {
await saveNewVariant(
await createNewVariant(
newVariant.baseId!,
newVariant.variantName!,
newVariant.configName!,
Expand Down
8 changes: 4 additions & 4 deletions agenta-web/src/components/Playground/ViewNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -125,7 +125,7 @@ const ViewNavigation: React.FC<Props> = ({
}

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) {
Expand Down Expand Up @@ -210,7 +210,7 @@ const ViewNavigation: React.FC<Props> = ({
type="primary"
danger
onClick={() => {
deleteVariant(() => removeVariant(variant.variantId))
deleteVariant(() => deleteSingleVariant(variant.variantId))
}}
>
<Tooltip placement="bottom" title="Delete the variant permanently">
Expand Down
4 changes: 2 additions & 2 deletions agenta-web/src/components/Playground/Views/ParametersView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -134,7 +134,7 @@ const ParametersView: React.FC<Props> = ({
const handleDelete = () => {
deleteVariant(() => {
if (variant.persistent) {
return removeVariant(variant.variantId).then(() => {
return deleteSingleVariant(variant.variantId).then(() => {
onStateChange(false)
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -54,7 +54,7 @@ const PublishVariantModal: React.FC<Props> = ({

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}`)
Expand Down
4 changes: 2 additions & 2 deletions agenta-web/src/components/TestSetTable/TestsetTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -208,7 +208,7 @@ const TestsetTable: React.FC<testsetTableProps> = ({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(
Expand Down
4 changes: 2 additions & 2 deletions agenta-web/src/contexts/profile.context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -36,7 +36,7 @@ const ProfileContextProvider: React.FC<PropsWithChildren> = ({children}) => {

const fetcher = useCallback((onSuccess?: () => void) => {
setLoading(true)
getProfile()
fetchProfile()
.then((profile) => {
posthog.identify()
setUser(profile.data, onSuccess)
Expand Down
4 changes: 2 additions & 2 deletions agenta-web/src/lib/helpers/variantHelper.ts
Original file line number Diff line number Diff line change
@@ -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) => ({
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions agenta-web/src/lib/hooks/useVariant.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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)
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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)
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions agenta-web/src/pages/apps/[app_id]/endpoints/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -51,7 +51,7 @@ export default function VariantEndpoint() {
const [uri, setURI] = useState<string | null>(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`)
}
}
Expand Down
Loading

0 comments on commit a6ce210

Please sign in to comment.