Skip to content

Commit

Permalink
fix(agent): Minor response improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
RezaRahemtola committed Jan 17, 2025
1 parent 451b050 commit 8c31364
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
16 changes: 9 additions & 7 deletions libertai_client/commands/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@
),
questionary.Choice(
title="requirements.txt",
value=AgentPythonPackageManager.pip,
value=AgentPythonPackageManager.requirements,
description="Any management tool that outputs a requirements.txt file (pip, pip-tools...)",
),
questionary.Choice(
title="pyproject.toml",
value="TODO",
value=AgentPythonPackageManager.pyproject,
description="Any tool respecting the standard PEP 621 pyproject.toml (hatch, modern usage of setuptools...)",
disabled="Coming soon",
),
]

Expand Down Expand Up @@ -90,7 +89,8 @@ async def deploy(
(
choice
for choice in dependencies_management_choices
if choice.value == detected_dependencies_management.value
if detected_dependencies_management is not None
and choice.value == detected_dependencies_management.value
),
None,
),
Expand Down Expand Up @@ -133,15 +133,17 @@ async def deploy(
data=data,
) as response:
if response.status == 200:
response_data = UpdateAgentResponse(**json.loads(await response.text())) # noqa: F821
response_data = UpdateAgentResponse(**json.loads(await response.text()))
success_text = (
f"Agent successfully deployed on http://[{response_data.instance_ip}]:8000/docs"
if usage_type == AgentUsageType.fastapi
else f"Agent successfully deployed on instance {response_data.instance_ip}"
)
rich.print(f"[green]{success_text}")
else:
error_message = await response.text()
err_console.print(f"[red]Request failed\n{error_message}")
error_message = await response.json()
err_console.print(
f"[red]Request failed: {error_message.get("detail", "An unknown error happened.")}"
)

os.remove(agent_zip_path)
3 changes: 2 additions & 1 deletion libertai_client/interfaces/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class AgentConfig(BaseModel):

class AgentPythonPackageManager(str, Enum):
poetry = "poetry"
pip = "pip"
requirements = "requirements"
pyproject = "pyproject"


class AgentUsageType(str, Enum):
Expand Down
20 changes: 16 additions & 4 deletions libertai_client/utils/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,26 @@ def detect_python_project_version(

def detect_python_dependencies_management(
project_path: str,
) -> AgentPythonPackageManager:
) -> AgentPythonPackageManager | None:
try:
_poetry_lock_path = get_full_path(project_path, "poetry.lock")
# Path was found without throwing an error, its poetry
return AgentPythonPackageManager.poetry
except FileNotFoundError:
pass

# TODO: confirm with requirements.txt
# TODO: handle pyproject.toml standard compatible package managers
return AgentPythonPackageManager.pip
try:
_requirements_path = get_full_path(project_path, "requirements.tx")
# Path was found without throwing an error, we can use this to install deps
return AgentPythonPackageManager.requirements
except FileNotFoundError:
pass

try:
_pyproject_path = get_full_path(project_path, "pyproject.toml")
# Path was found without throwing an error, and Poetry tested earlier so it should be a standard pyproject
return AgentPythonPackageManager.pyproject
except FileNotFoundError:
pass

return None

0 comments on commit 8c31364

Please sign in to comment.