Add Marketplace template (#7605)

* init

* Added sentry.io integration

* updated readme
This commit is contained in:
Swifty
2024-07-26 17:11:26 +02:00
committed by GitHub
parent dfa855f533
commit b62c24dc77
11 changed files with 1747 additions and 0 deletions

7
rnd/market/.env.example Normal file
View File

@@ -0,0 +1,7 @@
RUN_ENV=local
DB_USER=marketplace
DB_PASS=pass123
DB_NAME=marketplace
DB_PORT=5432
DATABASE_URL=postgresql://${DB_USER}:${DB_PASS}@localhost:${DB_PORT}/${DB_NAME}
SENTRY_DSN=https://sentry.io

6
rnd/market/.gitignore vendored Normal file
View File

@@ -0,0 +1,6 @@
database.db
database.db-journal
build/
config.json
secrets/*
!secrets/.gitkeep

14
rnd/market/README.md Normal file
View File

@@ -0,0 +1,14 @@
# AutoGPT Agent Marketplace
## Overview
AutoGPT Agent Marketplace is an open-source platform for autonomous AI agents. This project aims to create a user-friendly, accessible marketplace where users can discover, utilize, and contribute to a diverse ecosystem of AI solutions.
## Vision
Our vision is to empower users with customizable and free AI agents, fostering an open-source community that drives innovation in AI automation across various industries.
# Key Features
- Agent Discovery and Search
- Agent Listings with Detailed Information
- User Profiles
- Data Protection and Compliance

View File

@@ -0,0 +1,16 @@
version: "3"
services:
postgres:
image: ankane/pgvector:latest
environment:
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASS}
POSTGRES_DB: ${DB_NAME}
PGUSER: ${DB_USER}
healthcheck:
test: pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB
interval: 10s
timeout: 5s
retries: 5
ports:
- "${DB_PORT}:5432"

27
rnd/market/linter.py Normal file
View File

@@ -0,0 +1,27 @@
import os
import subprocess
directory = os.path.dirname(os.path.realpath(__file__))
def run(*command: str) -> None:
print(f">>>>> Running poetry run {' '.join(command)}")
subprocess.run(["poetry", "run"] + list(command), cwd=directory, check=True)
def lint():
try:
run("ruff", "check", ".", "--exit-zero")
run("isort", "--diff", "--check", "--profile", "black", ".")
run("black", "--diff", "--check", ".")
run("pyright")
except subprocess.CalledProcessError as e:
print("Lint failed, try running `poetry run format` to fix the issues: ", e)
raise e
def format():
run("ruff", "check", "--fix", ".")
run("isort", "--profile", "black", ".")
run("black", ".")
run("pyright", ".")

View File

60
rnd/market/market/app.py Normal file
View File

@@ -0,0 +1,60 @@
from contextlib import asynccontextmanager
import os
from dotenv import load_dotenv
from fastapi import FastAPI
from fastapi.middleware.gzip import GZipMiddleware
from prisma import Prisma
import sentry_sdk
from sentry_sdk.integrations.asyncio import AsyncioIntegration
from sentry_sdk.integrations.fastapi import FastApiIntegration
from sentry_sdk.integrations.starlette import StarletteIntegration
from market.routes import agents
load_dotenv()
if os.environ.get("SENTRY_DSN"):
sentry_sdk.init(
dsn=os.environ.get("SENTRY_DSN"),
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring.
traces_sample_rate=1.0,
# Set profiles_sample_rate to 1.0 to profile 100%
# of sampled transactions.
# We recommend adjusting this value in production.
profiles_sample_rate=1.0,
enable_tracing=True,
environment=os.environ.get("RUN_ENV", default="CLOUD").lower(),
integrations=[
StarletteIntegration(transaction_style="url"),
FastApiIntegration(transaction_style="url"),
AsyncioIntegration(),
],
)
db_client = Prisma(auto_register=True)
@asynccontextmanager
async def lifespan(app: FastAPI):
await db_client.connect()
yield
await db_client.disconnect()
app = FastAPI(
title="Marketplace API",
description=(
"AutoGPT Marketplace API is a service that allows users to share AI agents."
),
summary="Maketplace API",
version="0.1",
lifespan=lifespan,
)
# Add gzip middleware to compress responses
app.add_middleware(GZipMiddleware, minimum_size=1000)
app.include_router(agents.router, prefix="/market/agents", tags=["agents"])

View File

@@ -0,0 +1,3 @@
from fastapi import APIRouter
router = APIRouter()

1491
rnd/market/poetry.lock generated Normal file

File diff suppressed because it is too large Load Diff

45
rnd/market/pyproject.toml Normal file
View File

@@ -0,0 +1,45 @@
[tool.poetry]
name = "market"
version = "0.1.0"
description = ""
authors = ["SwiftyOS <craigswift13@gmail.com>"]
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.10"
prisma = "^0.12.0"
python-dotenv = "^1.0.1"
uvicorn = "^0.30.3"
fastapi = "^0.111.1"
sentry-sdk = {extras = ["fastapi"], version = "^2.11.0"}
[tool.poetry.group.dev.dependencies]
pytest = "^8.2.1"
pytest-asyncio = "^0.23.7"
pytest-watcher = "^0.4.2"
requests = "^2.32.3"
ruff = "^0.5.2"
pyright = "^1.1.371"
isort = "^5.13.2"
black = "^24.4.2"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
[tool.poetry.scripts]
format = "linter:format"
lint = "linter:lint"
[tool.pytest-watcher]
now = false
clear = true
delay = 0.2
runner = "pytest"
runner_args = []
patterns = ["*.py"]
ignore_patterns = []
[tool.pytest.ini_options]
asyncio_mode = "auto"

78
rnd/market/schema.prisma Normal file
View File

@@ -0,0 +1,78 @@
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-py"
recursive_type_depth = 5
interface = "asyncio"
}
// This model describes the Agent Graph/Flow (Multi Agent System).
model AgentGraph {
id String @default(uuid())
version Int @default(1)
name String?
description String?
isActive Boolean @default(true)
isTemplate Boolean @default(false)
AgentNodes AgentNode[]
@@id(name: "graphVersionId", [id, version])
}
// This model describes a single node in the Agent Graph/Flow (Multi Agent System).
model AgentNode {
id String @id @default(uuid())
agentBlockId String
AgentBlock AgentBlock @relation(fields: [agentBlockId], references: [id])
agentGraphId String
agentGraphVersion Int @default(1)
AgentGraph AgentGraph @relation(fields: [agentGraphId, agentGraphVersion], references: [id, version])
// List of consumed input, that the parent node should provide.
Input AgentNodeLink[] @relation("AgentNodeSink")
// List of produced output, that the child node should be executed.
Output AgentNodeLink[] @relation("AgentNodeSource")
// JSON serialized dict[str, str] containing predefined input values.
constantInput String @default("{}")
// JSON serialized dict[str, str] containing the node metadata.
metadata String @default("{}")
}
// This model describes the link between two AgentNodes.
model AgentNodeLink {
id String @id @default(uuid())
// Output of a node is connected to the source of the link.
agentNodeSourceId String
AgentNodeSource AgentNode @relation("AgentNodeSource", fields: [agentNodeSourceId], references: [id])
sourceName String
// Input of a node is connected to the sink of the link.
agentNodeSinkId String
AgentNodeSink AgentNode @relation("AgentNodeSink", fields: [agentNodeSinkId], references: [id])
sinkName String
}
// This model describes a component that will be executed by the AgentNode.
model AgentBlock {
id String @id @default(uuid())
name String @unique
// We allow a block to have multiple types of input & output.
// Serialized object-typed `jsonschema` with top-level properties as input/output name.
inputSchema String
outputSchema String
// Prisma requires explicit back-references.
ReferencedByAgentNode AgentNode[]
}