Skip to content

Commit

Permalink
Merge branch 'master' into reinier/open-1855-set-up-supabase-in-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Pwuts authored Sep 23, 2024
2 parents c300b44 + c07cf8a commit 323438e
Show file tree
Hide file tree
Showing 23 changed files with 580 additions and 527 deletions.
40 changes: 40 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Ignore everything by default, selectively add things to context
classic/run

# AutoGPT
!classic/original_autogpt/autogpt/
!classic/original_autogpt/pyproject.toml
!classic/original_autogpt/poetry.lock
!classic/original_autogpt/README.md
!classic/original_autogpt/tests/

# Benchmark
!classic/benchmark/agbenchmark/
!classic/benchmark/pyproject.toml
!classic/benchmark/poetry.lock
!classic/benchmark/README.md

# Forge
!classic/forge/
!classic/forge/pyproject.toml
!classic/forge/poetry.lock
!classic/forge/README.md

# Frontend
!classic/frontend/build/web/

# Platform
!autogpt_platform/

# Explicitly re-ignore some folders
.*
**/__pycache__

autogpt_platform/frontend/.next/
autogpt_platform/frontend/node_modules
autogpt_platform/frontend/.env.example
autogpt_platform/frontend/.env.local
autogpt_platform/backend/.env
autogpt_platform/backend/.venv/

autogpt_platform/market/.env
6 changes: 3 additions & 3 deletions autogpt_platform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ To run the AutoGPT Platform, follow these steps:
6. Run the following command:

```
docker compose -f docker-compose.combined.yml up -d
docker compose up -d
```

Expand All @@ -46,8 +46,8 @@ To run the AutoGPT Platform, follow these steps:

Here are some useful Docker Compose commands for managing your AutoGPT Platform:

- `docker compose -f docker-compose.combined.yml up -d`: Start the services in detached mode.
- `docker compose -f docker-compose.combined.yml stop`: Stop the running services without removing them.
- `docker compose up -d`: Start the services in detached mode.
- `docker compose stop`: Stop the running services without removing them.
- `docker compose rm`: Remove stopped service containers.
- `docker compose build`: Build or rebuild services.
- `docker compose down`: Stop and remove containers, networks, and volumes.
Expand Down
2 changes: 1 addition & 1 deletion autogpt_platform/backend/backend/blocks/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def llm_call(input_data: AIStructuredResponseGeneratorBlock.Input) -> str:
if output_name == "response":
return output_data["response"]
else:
raise output_data
raise RuntimeError(output_data)
raise ValueError("Failed to get a response from the LLM.")

def run(self, input_data: Input) -> BlockOutput:
Expand Down
2 changes: 1 addition & 1 deletion autogpt_platform/backend/backend/blocks/time_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self):
{"trigger": "Hello", "format": "{time}"},
],
test_output=[
("time", time.strftime("%H:%M:%S")),
("time", lambda _: time.strftime("%H:%M:%S")),
],
)

Expand Down
12 changes: 6 additions & 6 deletions autogpt_platform/backend/backend/data/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,19 +396,19 @@ def merge_execution_input(data: BlockInput) -> BlockInput:

# Merge all input with <input_name>_$_<index> into a single list.
items = list(data.items())
list_input: list[Any] = []

for key, value in items:
if LIST_SPLIT not in key:
continue
name, index = key.split(LIST_SPLIT)
if not index.isdigit():
list_input.append((name, value, 0))
else:
list_input.append((name, value, int(index)))
raise ValueError(f"Invalid key: {key}, #{index} index must be an integer.")

for name, value, _ in sorted(list_input, key=lambda x: x[2]):
data[name] = data.get(name, [])
data[name].append(value)
if int(index) >= len(data[name]):
# Pad list with empty string on missing indices.
data[name].extend([""] * (int(index) - len(data[name]) + 1))
data[name][int(index)] = value

# Merge all input with <input_name>_#_<index> into a single dict.
for key, value in items:
Expand Down
58 changes: 56 additions & 2 deletions autogpt_platform/backend/backend/data/graph.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import asyncio
import logging
import uuid
from datetime import datetime, timezone
from pathlib import Path
from typing import Any, Literal

import prisma.types
from prisma.models import AgentGraph, AgentNode, AgentNodeLink
from prisma.models import AgentGraph, AgentGraphExecution, AgentNode, AgentNodeLink
from prisma.types import AgentGraphInclude
from pydantic import BaseModel, PrivateAttr
from pydantic_core import PydanticUndefinedType

from backend.blocks.basic import AgentInputBlock, AgentOutputBlock
from backend.data.block import BlockInput, get_block, get_blocks
from backend.data.db import BaseDbModel, transaction
from backend.data.execution import ExecutionStatus
from backend.data.user import DEFAULT_USER_ID
from backend.util import json

Expand Down Expand Up @@ -77,23 +80,65 @@ def from_db(node: AgentNode):
return obj


class ExecutionMeta(BaseDbModel):
execution_id: str
started_at: datetime
ended_at: datetime
duration: float
total_run_time: float
status: ExecutionStatus

@staticmethod
def from_agent_graph_execution(execution: AgentGraphExecution):
now = datetime.now(timezone.utc)
start_time = execution.startedAt or execution.createdAt
end_time = execution.updatedAt or now
duration = (end_time - start_time).total_seconds()

