Skip to content

Commit

Permalink
Added pre populate database command
Browse files Browse the repository at this point in the history
  • Loading branch information
Swiftyos committed Aug 2, 2024
1 parent ee57568 commit 051b007
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion rnd/market/market/routes/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
router = fastapi.APIRouter()


@router.post("/admin/agent", response_model=market.model.AgentResponse)
@router.post("/agent", response_model=market.model.AgentResponse)
async def create_agent_entry(request: market.model.AddAgentRequest):
"""
A basic endpoint to create a new agent entry in the database.
Expand Down
2 changes: 2 additions & 0 deletions rnd/market/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ build-backend = "poetry.core.masonry.api"
format = "scripts:format"
lint = "scripts:lint"
app = "scripts:app"
setup = "scripts:setup"
populate = "scripts:populate_database"

[tool.pytest-watcher]
now = false
Expand Down
30 changes: 29 additions & 1 deletion rnd/market/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,29 @@ def lint():
print("Lint failed, try running `poetry run format` to fix the issues: ", e)
raise e

def populate_database():
import requests
import pathlib
import glob
import json
import market.model

templates = pathlib.Path(__file__).parent.parent / "autogpt_server" / "graph_templates"

all_files = glob.glob(str(templates / "*.json"))

for file in all_files:
with open(file, "r") as f:
data = f.read()
req = market.model.AddAgentRequest(
graph=json.loads(data),
author="Populate DB",
categories=["Pre-Populated"],
keywords=["test"]
)
response = requests.post("http://localhost:8001/market/admin/agent", json=req.model_dump())
print(response.text)


def format():
run("ruff", "check", "--fix", ".")
Expand All @@ -28,4 +51,9 @@ def format():


def app():
run("uvicorn", "market.app:app", "--reload" , "--port", "8001")
run("uvicorn", "market.app:app", "--reload", "--port", "8001")


def setup():
run("prisma", "generate")
run("prisma", "migrate", "deploy")

0 comments on commit 051b007

Please sign in to comment.