Skip to content

Commit

Permalink
feat(backend): Public agent route started and utils package added
Browse files Browse the repository at this point in the history
  • Loading branch information
RezaRahemtola committed Nov 4, 2024
1 parent ff2a388 commit c18578f
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 23 deletions.
2 changes: 2 additions & 0 deletions backend/mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[mypy-libertai_utils.*]
ignore_missing_imports = True
53 changes: 52 additions & 1 deletion backend/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ python = "^3.12"
fastapi = { extras = ["standard"], version = "^0.115.2" }
aleph-sdk-python = "^1.1.0"
eciespy = "^0.4.2"
libertai-utils = "^0.0.2"

[tool.poetry.group.dev.dependencies]
mypy = "^1.12.0"
Expand Down
19 changes: 15 additions & 4 deletions backend/src/interfaces/agent.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from libertai_utils.interfaces.subscription import SubscriptionAccount
from pydantic import BaseModel, validator

from src.config import config
from src.interfaces.subscription import SubscriptionAccount


class DeleteAgentBody(BaseModel):
Expand All @@ -25,14 +25,25 @@ class UpdateAgentResponse(BaseModel):
vm_hash: str


class Agent(BaseModel):
class PublicAgentData(BaseModel):
id: str
subscription_id: str
vm_hash: str | None
encrypted_secret: str
last_update: int


class Agent(PublicAgentData):
subscription_id: str
encrypted_secret: str
tags: list[str]


class FetchedAgent(Agent):
post_hash: str


class GetAgentResponse(PublicAgentData):
pass


class GetAgentSecretResponse(BaseModel):
secret: str
16 changes: 0 additions & 16 deletions backend/src/interfaces/subscription.py

This file was deleted.

36 changes: 34 additions & 2 deletions backend/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
SetupAgentBody,
DeleteAgentBody,
UpdateAgentResponse,
GetAgentResponse,
GetAgentSecretResponse,
)
from src.interfaces.aleph import AlephVolume
from src.utils.agent import fetch_agents, fetch_agent_program_message
Expand Down Expand Up @@ -66,9 +68,39 @@ async def setup(body: SetupAgentBody) -> None:
)


@app.put("/agent", description="Deploy an agent or update it")
@app.get("/agent/{agent_id}", description="Get an agent public information")
async def get_agent_public_info(agent_id: str) -> GetAgentResponse:
agents = await fetch_agents([agent_id])

if len(agents) != 1:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND,
detail=f"Agent with ID {agent_id} not found.",
)
agent = agents[0]

return GetAgentResponse(
id=agent.id, vm_hash=agent.vm_hash, last_update=agent.last_update
)


@app.get("/agent/{agent_id}/secret", description="Get an agent secret")
async def get_agent_secret(agent_id: str, signature: str) -> GetAgentSecretResponse:
agents = await fetch_agents([agent_id])

if len(agents) != 1:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND,
detail=f"Agent with ID {agent_id} not found.",
)
# agent = agents[0]
# TODO: real implementation
return GetAgentSecretResponse(secret="")


@app.put("/agent/{agent_id}", description="Deploy an agent or update it")
async def update(
agent_id: str = Form(),
agent_id: str,
secret: str = Form(),
code: UploadFile = File(...),
packages: UploadFile = File(...),
Expand Down

0 comments on commit c18578f

Please sign in to comment.