diff --git a/agenta-backend/agenta_backend/services/deployment_manager.py b/agenta-backend/agenta_backend/services/deployment_manager.py index b44c320cf..f93e0a247 100644 --- a/agenta-backend/agenta_backend/services/deployment_manager.py +++ b/agenta-backend/agenta_backend/services/deployment_manager.py @@ -152,15 +152,18 @@ async def validate_image(image: Image) -> bool: return True -def get_deployment_uri(uri: str) -> str: +def get_deployment_uri(deployment: DeploymentDB) -> str: """ - Replaces localhost with the appropriate hostname in the given URI. + Builds a URI allowing the backend to access a given deployment. + In the case of a self-hosted setup, we bypass traefik and use the docker generated dns entry instead. Args: - uri (str): The URI to be processed. + deployment (DeploymentDB): The deployment to reach. Returns: - str: The processed URI. + str: URI leading to the deployment. """ - - return uri.replace("http://localhost", "http://host.docker.internal") + if "localhost" in deployment.uri: + # the DNS entry automatically created by docker for the container are the first 12 characters of the container's id + return "http://" + deployment.container_id[:12] + return deployment.uri diff --git a/agenta-backend/agenta_backend/services/llm_apps_service.py b/agenta-backend/agenta_backend/services/llm_apps_service.py index e6b1064fe..eb8dbb6d6 100644 --- a/agenta-backend/agenta_backend/services/llm_apps_service.py +++ b/agenta-backend/agenta_backend/services/llm_apps_service.py @@ -311,7 +311,7 @@ async def get_parameters_from_openapi(uri: str) -> List[Dict]: """ - schema = await _get_openai_json_from_uri(uri) + schema = await _get_openapi_json_from_uri(uri) try: body_schema_name = ( @@ -341,7 +341,7 @@ async def get_parameters_from_openapi(uri: str) -> List[Dict]: return parameters -async def _get_openai_json_from_uri(uri): +async def _get_openapi_json_from_uri(uri): async with aiohttp.ClientSession() as client: resp = await client.get(uri, timeout=5) resp_text = await resp.text() diff --git a/agenta-backend/agenta_backend/tasks/evaluations.py b/agenta-backend/agenta_backend/tasks/evaluations.py index b563bdc20..1c548caee 100644 --- a/agenta-backend/agenta_backend/tasks/evaluations.py +++ b/agenta-backend/agenta_backend/tasks/evaluations.py @@ -120,7 +120,7 @@ def evaluate( deployment_db = loop.run_until_complete( get_deployment_by_id(str(app_variant_db.base.deployment_id)) ) - uri = deployment_manager.get_deployment_uri(uri=deployment_db.uri) # type: ignore + uri = deployment_manager.get_deployment_uri(deployment_db) # type: ignore # 2. Initialize vars evaluators_aggregated_data = {