mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
Add download counts for top agents
This commit is contained in:
@@ -75,6 +75,9 @@ const AgentCard: React.FC<{ agent: Agent; featured?: boolean }> = ({ agent, feat
|
||||
<div className="text-xs text-gray-400">
|
||||
Updated {new Date(agent.updatedAt).toLocaleDateString()}
|
||||
</div>
|
||||
<div className="text-xs text-gray-400">
|
||||
Downloads {agent.downloads}
|
||||
</div>
|
||||
{'rank' in agent && (
|
||||
<div className="text-xs text-indigo-600">
|
||||
Rank: {agent.rank.toFixed(2)}
|
||||
|
||||
@@ -31,6 +31,8 @@ export type Agent = {
|
||||
version: number;
|
||||
createdAt: string; // ISO8601 datetime string
|
||||
updatedAt: string; // ISO8601 datetime string
|
||||
views: number;
|
||||
downloads: number;
|
||||
};
|
||||
|
||||
export type AgentList = {
|
||||
|
||||
@@ -4,7 +4,9 @@ import fuzzywuzzy.fuzz
|
||||
import prisma.errors
|
||||
import prisma.models
|
||||
import prisma.types
|
||||
import pydantic
|
||||
|
||||
import market.model
|
||||
import market.utils.extension_types
|
||||
|
||||
|
||||
@@ -14,6 +16,25 @@ class AgentQueryError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class TopAgentsDBResponse(pydantic.BaseModel):
|
||||
"""
|
||||
Represents a response containing a list of top agents.
|
||||
|
||||
Attributes:
|
||||
analytics (list[AgentResponse]): The list of top agents.
|
||||
total_count (int): The total count of agents.
|
||||
page (int): The current page number.
|
||||
page_size (int): The number of agents per page.
|
||||
total_pages (int): The total number of pages.
|
||||
"""
|
||||
|
||||
analytics: list[prisma.models.AnalyticsTracker]
|
||||
total_count: int
|
||||
page: int
|
||||
page_size: int
|
||||
total_pages: int
|
||||
|
||||
|
||||
async def create_agent_entry(
|
||||
name: str,
|
||||
description: str,
|
||||
@@ -267,7 +288,9 @@ async def search_db(
|
||||
raise AgentQueryError(f"Unexpected error occurred: {str(e)}")
|
||||
|
||||
|
||||
async def get_top_agents_by_downloads(page: int = 1, page_size: int = 10):
|
||||
async def get_top_agents_by_downloads(
|
||||
page: int = 1, page_size: int = 10
|
||||
) -> TopAgentsDBResponse:
|
||||
"""Retrieve the top agents by download count.
|
||||
|
||||
Args:
|
||||
@@ -296,14 +319,13 @@ async def get_top_agents_by_downloads(page: int = 1, page_size: int = 10):
|
||||
# Get total count for pagination info
|
||||
total_count = len(analytics)
|
||||
|
||||
return {
|
||||
# should this be analytics as the top object?
|
||||
"agents": [agent.agent for agent in analytics],
|
||||
"total_count": total_count,
|
||||
"page": page,
|
||||
"page_size": page_size,
|
||||
"total_pages": (total_count + page_size - 1) // page_size, # floor division
|
||||
}
|
||||
return TopAgentsDBResponse(
|
||||
analytics=analytics,
|
||||
total_count=total_count,
|
||||
page=page,
|
||||
page_size=page_size,
|
||||
total_pages=(total_count + page_size - 1) // page_size,
|
||||
)
|
||||
|
||||
except AgentQueryError as e:
|
||||
# Log the error or handle it as needed
|
||||
|
||||
@@ -36,6 +36,8 @@ class AgentResponse(pydantic.BaseModel):
|
||||
version: int
|
||||
createdAt: datetime.datetime
|
||||
updatedAt: datetime.datetime
|
||||
views: int = 0
|
||||
downloads: int = 0
|
||||
|
||||
|
||||
class AgentListResponse(pydantic.BaseModel):
|
||||
|
||||
@@ -230,18 +230,32 @@ async def top_agents_by_downloads(
|
||||
page_size=page_size,
|
||||
)
|
||||
|
||||
agents = [
|
||||
market.model.AgentResponse(**agent.dict()) for agent in result["agents"]
|
||||
]
|
||||
|
||||
return market.model.AgentListResponse(
|
||||
agents=agents,
|
||||
total_count=result["total_count"],
|
||||
page=result["page"],
|
||||
page_size=result["page_size"],
|
||||
total_pages=result["total_pages"],
|
||||
ret = market.model.AgentListResponse(
|
||||
total_count=result.total_count,
|
||||
page=result.page,
|
||||
page_size=result.page_size,
|
||||
total_pages=result.total_pages,
|
||||
agents=[
|
||||
market.model.AgentResponse(
|
||||
id=item.agent.id,
|
||||
name=item.agent.name,
|
||||
description=item.agent.description,
|
||||
author=item.agent.author,
|
||||
keywords=item.agent.keywords,
|
||||
categories=item.agent.categories,
|
||||
version=item.agent.version,
|
||||
createdAt=item.agent.createdAt,
|
||||
updatedAt=item.agent.updatedAt,
|
||||
views=item.views,
|
||||
downloads=item.downloads,
|
||||
)
|
||||
for item in result.analytics
|
||||
if item.agent is not None
|
||||
],
|
||||
)
|
||||
|
||||
return ret
|
||||
|
||||
except market.db.AgentQueryError as e:
|
||||
raise fastapi.HTTPException(status_code=400, detail=str(e)) from e
|
||||
except Exception as e:
|
||||
|
||||
@@ -19,17 +19,22 @@ 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 pathlib
|
||||
|
||||
import requests
|
||||
|
||||
import market.model
|
||||
|
||||
templates = pathlib.Path(__file__).parent.parent / "autogpt_server" / "graph_templates"
|
||||
|
||||
|
||||
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()
|
||||
@@ -37,11 +42,13 @@ def populate_database():
|
||||
graph=json.loads(data),
|
||||
author="Populate DB",
|
||||
categories=["Pre-Populated"],
|
||||
keywords=["test"]
|
||||
keywords=["test"],
|
||||
)
|
||||
response = requests.post(
|
||||
"http://localhost:8001/market/admin/agent", json=req.model_dump()
|
||||
)
|
||||
response = requests.post("http://localhost:8001/market/admin/agent", json=req.model_dump())
|
||||
print(response.text)
|
||||
|
||||
|
||||
|
||||
def format():
|
||||
run("ruff", "check", "--fix", ".")
|
||||
|
||||
Reference in New Issue
Block a user