Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use frontend host as backend host per default #970

Merged
merged 8 commits into from
Dec 5, 2023
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
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
Loading