Skip to content

Commit

Permalink
feat: libertai-utils added
Browse files Browse the repository at this point in the history
  • Loading branch information
RezaRahemtola committed Nov 12, 2024
1 parent 853971e commit ca80351
Show file tree
Hide file tree
Showing 5 changed files with 1,970 additions and 129 deletions.
6 changes: 4 additions & 2 deletions libertai_client/commands/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
from docker import client # type: ignore
from docker.models.containers import Container # type: ignore
from dotenv import dotenv_values
from libertai_utils.aleph.program import get_vm_url
from rich.console import Console
from rich.progress import Progress, TextColumn, SpinnerColumn, TimeElapsedColumn

from libertai_client.config import config
from libertai_client.interfaces.agent import DockerCommand, UpdateAgentResponse
from libertai_client.utils.agent import parse_agent_config_env, get_vm_host_url
from libertai_client.utils.agent import parse_agent_config_env
from libertai_client.utils.rich import TaskOfTotalColumn, TEXT_PROGRESS_FORMAT
from libertai_client.utils.system import get_full_path

Expand Down Expand Up @@ -92,6 +93,7 @@ def deploy(path: Annotated[str, typer.Option(help="Path to the root of your repo
error_message = f"\n[red]Docker command error: '{command_output}'"
break

# TODO: add IDs to command and use it here instead of the text
if command.title == "Uploading to Aleph and creating the agent VM":
agent_result = result.output.decode()
progress.update(task, description=f"[green]{command.title}", advance=1)
Expand All @@ -111,4 +113,4 @@ def deploy(path: Annotated[str, typer.Option(help="Path to the root of your repo

if agent_result is not None:
agent_data = UpdateAgentResponse(**json.loads(agent_result))
print(f"Agent successfully deployed on {get_vm_host_url(agent_data.vm_hash)}")
print(f"Agent successfully deployed on {get_vm_url(agent_data.vm_hash)}")
7 changes: 0 additions & 7 deletions libertai_client/utils/agent.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from base64 import b32encode, b16decode

from libertai_client.interfaces.agent import AgentConfig


Expand All @@ -12,8 +10,3 @@ def parse_agent_config_env(env: dict[str, str | None]) -> AgentConfig:
f"Missing {'LIBERTAI_AGENT_ID' if agent_id is None else 'LIBERTAI_AGENT_SECRET'} variable in your project's .env.libertai")

return AgentConfig(id=agent_id, secret=agent_secret)

def get_vm_host_url(item_hash: str) -> str:
# From aleph-client
hash_base32 = b32encode(b16decode(item_hash.upper())).strip(b"=").lower().decode()
return f"https://{hash_base32}.aleph.sh"
2 changes: 2 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[mypy-libertai_utils.*]
ignore_missing_imports = True
Loading

0 comments on commit ca80351

Please sign in to comment.