Skip to content

Commit

Permalink
Merge pull request #970 from Agenta-AI/issue-957/-use-FE-host-as-BE-host
Browse files Browse the repository at this point in the history
 Use frontend host as backend host per default
  • Loading branch information
aakrem authored Dec 5, 2023
2 parents 68b7fa9 + 4c8dec9 commit e71d07b
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 103 deletions.
4 changes: 2 additions & 2 deletions agenta-web/src/components/Evaluations/Evaluations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
useLoadTestsetsList,
fetchCustomEvaluations,
} from "@/lib/services/api"
import {dynamicComponent, getApikeys, isDemo} from "@/lib/helpers/utils"
import {dynamicComponent, getAgentaApiUrl, getApikeys, isDemo} from "@/lib/helpers/utils"
import {useRouter} from "next/router"
import {Variant, Parameter, GenericObject, SingleCustomEvaluation} from "@/lib/Types"
import {EvaluationType} from "@/lib/enums"
Expand Down Expand Up @@ -357,7 +357,7 @@ export default function Evaluations() {
evaluationTypeSettings.regex_pattern = ""
evaluationTypeSettings.regex_should_match = true
} else if (selectedEvaluationType === EvaluationType.auto_webhook_test) {
evaluationTypeSettings.webhook_url = `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/evaluations/webhook_example_fake`
evaluationTypeSettings.webhook_url = `${getAgentaApiUrl()}/api/evaluations/webhook_example_fake`
}

const evaluationTableId = await createNewEvaluation({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {createUseStyles} from "react-jss"
import {formatDate} from "@/lib/helpers/dateTimeHelper"
import {useAppTheme} from "../Layout/ThemeContextProvider"
import {getVotesPercentage} from "@/lib/helpers/evaluate"
import {EvaluationTypeLabels, isDemo} from "@/lib/helpers/utils"
import {EvaluationTypeLabels, getAgentaApiUrl, isDemo} from "@/lib/helpers/utils"

interface VariantVotesData {
number_of_votes: number
Expand Down Expand Up @@ -98,13 +98,11 @@ export default function HumanEvaluationResult() {
}
const fetchEvaluations = async () => {
try {
fetchData(
`${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/evaluations/?app_id=${app_id}`,
)
fetchData(`${getAgentaApiUrl()}/api/evaluations/?app_id=${app_id}`)
.then((response) => {
const fetchPromises = response.map((item: EvaluationResponseType) => {
return fetchData(
`${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/evaluations/${item.id}/results/`,
`${getAgentaApiUrl()}/api/evaluations/${item.id}/results/`,
)
.then((results) => {
if (item.evaluation_type === EvaluationType.human_a_b_testing) {
Expand Down
10 changes: 10 additions & 0 deletions agenta-web/src/lib/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,13 @@ export const safeParse = (str: string, fallback: any = "") => {
return fallback
}
}

export const getAgentaApiUrl = () => {
const apiUrl = process.env.NEXT_PUBLIC_AGENTA_API_URL

if (!apiUrl && typeof window !== "undefined") {
return `${window.location.protocol}//${window.location.hostname}`
}

return apiUrl
}
Loading

0 comments on commit e71d07b

Please sign in to comment.