total_run_time = 0
if execution.AgentNodeExecutions:
for node_execution in execution.AgentNodeExecutions:
node_start = node_execution.startedTime or now
node_end = node_execution.endedTime or now
total_run_time += (node_end - node_start).total_seconds()

return ExecutionMeta(
id=execution.id,
execution_id=execution.id,
started_at=start_time,
ended_at=end_time,
duration=duration,
total_run_time=total_run_time,
status=ExecutionStatus(execution.executionStatus),
)


class GraphMeta(BaseDbModel):
version: int = 1
is_active: bool = True
is_template: bool = False

name: str
description: str
executions: list[ExecutionMeta] | None = None

@staticmethod
def from_db(graph: AgentGraph):
if graph.AgentGraphExecution:
executions = [
ExecutionMeta.from_agent_graph_execution(execution)
for execution in graph.AgentGraphExecution
]
else:
executions = None

return GraphMeta(
id=graph.id,
version=graph.version,
is_active=graph.isActive,
is_template=graph.isTemplate,
name=graph.name or "",
description=graph.description or "",
executions=executions,
)


Expand Down Expand Up @@ -337,6 +382,7 @@ async def get_node(node_id: str) -> Node:


async def get_graphs_meta(
include_executions: bool = False,
filter_by: Literal["active", "template"] | None = "active",
user_id: str | None = None,
) -> list[GraphMeta]:
Expand All @@ -345,6 +391,7 @@ async def get_graphs_meta(
Default behaviour is to get all currently active graphs.
Args:
include_executions: Whether to include executions in the graph metadata.
filter_by: An optional filter to either select templates or active graphs.
Returns:
Expand All @@ -364,6 +411,13 @@ async def get_graphs_meta(
where=where_clause,
distinct=["id"],
order={"version": "desc"},
include=(
AgentGraphInclude(
AgentGraphExecution={"include": {"AgentNodeExecutions": True}}
)
if include_executions
else None
),
)

if not graphs:
Expand Down
8 changes: 8 additions & 0 deletions autogpt_platform/backend/backend/executor/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,28 @@ def __init__(
self.prefix = f"[ExecutionManager|uid:{user_id}|gid:{graph_id}|nid:{node_id}]|geid:{graph_eid}|nid:{node_eid}|{block_name}]"

def info(self, msg: str, **extra):
msg = self._wrap(msg, **extra)
logger.info(msg, extra={"json_fields": {**self.metadata, **extra}})

def warning(self, msg: str, **extra):
msg = self._wrap(msg, **extra)
logger.warning(msg, extra={"json_fields": {**self.metadata, **extra}})

def error(self, msg: str, **extra):
msg = self._wrap(msg, **extra)
logger.error(msg, extra={"json_fields": {**self.metadata, **extra}})

def debug(self, msg: str, **extra):
msg = self._wrap(msg, **extra)
logger.debug(msg, extra={"json_fields": {**self.metadata, **extra}})

def exception(self, msg: str, **extra):
msg = self._wrap(msg, **extra)
logger.exception(msg, extra={"json_fields": {**self.metadata, **extra}})

def _wrap(self, msg: str, **extra):
return f"{self.prefix} {msg} {extra}"


T = TypeVar("T")
ExecutionStream = Generator[NodeExecution, None, None]
Expand Down
8 changes: 6 additions & 2 deletions autogpt_platform/backend/backend/server/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,13 @@ def execute_graph_block(

@classmethod
async def get_graphs(
cls, user_id: Annotated[str, Depends(get_user_id)]
cls,
user_id: Annotated[str, Depends(get_user_id)],
with_runs: bool = False,
) -> list[graph_db.GraphMeta]:
return await graph_db.get_graphs_meta(filter_by="active", user_id=user_id)
return await graph_db.get_graphs_meta(
include_executions=with_runs, filter_by="active", user_id=user_id
)

@classmethod
async def get_templates(cls) -> list[graph_db.GraphMeta]:
Expand Down
35 changes: 1 addition & 34 deletions autogpt_platform/backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ authors = ["AutoGPT <[email protected]>"]
readme = "README.md"
packages = [{ include = "backend" }]


[tool.poetry.dependencies]
python = "^3.10"
aio-pika = "^9.4.3"
Expand Down Expand Up @@ -67,40 +68,6 @@ cli = "backend.cli:main"
format = "linter:format"
lint = "linter:lint"
test = "run_tests:test"
# https://poethepoet.natn.io/index.html

[tool.poe]
poetry_command = ""

# poetry run poe xxx
[tool.poe.tasks]
test = "pytest"
build = ["test", "_dbuild"]

# This might break your python install :)
install = ["build", "_dinstall"]

# https://cx-freeze.readthedocs.io/en/stable/index.html
[tool.poe.tasks._dbuild]
cmd = "python setup.py build"

[tool.poe.tasks.dist_app]
cmd = "python setup.py bdist_app"

[tool.poe.tasks.dist_dmg]
cmd = "python setup.py bdist_dmg"

[tool.poe.tasks.dist_msi]
cmd = "python setup.py bdist_msi"

[tool.poe.tasks.dist_appimage]
cmd = "python setup.py bdist_appimage"

[tool.poe.tasks.dist_deb]
cmd = "python setup.py bdist_deb"

[tool.poe.tasks._dinstall]
cmd = "python setup.py install"

[tool.pytest-watcher]
now = false
Expand Down
Loading

0 comments on commit 323438e

Please sign in to comment.