Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(platform): updated schema to allow featuring of specific creators #9048

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ async def test_add_agent_to_library(mocker):
)

mock_user_agent = mocker.patch("prisma.models.UserAgent.prisma")
mock_user_agent.return_value.find_first = mocker.AsyncMock(return_value=None)
mock_user_agent.return_value.create = mocker.AsyncMock()

# Call function
Expand All @@ -162,6 +163,13 @@ async def test_add_agent_to_library(mocker):
mock_store_listing_version.return_value.find_unique.assert_called_once_with(
where={"id": "version123"}, include={"Agent": True}
)
mock_user_agent.return_value.find_first.assert_called_once_with(
where={
"userId": "test-user",
"agentId": "agent1",
"agentVersion": 1,
}
)
mock_user_agent.return_value.create.assert_called_once_with(
data=prisma.types.UserAgentCreateInput(
userId="test-user", agentId="agent1", agentVersion=1, isCreatedByUser=False
Expand Down
4 changes: 4 additions & 0 deletions autogpt_platform/backend/backend/server/v2/store/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ async def get_store_creators(
# Build where clause with sanitized inputs
where = {}

if featured:
where["isFeatured"] = featured

# Add search filter if provided, using parameterized queries
if search_query:
# Sanitize and validate search query by escaping special characters
Expand Down Expand Up @@ -247,6 +250,7 @@ async def get_store_creators(
num_agents=creator.num_agents,
agent_rating=creator.agent_rating,
agent_runs=creator.agent_runs,
is_featured=creator.is_featured,
)
for creator in creators
]
Expand Down
4 changes: 4 additions & 0 deletions autogpt_platform/backend/backend/server/v2/store/db_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ async def test_get_store_creator_details(mocker):
agent_rating=4.5,
agent_runs=10,
top_categories=["test"],
is_featured=False,
)

# Mock prisma call
Expand Down Expand Up @@ -197,6 +198,7 @@ async def test_update_profile(mocker):
description="Test description",
links=["link1"],
avatarUrl="avatar.jpg",
isFeatured=False,
createdAt=datetime.now(),
updatedAt=datetime.now(),
)
Expand All @@ -215,6 +217,7 @@ async def test_update_profile(mocker):
description="Test description",
links=["link1"],
avatar_url="avatar.jpg",
is_featured=False,
)

# Call function
Expand All @@ -239,6 +242,7 @@ async def test_get_user_profile(mocker):
description="Test description",
links=["link1", "link2"],
avatarUrl="avatar.jpg",
isFeatured=False,
createdAt=datetime.now(),
updatedAt=datetime.now(),
)
Expand Down
2 changes: 2 additions & 0 deletions autogpt_platform/backend/backend/server/v2/store/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class Creator(pydantic.BaseModel):
num_agents: int
agent_rating: float
agent_runs: int
is_featured: bool


class CreatorsResponse(pydantic.BaseModel):
Expand All @@ -98,6 +99,7 @@ class Profile(pydantic.BaseModel):
description: str
links: list[str]
avatar_url: str
is_featured: bool


class StoreSubmission(pydantic.BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def test_creator():
description="Test description",
avatar_url="avatar.jpg",
num_agents=5,
is_featured=False,
)
assert creator.name == "Test Creator"
assert creator.num_agents == 5
Expand All @@ -104,6 +105,7 @@ def test_creators_response():
description="Test description",
avatar_url="avatar.jpg",
num_agents=5,
is_featured=False,
)
],
pagination=backend.server.v2.store.model.Pagination(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ def test_get_creators_pagination(mocker: pytest_mock.MockFixture):
num_agents=1,
agent_rating=4.5,
agent_runs=100,
is_featured=False,
)
for i in range(5)
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Profile" ADD COLUMN "isFeatured" BOOLEAN NOT NULL DEFAULT false;
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ SELECT
p.description,
ARRAY_AGG(DISTINCT c) FILTER (WHERE c IS NOT NULL) as top_categories,
p.links,
p."isFeatured" as is_featured,
COALESCE(ast.num_agents, 0) as num_agents,
COALESCE(ast.agent_rating, 0.0) as agent_rating,
COALESCE(ast.agent_runs, 0) as agent_runs
Expand All @@ -84,7 +85,7 @@ LEFT JOIN LATERAL (
AND sl."isDeleted" = FALSE
AND sl."isApproved" = TRUE
) cats ON true
GROUP BY p.username, p.name, p."avatarUrl", p.description, p.links,
GROUP BY p.username, p.name, p."avatarUrl", p.description, p.links, p."isFeatured",
ast.num_agents, ast.agent_rating, ast.agent_runs;

CREATE VIEW "StoreSubmission" AS
Expand Down
3 changes: 3 additions & 0 deletions autogpt_platform/backend/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ model Profile {

avatarUrl String?

isFeatured Boolean @default(false)

@@index([username])
@@index([userId])
}
Expand All @@ -439,6 +441,7 @@ view Creator {
num_agents Int
agent_rating Float
agent_runs Int
is_featured Boolean
}

view StoreAgent {
Expand Down
Loading
Loading