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

[Enhancement]: Make use of fix local uri for deployments #2072

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
15 changes: 9 additions & 6 deletions agenta-backend/agenta_backend/services/deployment_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions agenta-backend/agenta_backend/services/llm_apps_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion agenta-backend/agenta_backend/tasks/evaluations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Loading