From 6540d4a546a3db5c54fc59fd59195ce4c85e5134 Mon Sep 17 00:00:00 2001 From: Kaosiso Ezealigo Date: Wed, 29 Nov 2023 10:31:38 +0100 Subject: [PATCH 01/22] chore: conditional to check if env var is undefined --- agenta-web/src/lib/helpers/utils.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/agenta-web/src/lib/helpers/utils.ts b/agenta-web/src/lib/helpers/utils.ts index 25442d9d20..aa206fff89 100644 --- a/agenta-web/src/lib/helpers/utils.ts +++ b/agenta-web/src/lib/helpers/utils.ts @@ -228,3 +228,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 +} From e935d8561bb896ca9aaeeae81058f9ee29cdd395 Mon Sep 17 00:00:00 2001 From: Kaosiso Ezealigo Date: Wed, 29 Nov 2023 10:31:49 +0100 Subject: [PATCH 02/22] modifies url --- .../components/Evaluations/Evaluations.tsx | 4 +- .../Evaluations/HumanEvaluationResult.tsx | 8 +- agenta-web/src/lib/services/api.ts | 134 +++++++----------- .../apps/[app_id]/testsets/new/api/index.tsx | 5 +- .../[app_id]/testsets/new/endpoint/index.tsx | 9 +- .../[app_id]/testsets/new/upload/index.tsx | 13 +- 6 files changed, 72 insertions(+), 101 deletions(-) diff --git a/agenta-web/src/components/Evaluations/Evaluations.tsx b/agenta-web/src/components/Evaluations/Evaluations.tsx index ac7388d137..65a10bdac9 100644 --- a/agenta-web/src/components/Evaluations/Evaluations.tsx +++ b/agenta-web/src/components/Evaluations/Evaluations.tsx @@ -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" @@ -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({ diff --git a/agenta-web/src/components/Evaluations/HumanEvaluationResult.tsx b/agenta-web/src/components/Evaluations/HumanEvaluationResult.tsx index 8cf74202de..68f6fcc625 100644 --- a/agenta-web/src/components/Evaluations/HumanEvaluationResult.tsx +++ b/agenta-web/src/components/Evaluations/HumanEvaluationResult.tsx @@ -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 @@ -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) { diff --git a/agenta-web/src/lib/services/api.ts b/agenta-web/src/lib/services/api.ts index cd9c11c070..781d6c3e32 100644 --- a/agenta-web/src/lib/services/api.ts +++ b/agenta-web/src/lib/services/api.ts @@ -24,7 +24,7 @@ import { fromEvaluationScenarioResponseToEvaluationScenario, } from "../transformers" import {EvaluationFlow, EvaluationType} from "../enums" -import {delay, removeKeys} from "../helpers/utils" +import {delay, getAgentaApiUrl, removeKeys} from "../helpers/utils" import {useProfileData} from "@/contexts/profile.context" /** * Raw interface for the parameters parsed from the openapi.json @@ -36,10 +36,9 @@ export async function fetchVariants( appId: string, ignoreAxiosError: boolean = false, ): Promise { - const response = await axios.get( - `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/apps/${appId}/variants/`, - {_ignoreError: ignoreAxiosError} as any, - ) + const response = await axios.get(`${getAgentaApiUrl()}/api/apps/${appId}/variants/`, { + _ignoreError: ignoreAxiosError, + } as any) if (response.data && Array.isArray(response.data) && response.data.length > 0) { return response.data.map((variant: Record) => { @@ -63,10 +62,9 @@ export async function fetchVariants( } export function restartAppVariantContainer(variantId: string) { - return axios.post( - `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/containers/restart_container/`, - {variant_id: variantId}, - ) + return axios.post(`${getAgentaApiUrl()}/api/containers/restart_container/`, { + variant_id: variantId, + }) } /** @@ -188,7 +186,7 @@ export const getAppContainerURL = async ( ): Promise => { try { // Null-check for the environment variable - if (!process.env.NEXT_PUBLIC_AGENTA_API_URL) { + if (!getAgentaApiUrl()) { throw new Error("Environment variable NEXT_PUBLIC_AGENTA_API_URL is not set.") } @@ -202,7 +200,7 @@ export const getAppContainerURL = async ( } // Retrieve container URL from backend - const url = `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/containers/container_url/` + const url = `${getAgentaApiUrl()}/api/containers/container_url/` const response = await axios.get(url, {params: {variant_id: variantId, base_id: baseId}}) if (response.status === 200 && response.data && response.data.uri) { // Cache the URL before returning @@ -226,7 +224,7 @@ export async function saveNewVariant( newConfigName: string, parameters: Parameter[], ) { - await axios.post(`${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/variants/from-base/`, { + await axios.post(`${getAgentaApiUrl()}/api/variants/from-base/`, { base_id: baseId, new_variant_name: newVariantName, new_config_name: newConfigName, @@ -237,24 +235,21 @@ export async function saveNewVariant( } export async function updateVariantParams(variantId: string, parameters: Parameter[]) { - await axios.put( - `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/variants/${variantId}/parameters/`, - { - parameters: parameters.reduce((acc, param) => { - return {...acc, [param.name]: param.default} - }, {}), - }, - ) + await axios.put(`${getAgentaApiUrl()}/api/variants/${variantId}/parameters/`, { + parameters: parameters.reduce((acc, param) => { + return {...acc, [param.name]: param.default} + }, {}), + }) } export async function removeApp(appId: string) { - await axios.delete(`${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/apps/${appId}/`, { + await axios.delete(`${getAgentaApiUrl()}/api/apps/${appId}/`, { data: {app_id: appId}, }) } export async function removeVariant(variantId: string) { - await axios.delete(`${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/variants/${variantId}/`) + await axios.delete(`${getAgentaApiUrl()}/api/variants/${variantId}/`) } /** @@ -263,7 +258,7 @@ export async function removeVariant(variantId: string) { */ export const useLoadTestsetsList = (appId: string) => { const {data, error, mutate, isLoading} = useSWR( - `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/testsets/?app_id=${appId}`, + `${getAgentaApiUrl()}/api/testsets/?app_id=${appId}`, fetcher, {revalidateOnFocus: false}, ) @@ -277,38 +272,30 @@ export const useLoadTestsetsList = (appId: string) => { } export async function createNewTestset(appId: string, testsetName: string, testsetData: any) { - const response = await axios.post( - `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/testsets/${appId}/`, - { - name: testsetName, - csvdata: testsetData, - }, - ) + const response = await axios.post(`${getAgentaApiUrl()}/api/testsets/${appId}/`, { + name: testsetName, + csvdata: testsetData, + }) return response } export async function updateTestset(testsetId: String, testsetName: string, testsetData: any) { - const response = await axios.put( - `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/testsets/${testsetId}/`, - { - name: testsetName, - csvdata: testsetData, - }, - ) + const response = await axios.put(`${getAgentaApiUrl()}/api/testsets/${testsetId}/`, { + name: testsetName, + csvdata: testsetData, + }) return response } export const loadTestset = async (testsetId: string) => { - const response = await axios.get( - `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/testsets/${testsetId}/`, - ) + const response = await axios.get(`${getAgentaApiUrl()}/api/testsets/${testsetId}/`) return response.data } export const deleteTestsets = async (ids: string[]) => { const response = await axios({ method: "delete", - url: `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/testsets/`, + url: `${getAgentaApiUrl()}/api/testsets/`, data: {testset_ids: ids}, }) return response.data @@ -316,7 +303,7 @@ export const deleteTestsets = async (ids: string[]) => { export const loadEvaluations = async (appId: string) => { return await axios - .get(`${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/evaluations/?app_id=${appId}`) + .get(`${getAgentaApiUrl()}/api/evaluations/?app_id=${appId}`) .then((responseData) => { const evaluations = responseData.data.map((item: EvaluationResponseType) => { return fromEvaluationResponseToEvaluation(item) @@ -328,7 +315,7 @@ export const loadEvaluations = async (appId: string) => { export const loadEvaluation = async (evaluationId: string) => { return await axios - .get(`${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/evaluations/${evaluationId}/`) + .get(`${getAgentaApiUrl()}/api/evaluations/${evaluationId}/`) .then((responseData) => { return fromEvaluationResponseToEvaluation(responseData.data) }) @@ -337,7 +324,7 @@ export const loadEvaluation = async (evaluationId: string) => { export const deleteEvaluations = async (ids: string[]) => { const response = await axios({ method: "delete", - url: `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/evaluations/`, + url: `${getAgentaApiUrl()}/api/evaluations/`, data: {evaluations_ids: ids}, }) return response.data @@ -348,9 +335,7 @@ export const loadEvaluationsScenarios = async ( evaluation: Evaluation, ) => { return await axios - .get( - `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/evaluations/${evaluationTableId}/evaluation_scenarios/`, - ) + .get(`${getAgentaApiUrl()}/api/evaluations/${evaluationTableId}/evaluation_scenarios/`) .then((responseData) => { const evaluationsRows = responseData.data.map((item: any) => { return fromEvaluationScenarioResponseToEvaluationScenario(item, evaluation) @@ -396,19 +381,14 @@ export const createNewEvaluation = async ( status: EvaluationFlow.EVALUATION_INITIALIZED, } - const response = await axios.post( - `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/evaluations/`, - data, - {_ignoreError: ignoreAxiosError} as any, - ) + const response = await axios.post(`${getAgentaApiUrl()}/api/evaluations/`, data, { + _ignoreError: ignoreAxiosError, + } as any) return response.data.id } export const updateEvaluation = async (evaluationId: string, data: GenericObject) => { - const response = await axios.put( - `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/evaluations/${evaluationId}/`, - data, - ) + const response = await axios.put(`${getAgentaApiUrl()}/api/evaluations/${evaluationId}/`, data) return response.data } @@ -419,7 +399,7 @@ export const updateEvaluationScenario = async ( evaluationType: EvaluationType, ) => { const response = await axios.put( - `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/evaluations/${evaluationTableId}/evaluation_scenario/${evaluationScenarioId}/${evaluationType}/`, + `${getAgentaApiUrl()}/api/evaluations/${evaluationTableId}/evaluation_scenario/${evaluationScenarioId}/${evaluationType}/`, data, ) return response.data @@ -427,7 +407,7 @@ export const updateEvaluationScenario = async ( export const postEvaluationScenario = async (evaluationTableId: string, data: GenericObject) => { const response = await axios.post( - `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/evaluations/${evaluationTableId}/evaluation_scenario/`, + `${getAgentaApiUrl()}/api/evaluations/${evaluationTableId}/evaluation_scenario/`, data, ) return response.data @@ -438,7 +418,7 @@ export const evaluateAICritiqueForEvalScenario = async ( ignoreAxiosError: boolean = false, ) => { const response = await axios.post( - `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/evaluations/evaluation_scenario/ai_critique/`, + `${getAgentaApiUrl()}/api/evaluations/evaluation_scenario/ai_critique/`, data, {_ignoreError: ignoreAxiosError} as any, ) @@ -447,14 +427,14 @@ export const evaluateAICritiqueForEvalScenario = async ( export const fetchEvaluationResults = async (evaluationId: string) => { const response = await axios.get( - `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/evaluations/${evaluationId}/results/`, + `${getAgentaApiUrl()}/api/evaluations/${evaluationId}/results/`, ) return response.data } export const fetchEvaluationScenarioResults = async (evaluation_scenario_id: string) => { const response = await axios.get( - `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/evaluations/evaluation_scenario/${evaluation_scenario_id}/score/`, + `${getAgentaApiUrl()}/api/evaluations/evaluation_scenario/${evaluation_scenario_id}/score/`, ) return response } @@ -464,7 +444,7 @@ export const saveCustomCodeEvaluation = async ( ignoreAxiosError: boolean = false, ) => { const response = await axios.post( - `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/evaluations/custom_evaluation/`, + `${getAgentaApiUrl()}/api/evaluations/custom_evaluation/`, payload, {_ignoreError: ignoreAxiosError} as any, ) @@ -477,7 +457,7 @@ export const editCustomEvaluationDetail = async ( ignoreAxiosError: boolean = false, ) => { const response = await axios.put( - `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/evaluations/custom_evaluation/${id}`, + `${getAgentaApiUrl()}/api/evaluations/custom_evaluation/${id}`, payload, {_ignoreError: ignoreAxiosError} as any, ) @@ -486,7 +466,7 @@ export const editCustomEvaluationDetail = async ( export const fetchCustomEvaluations = async (app_id: string, ignoreAxiosError: boolean = false) => { const response = await axios.get( - `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/evaluations/custom_evaluation/list/${app_id}/`, + `${getAgentaApiUrl()}/api/evaluations/custom_evaluation/list/${app_id}/`, {_ignoreError: ignoreAxiosError} as any, ) return response @@ -497,7 +477,7 @@ export const fetchCustomEvaluationDetail = async ( ignoreAxiosError: boolean = false, ) => { const response = await axios.get( - `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/evaluations/custom_evaluation/${id}/`, + `${getAgentaApiUrl()}/api/evaluations/custom_evaluation/${id}/`, {_ignoreError: ignoreAxiosError} as any, ) return response.data @@ -508,7 +488,7 @@ export const fetchCustomEvaluationNames = async ( ignoreAxiosError: boolean = false, ) => { const response = await axios.get( - `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/evaluations/custom_evaluation/${app_id}/names/`, + `${getAgentaApiUrl()}/api/evaluations/custom_evaluation/${app_id}/names/`, {_ignoreError: ignoreAxiosError} as any, ) return response @@ -519,7 +499,7 @@ export const executeCustomEvaluationCode = async ( ignoreAxiosError: boolean = false, ) => { const response = await axios.post( - `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/evaluations/custom_evaluation/execute/${payload.evaluation_id}/`, + `${getAgentaApiUrl()}/api/evaluations/custom_evaluation/execute/${payload.evaluation_id}/`, payload, {_ignoreError: ignoreAxiosError} as any, ) @@ -532,7 +512,7 @@ export const updateEvaluationScenarioScore = async ( ignoreAxiosError: boolean = false, ) => { const response = await axios.put( - `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/evaluations/evaluation_scenario/${evaluation_scenario_id}/score/`, + `${getAgentaApiUrl()}/api/evaluations/evaluation_scenario/${evaluation_scenario_id}/score/`, {score}, {_ignoreError: ignoreAxiosError} as any, ) @@ -542,7 +522,7 @@ export const updateEvaluationScenarioScore = async ( export const useApps = () => { const {selectedOrg} = useProfileData() const {data, error, isLoading, mutate} = useSWR( - `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/apps/?org_id=${selectedOrg?.id}`, + `${getAgentaApiUrl()}/api/apps/?org_id=${selectedOrg?.id}`, selectedOrg?.id ? fetcher : () => {}, //doon't fetch if org is not selected ) @@ -555,21 +535,19 @@ export const useApps = () => { } export const getProfile = async (ignoreAxiosError: boolean = false) => { - return axios.get(`${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/profile/`, { + return axios.get(`${getAgentaApiUrl()}/api/profile/`, { _ignoreError: ignoreAxiosError, } as any) } export const getOrgsList = async (ignoreAxiosError: boolean = false) => { - return axios.get(`${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/organizations/`, { + return axios.get(`${getAgentaApiUrl()}/api/organizations/`, { _ignoreError: ignoreAxiosError, } as any) } export const getTemplates = async () => { - const response = await axios.get( - `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/containers/templates/`, - ) + const response = await axios.get(`${getAgentaApiUrl()}/api/containers/templates/`) return response.data } @@ -578,7 +556,7 @@ export const createAppFromTemplate = async ( ignoreAxiosError: boolean = false, ) => { const response = await axios.post( - `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/apps/app_and_variant_from_template/`, + `${getAgentaApiUrl()}/api/apps/app_and_variant_from_template/`, templateObj, {_ignoreError: ignoreAxiosError} as any, ) @@ -685,9 +663,7 @@ export const createAndStartTemplate = async ({ } export const fetchEnvironments = async (appId: string): Promise => { - const response = await fetch( - `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/apps/${appId}/environments/`, - ) + const response = await fetch(`${getAgentaApiUrl()}/api/apps/${appId}/environments/`) if (response.status !== 200) { throw new Error("Failed to fetch environments") @@ -698,7 +674,7 @@ export const fetchEnvironments = async (appId: string): Promise = } export const publishVariant = async (variantId: string, environmentName: string) => { - await axios.post(`${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/environments/deploy/`, { + await axios.post(`${getAgentaApiUrl()}/api/environments/deploy/`, { environment_name: environmentName, variant_id: variantId, }) diff --git a/agenta-web/src/pages/apps/[app_id]/testsets/new/api/index.tsx b/agenta-web/src/pages/apps/[app_id]/testsets/new/api/index.tsx index 2db038e753..43c03465b1 100644 --- a/agenta-web/src/pages/apps/[app_id]/testsets/new/api/index.tsx +++ b/agenta-web/src/pages/apps/[app_id]/testsets/new/api/index.tsx @@ -10,6 +10,7 @@ import tsCodeUpload from "../../../../../../code_snippets/testsets/create_with_u import {Typography} from "antd" import {useRouter} from "next/router" import {createUseStyles} from "react-jss" +import {getAgentaApiUrl} from "@/lib/helpers/utils" const useStyles = createUseStyles({ title: { @@ -22,8 +23,8 @@ export default function NewTestsetWithAPI() { const router = useRouter() const appId = router.query.app_id as string - const uploadURI = `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/testsets/upload` - const jsonURI = `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/testsets/${appId}` + const uploadURI = `${getAgentaApiUrl()}/api/testsets/upload` + const jsonURI = `${getAgentaApiUrl()}/api/testsets/${appId}` const params = `{ "name": "testset_name",}` diff --git a/agenta-web/src/pages/apps/[app_id]/testsets/new/endpoint/index.tsx b/agenta-web/src/pages/apps/[app_id]/testsets/new/endpoint/index.tsx index 887652e6e8..673706a4d6 100644 --- a/agenta-web/src/pages/apps/[app_id]/testsets/new/endpoint/index.tsx +++ b/agenta-web/src/pages/apps/[app_id]/testsets/new/endpoint/index.tsx @@ -1,4 +1,5 @@ import axios from "@/lib/helpers/axiosConfig" +import {getAgentaApiUrl} from "@/lib/helpers/utils" import {Alert, Button, Form, Input, Spin, Typography, message} from "antd" import {useRouter} from "next/router" import {useState} from "react" @@ -47,11 +48,9 @@ export default function ImportTestsetFromEndpoint() { try { // TODO: move to api.ts - await axios.post( - `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/testsets/endpoint/`, - formData, - {headers: {"Content-Type": "multipart/form-data"}}, - ) + await axios.post(`${getAgentaApiUrl()}/api/testsets/endpoint/`, formData, { + headers: {"Content-Type": "multipart/form-data"}, + }) router.push(`/apps/${appId}/testsets`) } catch (_) { // Errors will be handled by Axios interceptor diff --git a/agenta-web/src/pages/apps/[app_id]/testsets/new/upload/index.tsx b/agenta-web/src/pages/apps/[app_id]/testsets/new/upload/index.tsx index 4092746fe6..0b53090c67 100644 --- a/agenta-web/src/pages/apps/[app_id]/testsets/new/upload/index.tsx +++ b/agenta-web/src/pages/apps/[app_id]/testsets/new/upload/index.tsx @@ -4,6 +4,7 @@ import {useState} from "react" import axios from "@/lib/helpers/axiosConfig" import {useRouter} from "next/router" import {createUseStyles} from "react-jss" +import {getAgentaApiUrl} from "@/lib/helpers/utils" const useStyles = createUseStyles({ fileFormatBtn: { @@ -50,15 +51,11 @@ export default function AddANewTestset() { try { setUploadLoading(true) // TODO: move to api.ts - await axios.post( - `${process.env.NEXT_PUBLIC_AGENTA_API_URL}/api/testsets/upload/`, - formData, - { - headers: { - "Content-Type": "multipart/form-data", - }, + await axios.post(`${getAgentaApiUrl()}/api/testsets/upload/`, formData, { + headers: { + "Content-Type": "multipart/form-data", }, - ) + }) form.resetFields() router.push(`/apps/${appId}/testsets`) } finally { From 6c52941fd78b1b2a5745eaae1ab4e5244d3eb491 Mon Sep 17 00:00:00 2001 From: Abram Date: Wed, 29 Nov 2023 13:39:13 +0100 Subject: [PATCH 03/22] Feat - created vision_gpt_explain_image llm application --- examples/vision_gpt_explain_image/app.py | 56 +++++++++++++++++++ .../vision_gpt_explain_image/requirements.txt | 2 + 2 files changed, 58 insertions(+) create mode 100644 examples/vision_gpt_explain_image/app.py create mode 100644 examples/vision_gpt_explain_image/requirements.txt diff --git a/examples/vision_gpt_explain_image/app.py b/examples/vision_gpt_explain_image/app.py new file mode 100644 index 0000000000..1362087a4b --- /dev/null +++ b/examples/vision_gpt_explain_image/app.py @@ -0,0 +1,56 @@ +import agenta as ag +from openai import OpenAI +from typing import List, Dict + + +client = OpenAI() + +ag.init(app_name="explain_image", base_name="app") +ag.config.default( + model=ag.MultipleChoiceParam("gpt-4-vision-preview", []), + max_tokens=ag.IntParam(300, -1, 4000), +) + + +def replace_image_url( + messages: List[Dict[str, str]], image_one: str, image_two: str +) -> Dict[str, str]: + new_message = {} + for message in messages: + for key, value in message.items(): + if key == "content": + new_content = [] + for content in value: + if content["type"] == "image_url": + content["image_url"] = ( + image_two + if content["image_url"] == image_one + else image_one + ) + new_content.append(content) + new_message[key] = new_content + else: + new_message[key] = value + return new_message + + +@ag.entrypoint +def explain( + image_one: ag.FileInputURL, + image_two: ag.FileInputURL, + inputs: ag.DictInput = ag.DictInput(default_keys=["role"]), + messages: ag.MessagesInput = ag.MessagesInput( + [ + {"type": "text", "text": "What are in these image?"}, + ] + ), +) -> str: + messages = [inputs] + [{"content": messages}] + new_messages = replace_image_url(messages, image_one, image_two) + max_tokens = ag.config.max_tokens if ag.config.max_tokens != -1 else None + chat_completion = client.chat.completions.create( + model=ag.config.model, + messages=[new_messages], + max_tokens=max_tokens, + ) + return chat_completion.choices[0].message.content diff --git a/examples/vision_gpt_explain_image/requirements.txt b/examples/vision_gpt_explain_image/requirements.txt new file mode 100644 index 0000000000..310f162cec --- /dev/null +++ b/examples/vision_gpt_explain_image/requirements.txt @@ -0,0 +1,2 @@ +agenta +openai \ No newline at end of file From 325c6085134acc1ca3ba715dc806e9cc796450a0 Mon Sep 17 00:00:00 2001 From: Abram Date: Wed, 29 Nov 2023 13:54:15 +0100 Subject: [PATCH 04/22] Update - ensure attachment (images) are in a dict with the key 'url' --- examples/vision_gpt_explain_image/app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/vision_gpt_explain_image/app.py b/examples/vision_gpt_explain_image/app.py index 1362087a4b..0f739f375e 100644 --- a/examples/vision_gpt_explain_image/app.py +++ b/examples/vision_gpt_explain_image/app.py @@ -23,9 +23,9 @@ def replace_image_url( for content in value: if content["type"] == "image_url": content["image_url"] = ( - image_two + {"url": image_two} if content["image_url"] == image_one - else image_one + else {"url": image_one} ) new_content.append(content) new_message[key] = new_content From 930cf4eeb77e79118fd44544d35b99ac02136c0d Mon Sep 17 00:00:00 2001 From: Akrem Abayed Date: Thu, 30 Nov 2023 16:28:18 +0100 Subject: [PATCH 05/22] add on workflow dispatch to docker --- .github/workflows/docker.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 186f6e22cd..c366c4007d 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,6 +1,7 @@ name: Build and Publish Docker Images -on: +on: + workflow_dispatch: push: branches: - main @@ -33,7 +34,7 @@ jobs: registry: ghcr.io username: ${{ env.REPOSITORY_USERNAME }} password: ${{ secrets.DOCKER_GITHUB_SECRETS }} - + - name: Build, tag and push Backend image to Github Container Registry id: build-backend-image run: | From eec139f3515b9ee90aeaa03d92f6f8ad458d7e51 Mon Sep 17 00:00:00 2001 From: Akrem Abayed Date: Thu, 30 Nov 2023 16:33:39 +0100 Subject: [PATCH 06/22] put back original file --- .github/workflows/docker.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index c366c4007d..186f6e22cd 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,7 +1,6 @@ name: Build and Publish Docker Images -on: - workflow_dispatch: +on: push: branches: - main @@ -34,7 +33,7 @@ jobs: registry: ghcr.io username: ${{ env.REPOSITORY_USERNAME }} password: ${{ secrets.DOCKER_GITHUB_SECRETS }} - + - name: Build, tag and push Backend image to Github Container Registry id: build-backend-image run: | From 9d1a1163cfe410ede5f80248c182d6f7d2916828 Mon Sep 17 00:00:00 2001 From: Abram Date: Fri, 1 Dec 2023 08:58:00 +0100 Subject: [PATCH 07/22] Update - modified vision_gpt llm app --- examples/vision_gpt_explain_image/app.py | 65 +++++++++++------------- 1 file changed, 30 insertions(+), 35 deletions(-) diff --git a/examples/vision_gpt_explain_image/app.py b/examples/vision_gpt_explain_image/app.py index 0f739f375e..9cbeaf4f08 100644 --- a/examples/vision_gpt_explain_image/app.py +++ b/examples/vision_gpt_explain_image/app.py @@ -1,56 +1,51 @@ import agenta as ag from openai import OpenAI -from typing import List, Dict client = OpenAI() + +SYSTEM_PROMPT = "You are an expert in reading images you look into details, you answer in accurate language." +HUMAN_PROMPT = "Please compare two images" + ag.init(app_name="explain_image", base_name="app") ag.config.default( - model=ag.MultipleChoiceParam("gpt-4-vision-preview", []), - max_tokens=ag.IntParam(300, -1, 4000), + temperature=ag.FloatParam(0.5, 0, 1), + max_tokens=ag.IntParam(300, 1, 4000), + prompt_system=ag.TextParam(SYSTEM_PROMPT), + prompt_human=ag.TextParam(HUMAN_PROMPT), ) -def replace_image_url( - messages: List[Dict[str, str]], image_one: str, image_two: str -) -> Dict[str, str]: - new_message = {} - for message in messages: - for key, value in message.items(): - if key == "content": - new_content = [] - for content in value: - if content["type"] == "image_url": - content["image_url"] = ( - {"url": image_two} - if content["image_url"] == image_one - else {"url": image_one} - ) - new_content.append(content) - new_message[key] = new_content - else: - new_message[key] = value - return new_message - - @ag.entrypoint def explain( image_one: ag.FileInputURL, image_two: ag.FileInputURL, - inputs: ag.DictInput = ag.DictInput(default_keys=["role"]), - messages: ag.MessagesInput = ag.MessagesInput( - [ - {"type": "text", "text": "What are in these image?"}, - ] - ), ) -> str: - messages = [inputs] + [{"content": messages}] - new_messages = replace_image_url(messages, image_one, image_two) + messages = [{"role": "system", "content": ag.config.prompt_system}] + [ + { + "role": "user", + "content": [ + {"type": "text", "text": ag.config.prompt_human}, + { + "type": "image_url", + "image_url": { + "url": image_one, + }, + }, + { + "type": "image_url", + "image_url": { + "url": image_two, + }, + }, + ], + } + ] max_tokens = ag.config.max_tokens if ag.config.max_tokens != -1 else None chat_completion = client.chat.completions.create( - model=ag.config.model, - messages=[new_messages], + model="gpt-4-vision-preview", + messages=messages, max_tokens=max_tokens, ) return chat_completion.choices[0].message.content From 521d2e81fbb9c7e0f3b259f12bcccff05b33c471 Mon Sep 17 00:00:00 2001 From: Abram Date: Fri, 1 Dec 2023 09:01:00 +0100 Subject: [PATCH 08/22] Cleanup - remove conditional use of max_tokens in explain function --- examples/vision_gpt_explain_image/app.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/vision_gpt_explain_image/app.py b/examples/vision_gpt_explain_image/app.py index 9cbeaf4f08..b14901e396 100644 --- a/examples/vision_gpt_explain_image/app.py +++ b/examples/vision_gpt_explain_image/app.py @@ -42,7 +42,6 @@ def explain( ], } ] - max_tokens = ag.config.max_tokens if ag.config.max_tokens != -1 else None chat_completion = client.chat.completions.create( model="gpt-4-vision-preview", messages=messages, From 8a44fdcc21bddc1702ef14f17cab8ca6e76dcd88 Mon Sep 17 00:00:00 2001 From: Abram Date: Fri, 1 Dec 2023 09:11:19 +0100 Subject: [PATCH 09/22] :art: Format - ran format-fix and black --- .../components/AppSelector/modals/CreateAppStatusModal.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agenta-web/src/components/AppSelector/modals/CreateAppStatusModal.tsx b/agenta-web/src/components/AppSelector/modals/CreateAppStatusModal.tsx index 3a7d655407..cb165d4b04 100644 --- a/agenta-web/src/components/AppSelector/modals/CreateAppStatusModal.tsx +++ b/agenta-web/src/components/AppSelector/modals/CreateAppStatusModal.tsx @@ -196,8 +196,8 @@ const CreateAppStatusModal: React.FC> type === "success" ? "success" : type === "error" - ? "danger" - : "secondary" + ? "danger" + : "secondary" } strong={Object.keys(messages)[ix] === "success"} > From e7e9b2d1633e72d8c76d2d3bda744e07b00b7c82 Mon Sep 17 00:00:00 2001 From: Abram Date: Fri, 1 Dec 2023 12:24:56 +0100 Subject: [PATCH 10/22] Update - remove params from ag.init --- examples/vision_gpt_explain_image/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/vision_gpt_explain_image/app.py b/examples/vision_gpt_explain_image/app.py index b14901e396..d77ea99bca 100644 --- a/examples/vision_gpt_explain_image/app.py +++ b/examples/vision_gpt_explain_image/app.py @@ -8,7 +8,7 @@ SYSTEM_PROMPT = "You are an expert in reading images you look into details, you answer in accurate language." HUMAN_PROMPT = "Please compare two images" -ag.init(app_name="explain_image", base_name="app") +ag.init() ag.config.default( temperature=ag.FloatParam(0.5, 0, 1), max_tokens=ag.IntParam(300, 1, 4000), From 8471a045195584ae5f3e1190882d20235f78c98c Mon Sep 17 00:00:00 2001 From: Kaosiso Ezealigo Date: Fri, 1 Dec 2023 20:01:53 +0100 Subject: [PATCH 11/22] format fix --- .../components/AppSelector/modals/CreateAppStatusModal.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agenta-web/src/components/AppSelector/modals/CreateAppStatusModal.tsx b/agenta-web/src/components/AppSelector/modals/CreateAppStatusModal.tsx index cb165d4b04..3a7d655407 100644 --- a/agenta-web/src/components/AppSelector/modals/CreateAppStatusModal.tsx +++ b/agenta-web/src/components/AppSelector/modals/CreateAppStatusModal.tsx @@ -196,8 +196,8 @@ const CreateAppStatusModal: React.FC> type === "success" ? "success" : type === "error" - ? "danger" - : "secondary" + ? "danger" + : "secondary" } strong={Object.keys(messages)[ix] === "success"} > From 024427fe6acab056c22d987b9d4bdac1326d0b95 Mon Sep 17 00:00:00 2001 From: Akrem Abayed Date: Sun, 3 Dec 2023 16:40:49 +0100 Subject: [PATCH 12/22] fix env bug --- agenta-backend/agenta_backend/routers/app_router.py | 4 ++-- agenta-backend/agenta_backend/services/app_manager.py | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/agenta-backend/agenta_backend/routers/app_router.py b/agenta-backend/agenta_backend/routers/app_router.py index fcada15d68..b687d2c305 100644 --- a/agenta-backend/agenta_backend/routers/app_router.py +++ b/agenta-backend/agenta_backend/routers/app_router.py @@ -362,10 +362,10 @@ async def create_app_and_variant_from_template( app=app, variant_name="app.default", docker_id_or_template_uri=template_db.template_uri - if os.environ["FEATURE_FLAG"] in ["cloud"] + if os.environ["FEATURE_FLAG"] in ["cloud", "ee"] else template_db.digest, tags=f"{image_name}" - if os.environ["FEATURE_FLAG"] not in ["cloud"] + if os.environ["FEATURE_FLAG"] not in ["cloud", "ee"] else None, base_name="app", config_name="default", diff --git a/agenta-backend/agenta_backend/services/app_manager.py b/agenta-backend/agenta_backend/services/app_manager.py index 3d5e338b6d..21caa5201d 100644 --- a/agenta-backend/agenta_backend/services/app_manager.py +++ b/agenta-backend/agenta_backend/services/app_manager.py @@ -86,6 +86,8 @@ async def start_variant( str(db_app_variant.user.uid), expiration_date=None, hidden=True ) env_vars.update({"AGENTA_API_KEY": api_key}) + print("start_variant ---- db_app_variant") + print(db_app_variant) deployment = await deployment_manager.start_service( app_variant_db=db_app_variant, env_vars=env_vars ) @@ -379,7 +381,7 @@ async def add_variant_based_on_image( ): raise ValueError("App variant or image is None") - if os.environ["FEATURE_FLAG"] not in ["cloud"]: + if os.environ["FEATURE_FLAG"] not in ["cloud", "ee"]: if tags in [None, ""]: raise ValueError("OSS: Tags is None") From d17285e4339b6eb1632e33fad772ebf367afb065 Mon Sep 17 00:00:00 2001 From: Akrem Abayed Date: Sun, 3 Dec 2023 16:59:12 +0100 Subject: [PATCH 13/22] remvoe prints --- agenta-backend/agenta_backend/services/app_manager.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/agenta-backend/agenta_backend/services/app_manager.py b/agenta-backend/agenta_backend/services/app_manager.py index 21caa5201d..2a27a2abb1 100644 --- a/agenta-backend/agenta_backend/services/app_manager.py +++ b/agenta-backend/agenta_backend/services/app_manager.py @@ -86,8 +86,6 @@ async def start_variant( str(db_app_variant.user.uid), expiration_date=None, hidden=True ) env_vars.update({"AGENTA_API_KEY": api_key}) - print("start_variant ---- db_app_variant") - print(db_app_variant) deployment = await deployment_manager.start_service( app_variant_db=db_app_variant, env_vars=env_vars ) From 9e5a35a3963655dce3067190619e3c9133019661 Mon Sep 17 00:00:00 2001 From: Mahmoud Mabrouk Date: Tue, 5 Dec 2023 10:15:21 +0100 Subject: [PATCH 14/22] same as https://github.com/Agenta-AI/agenta/pull/949/files --- agenta-cli/agenta/__init__.py | 1 + agenta-cli/agenta/sdk/__init__.py | 1 + agenta-cli/agenta/sdk/agenta_decorator.py | 8 ++++++++ agenta-cli/agenta/sdk/types.py | 8 +++++++- agenta-cli/pyproject.toml | 2 +- 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/agenta-cli/agenta/__init__.py b/agenta-cli/agenta/__init__.py index 8ab228be22..b73eb24d60 100644 --- a/agenta-cli/agenta/__init__.py +++ b/agenta-cli/agenta/__init__.py @@ -9,6 +9,7 @@ MultipleChoiceParam, MessagesInput, TextParam, + FileInputURL, ) from .sdk.utils.preinit import PreInitObject from .sdk.agenta_init import Config, init diff --git a/agenta-cli/agenta/sdk/__init__.py b/agenta-cli/agenta/sdk/__init__.py index 4b4cdc6fe9..b10b8c1e17 100644 --- a/agenta-cli/agenta/sdk/__init__.py +++ b/agenta-cli/agenta/sdk/__init__.py @@ -11,6 +11,7 @@ MultipleChoiceParam, TextParam, MessagesInput, + FileInputURL, ) from .agenta_init import Config, init diff --git a/agenta-cli/agenta/sdk/agenta_decorator.py b/agenta-cli/agenta/sdk/agenta_decorator.py index 3d61765d8c..e132b084a1 100644 --- a/agenta-cli/agenta/sdk/agenta_decorator.py +++ b/agenta-cli/agenta/sdk/agenta_decorator.py @@ -25,6 +25,7 @@ MultipleChoiceParam, TextParam, MessagesInput, + FileInputURL, ) app = FastAPI() @@ -314,6 +315,7 @@ def override_schema(openapi_schema: dict, func_name: str, endpoint: str, params: - The min and max values for each IntParam instance - The default value for DictInput instance - The default value for MessagesParam instance + - The default value for FileInputURL instance - ... [PLEASE ADD AT EACH CHANGE] Args: @@ -380,3 +382,9 @@ def find_in_schema(schema: dict, param_name: str, xparam: str): ): subschema = find_in_schema(schema_to_override, param_name, "messages") subschema["default"] = param_val.default + if ( + isinstance(param_val, inspect.Parameter) + and param_val.annotation is FileInputURL + ): + subschema = find_in_schema(schema_to_override, param_name, "file_url") + subschema["default"] = "https://example.com" diff --git a/agenta-cli/agenta/sdk/types.py b/agenta-cli/agenta/sdk/types.py index 080eb9d8fd..8c22032bf8 100644 --- a/agenta-cli/agenta/sdk/types.py +++ b/agenta-cli/agenta/sdk/types.py @@ -1,7 +1,7 @@ import json from typing import Any, Dict, List -from pydantic import BaseModel, Extra +from pydantic import BaseModel, Extra, HttpUrl class InFile: @@ -125,6 +125,12 @@ def __modify_schema__(cls, field_schema: dict[str, Any]): field_schema.update({"x-parameter": "messages", "type": "array"}) +class FileInputURL(HttpUrl): + @classmethod + def __modify_schema__(cls, field_schema: Dict[str, Any]) -> None: + field_schema.update({"x-parameter": "file_url", "type": "string"}) + + class Context(BaseModel): class Config: extra = Extra.allow diff --git a/agenta-cli/pyproject.toml b/agenta-cli/pyproject.toml index 1b97d985bf..c956362390 100644 --- a/agenta-cli/pyproject.toml +++ b/agenta-cli/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "agenta" -version = "0.6.1" +version = "0.6.2" description = "The SDK for agenta is an open-source LLMOps platform." readme = "README.md" authors = ["Mahmoud Mabrouk "] From a3fcf464852d6e3b493172758683543a5206ae4c Mon Sep 17 00:00:00 2001 From: Kaosiso Ezealigo Date: Tue, 5 Dec 2023 11:13:23 +0100 Subject: [PATCH 15/22] exclude failing tests --- agenta-web/cypress.config.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/agenta-web/cypress.config.ts b/agenta-web/cypress.config.ts index 6824bd5527..264a79bf05 100644 --- a/agenta-web/cypress.config.ts +++ b/agenta-web/cypress.config.ts @@ -11,6 +11,7 @@ export default defineConfig({ baseUrl: "http://localhost", defaultCommandTimeout: 30000, requestTimeout: 10000, + specPattern: ["*/e2e/smoke-tests.cy.ts", "*/e2e/app-navigation.cy.ts"], }, env: { baseApiURL: "http://localhost/api", From 4c8dec97449a52f803d55e366b191c4d5c4241af Mon Sep 17 00:00:00 2001 From: Kaosiso Ezealigo Date: Tue, 5 Dec 2023 11:53:19 +0100 Subject: [PATCH 16/22] format fix --- .../apps/[app_id]/testsets/new/upload/index.tsx | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/agenta-web/src/pages/apps/[app_id]/testsets/new/upload/index.tsx b/agenta-web/src/pages/apps/[app_id]/testsets/new/upload/index.tsx index 3bde8435dc..29f7c47337 100644 --- a/agenta-web/src/pages/apps/[app_id]/testsets/new/upload/index.tsx +++ b/agenta-web/src/pages/apps/[app_id]/testsets/new/upload/index.tsx @@ -59,17 +59,13 @@ export default function AddANewTestset() { try { setUploadLoading(true) // TODO: move to api.ts - await axios.post( - `${getAgentaApiUrl()}/api/testsets/upload/`, - formData, - { - headers: { - "Content-Type": "multipart/form-data", - }, - //@ts-ignore - _ignoreError: true, + await axios.post(`${getAgentaApiUrl()}/api/testsets/upload/`, formData, { + headers: { + "Content-Type": "multipart/form-data", }, - ) + //@ts-ignore + _ignoreError: true, + }) form.resetFields() router.push(`/apps/${appId}/testsets`) } catch (e: any) { From a1c72251a1165f589562dbb4a7fdfbf62aec95e4 Mon Sep 17 00:00:00 2001 From: Akrem Abayed Date: Tue, 5 Dec 2023 14:34:19 +0100 Subject: [PATCH 17/22] default to agentaai/templates_v2 --- agenta-backend/agenta_backend/routers/app_router.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agenta-backend/agenta_backend/routers/app_router.py b/agenta-backend/agenta_backend/routers/app_router.py index b687d2c305..b7d7e50cbf 100644 --- a/agenta-backend/agenta_backend/routers/app_router.py +++ b/agenta-backend/agenta_backend/routers/app_router.py @@ -352,7 +352,7 @@ async def create_app_and_variant_from_template( logger.debug("Step 5: Retrieve template from db") template_db = await db_manager.get_template(payload.template_id) - repo_name = os.environ.get("AGENTA_TEMPLATE_REPO", "agentaai/lambda_templates") + repo_name = os.environ.get("AGENTA_TEMPLATE_REPO", "agentaai/templates_v2") image_name = f"{repo_name}:{template_db.name}" logger.debug( From 7133ba6e0a7ca5f033fa6cce90ed8bd11d15b18f Mon Sep 17 00:00:00 2001 From: Akrem Abayed Date: Tue, 5 Dec 2023 15:47:00 +0100 Subject: [PATCH 18/22] fix for oss when hosted --- agenta-backend/agenta_backend/services/app_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agenta-backend/agenta_backend/services/app_manager.py b/agenta-backend/agenta_backend/services/app_manager.py index 2a27a2abb1..d20ac81c8d 100644 --- a/agenta-backend/agenta_backend/services/app_manager.py +++ b/agenta-backend/agenta_backend/services/app_manager.py @@ -71,7 +71,7 @@ async def start_variant( logger.debug("App name is %s", db_app_variant.app.app_name) # update the env variables domain_name = os.environ.get("DOMAIN_NAME") - if domain_name is None or domain_name == "http://localhost": + if os.environ["FEATURE_FLAG"] in ["oss"]: # in the case of agenta running locally, the containers can access the host machine via this address domain_name = ( "http://host.docker.internal" # unclear why this stopped working From 452532041cce16ec4dd87f205e72e923eb77eed7 Mon Sep 17 00:00:00 2001 From: Akrem Abayed Date: Tue, 5 Dec 2023 15:48:10 +0100 Subject: [PATCH 19/22] revert commit --- agenta-backend/agenta_backend/services/app_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agenta-backend/agenta_backend/services/app_manager.py b/agenta-backend/agenta_backend/services/app_manager.py index d20ac81c8d..2a27a2abb1 100644 --- a/agenta-backend/agenta_backend/services/app_manager.py +++ b/agenta-backend/agenta_backend/services/app_manager.py @@ -71,7 +71,7 @@ async def start_variant( logger.debug("App name is %s", db_app_variant.app.app_name) # update the env variables domain_name = os.environ.get("DOMAIN_NAME") - if os.environ["FEATURE_FLAG"] in ["oss"]: + if domain_name is None or domain_name == "http://localhost": # in the case of agenta running locally, the containers can access the host machine via this address domain_name = ( "http://host.docker.internal" # unclear why this stopped working From eafb78996072603425efe8d1c271d7def771df9f Mon Sep 17 00:00:00 2001 From: Nehemiah Onyekachukwu Emmanuel Date: Tue, 5 Dec 2023 17:19:10 +0100 Subject: [PATCH 20/22] properly return variant input names --- agenta-backend/agenta_backend/services/evaluation_service.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/agenta-backend/agenta_backend/services/evaluation_service.py b/agenta-backend/agenta_backend/services/evaluation_service.py index 0b1e062b4b..8f951ab555 100644 --- a/agenta-backend/agenta_backend/services/evaluation_service.py +++ b/agenta-backend/agenta_backend/services/evaluation_service.py @@ -196,6 +196,8 @@ async def prepare_csvdata_and_create_evaluation_scenario( user: The owner of the evaluation scenario app: The app the evaluation is going to belong to """ + + print('payload_inputs', payload_inputs) for datum in csvdata: # Check whether the inputs in the test set match the inputs in the variant From 10c98c3ab7eaaa1b42d9c65a10bcaac5b3c5a764 Mon Sep 17 00:00:00 2001 From: Nehemiah Onyekachukwu Emmanuel Date: Tue, 5 Dec 2023 17:21:26 +0100 Subject: [PATCH 21/22] properly return variant input names --- agenta-backend/agenta_backend/services/evaluation_service.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agenta-backend/agenta_backend/services/evaluation_service.py b/agenta-backend/agenta_backend/services/evaluation_service.py index 0b1e062b4b..67ad49e8e5 100644 --- a/agenta-backend/agenta_backend/services/evaluation_service.py +++ b/agenta-backend/agenta_backend/services/evaluation_service.py @@ -190,7 +190,7 @@ async def prepare_csvdata_and_create_evaluation_scenario( Args: csvdata: A list of dictionaries representing the CSV data. - inputs: A list of strings representing the names of the inputs in the variant. + payload_inputs: A list of strings representing the names of the inputs in the variant. evaluation_type: The type of evaluation new_evaluation: The instance of EvaluationDB user: The owner of the evaluation scenario @@ -208,7 +208,7 @@ async def prepare_csvdata_and_create_evaluation_scenario( await engine.delete(new_evaluation) msg = f""" Columns in the test set should match the names of the inputs in the variant. - Inputs names in variant are: {inputs} while + Inputs names in variant are: {[variant_input for variant_input in payload_inputs]} while columns in test set are: {[col for col in datum.keys() if col != 'correct_answer']} """ raise HTTPException( From f693ca86058586f9516e435aa0d9cccb1c91fed7 Mon Sep 17 00:00:00 2001 From: Nehemiah Onyekachukwu Emmanuel Date: Tue, 5 Dec 2023 17:24:56 +0100 Subject: [PATCH 22/22] remove debug print statement --- agenta-backend/agenta_backend/services/evaluation_service.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/agenta-backend/agenta_backend/services/evaluation_service.py b/agenta-backend/agenta_backend/services/evaluation_service.py index 50d9d5a2dc..67ad49e8e5 100644 --- a/agenta-backend/agenta_backend/services/evaluation_service.py +++ b/agenta-backend/agenta_backend/services/evaluation_service.py @@ -196,8 +196,6 @@ async def prepare_csvdata_and_create_evaluation_scenario( user: The owner of the evaluation scenario app: The app the evaluation is going to belong to """ - - print('payload_inputs', payload_inputs) for datum in csvdata: # Check whether the inputs in the test set match the inputs in the variant