Skip to content

Commit

Permalink
tweak(platform): Remove importing templates from local dir (#8276)
Browse files Browse the repository at this point in the history
* always filter on user id

* add user id to doc string

* fix linting

* fix imports function

* remove import templates from local directory
  • Loading branch information
aarushik93 authored Oct 9, 2024
1 parent dbc603c commit c03e2fb
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 34 deletions.
31 changes: 0 additions & 31 deletions autogpt_platform/backend/backend/data/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging
import uuid
from datetime import datetime, timezone
from pathlib import Path
from typing import Any, Literal

import prisma.types
Expand All @@ -15,7 +14,6 @@
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

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -611,32 +609,3 @@ async def __create_graph(tx, graph: Graph, user_id: str):
for link in graph.links
]
)


# --------------------- Helper functions --------------------- #


TEMPLATES_DIR = Path(__file__).parent.parent.parent / "graph_templates"


async def import_packaged_templates() -> None:
templates_in_db = await get_graphs_meta(
user_id=DEFAULT_USER_ID, filter_by="template"
)

logging.info("Loading templates...")
for template_file in TEMPLATES_DIR.glob("*.json"):
template_data = json.loads(template_file.read_bytes())

template = Graph.model_validate(template_data)
if not template.is_template:
logging.warning(
f"pre-packaged graph file {template_file} is not a template"
)
continue
if (
exists := next((t for t in templates_in_db if t.id == template.id), None)
) and exists.version >= template.version:
continue
await create_graph(template, DEFAULT_USER_ID)
logging.info(f"Loaded template '{template.name}' ({template.id})")
3 changes: 0 additions & 3 deletions autogpt_platform/backend/backend/server/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from backend.data import block, db
from backend.data import execution as execution_db
from backend.data import graph as graph_db
from backend.data import user as user_db
from backend.data.block import BlockInput, CompletedBlockOutput
from backend.data.credit import get_block_costs, get_user_credit_model
from backend.data.queue import RedisEventQueue
Expand Down Expand Up @@ -45,8 +44,6 @@ async def lifespan(self, _: FastAPI):
await db.connect()
self.event_queue.connect()
await block.initialize_blocks()
if await user_db.create_default_user(settings.config.enable_auth):
await graph_db.import_packaged_templates()
yield
self.event_queue.close()
await db.disconnect()
Expand Down

0 comments on commit c03e2fb

Please sign in to comment.