mirror of
https://github.com/Significant-Gravitas/AutoGPT-Code-Ability.git
synced 2026-11-10 16:11:28 -10:00
This is a very early prototype of the front-end code generation. The current implementation is still super basic, but the idea is to evaluate early if this is possible. The hypothesis is if we can build a small fully working UI component, we can utilize more sophisticated agentic prompting. I created a video of the quick run-through of the code and how to test it https://www.loom.com/share/b331582fa2694ece8594c00ae78c71e5?sid=59b6baa6-ca9b-4f46-bb7e-76a82b1fce98 These are the possible next steps: https://www.notion.so/auto-gpt/Front-end-Codex-Plan-abf6c1d990104d23b758960cbaea26f9 --------- Co-authored-by: majdyz <[email protected]>
136 lines
4.3 KiB
Python
136 lines
4.3 KiB
Python
from typing import List, Tuple
|
|
|
|
from prisma.models import CompiledRoute, CompletedApp, Function, Specification
|
|
|
|
from codex.api_model import Identifiers, Pagination
|
|
from codex.common.database import INCLUDE_API_ROUTE, INCLUDE_FUNC
|
|
|
|
|
|
async def get_deliverable(deliverable_id: str) -> CompletedApp:
|
|
completed_app = await CompletedApp.prisma().find_unique_or_raise(
|
|
where={"id": deliverable_id, "deleted": False},
|
|
include={
|
|
"CompiledRoutes": {
|
|
"include": {
|
|
"RootFunction": INCLUDE_FUNC, # type: ignore
|
|
"Functions": INCLUDE_FUNC,
|
|
"ApiRouteSpec": INCLUDE_API_ROUTE,
|
|
}
|
|
}
|
|
},
|
|
)
|
|
|
|
return completed_app
|
|
|
|
|
|
async def delete_deliverable(
|
|
user_id: str, app_id: str, spec_id: str, deliverable_id: str
|
|
) -> None:
|
|
await CompletedApp.prisma().update(
|
|
where={"id": deliverable_id},
|
|
data={"deleted": True},
|
|
)
|
|
|
|
|
|
async def list_deliverables(
|
|
user_id: str,
|
|
app_id: str,
|
|
spec_id: str,
|
|
page: int = 1,
|
|
page_size: int = 10,
|
|
) -> Tuple[List[CompletedApp], Pagination]:
|
|
skip = (page - 1) * page_size
|
|
total_items = await CompletedApp.prisma().count(
|
|
where={"deleted": False, "specificationId": spec_id}
|
|
)
|
|
if total_items == 0:
|
|
return [], Pagination(total_items=0, total_pages=0, current_page=0, page_size=0)
|
|
total_pages = (total_items + page_size - 1) // page_size
|
|
|
|
completed_apps_data = await CompletedApp.prisma().find_many(
|
|
skip=skip,
|
|
take=page_size,
|
|
include={"CompiledRoutes": True},
|
|
where={"deleted": False, "specificationId": spec_id},
|
|
)
|
|
|
|
pagination = Pagination(
|
|
total_items=total_items,
|
|
total_pages=total_pages,
|
|
current_page=page,
|
|
page_size=page_size,
|
|
)
|
|
return completed_apps_data, pagination
|
|
|
|
|
|
async def get_compiled_code(deliverable_id: str) -> list[str]:
|
|
routes = await CompiledRoute.prisma().find_many(
|
|
where={"completedAppId": deliverable_id}
|
|
)
|
|
return [route.compiledCode for route in routes]
|
|
|
|
|
|
async def get_compiled_route(compiled_route_id: str) -> CompiledRoute:
|
|
return await CompiledRoute.prisma().find_unique_or_raise(
|
|
where={"id": compiled_route_id},
|
|
include={
|
|
"RootFunction": INCLUDE_FUNC, # type: ignore
|
|
"Functions": INCLUDE_FUNC, # type: ignore
|
|
"ApiRouteSpec": INCLUDE_API_ROUTE, # type: ignore
|
|
},
|
|
)
|
|
|
|
|
|
async def get_ids_from_function_id_and_compiled_route(
|
|
function_id: str, compiled_route_id: str
|
|
) -> Identifiers:
|
|
function = await Function.prisma().find_unique_or_raise(
|
|
where={"id": function_id},
|
|
include={
|
|
"CompiledRoute": {
|
|
"include": {
|
|
"ApiRouteSpec": True,
|
|
"CompletedApp": {
|
|
"include": {
|
|
"User": True,
|
|
"Application": True,
|
|
"Specification": True,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
)
|
|
|
|
compiled_route = await CompiledRoute.prisma().find_unique_or_raise(
|
|
where={"id": compiled_route_id},
|
|
include={
|
|
"CompletedApp": {
|
|
"include": {"User": True, "Application": True, "Specification": True},
|
|
}
|
|
},
|
|
)
|
|
if not compiled_route.CompletedApp:
|
|
raise ValueError("Compiled route does not have a completed app")
|
|
if not compiled_route.CompletedApp.Specification:
|
|
raise ValueError("Compiled route does not have a specification")
|
|
specification = await Specification.prisma().find_unique_or_raise(
|
|
where={"id": compiled_route.CompletedApp.Specification.id},
|
|
include={
|
|
"Interview": True,
|
|
"User": True,
|
|
},
|
|
)
|
|
if not specification.User:
|
|
raise ValueError("Specification does not have a user")
|
|
return Identifiers(
|
|
user_id=specification.userId,
|
|
cloud_services_id=specification.User.cloudServicesId,
|
|
app_id=specification.applicationId,
|
|
interview_id=specification.interviewId,
|
|
spec_id=specification.id,
|
|
compiled_route_id=function.compiledRouteId,
|
|
function_id=function.id,
|
|
completed_app_id=compiled_route.completedAppId,
|
|
)
|