mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
fix graph ID handling
This commit is contained in:
@@ -5,6 +5,7 @@ Provides endpoints for managing agent graphs (CRUD operations).
|
||||
"""
|
||||
|
||||
import logging
|
||||
from uuid import uuid4
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Query, Security
|
||||
from prisma.enums import APIKeyPermission
|
||||
@@ -121,7 +122,7 @@ async def create_graph(
|
||||
"""
|
||||
from backend.api.features.library import db as library_db
|
||||
|
||||
internal_graph = create_graph.to_internal()
|
||||
internal_graph = create_graph.to_internal(id=str(uuid4()), version=1)
|
||||
|
||||
graph = graph_db.make_graph_model(internal_graph, auth.user_id)
|
||||
graph.reassign_ids(user_id=auth.user_id, reassign_graph_id=True)
|
||||
@@ -154,9 +155,6 @@ async def update_graph(
|
||||
"""
|
||||
from backend.api.features.library import db as library_db
|
||||
|
||||
if update_graph.id and update_graph.id != graph_id:
|
||||
raise HTTPException(400, detail="Graph ID does not match ID in URI")
|
||||
|
||||
existing_versions = await graph_db.get_graph_all_versions(
|
||||
graph_id, user_id=auth.user_id
|
||||
)
|
||||
|
||||
@@ -80,10 +80,8 @@ class GraphNode(BaseModel):
|
||||
|
||||
|
||||
class CreatableGraph(BaseModel):
|
||||
"""Graph definition for creating or updating an agent."""
|
||||
"""Graph model for creating or updating an agent graph."""
|
||||
|
||||
id: Optional[str] = Field(default=None, description="Graph ID (assigned by server)")
|
||||
version: int = Field(default=1, description="Graph version")
|
||||
name: str = Field(description="Graph name")
|
||||
description: str = Field(default="", description="Graph description")
|
||||
nodes: list[GraphNode] = Field(description="List of nodes")
|
||||
@@ -93,16 +91,16 @@ class CreatableGraph(BaseModel):
|
||||
def to_internal(
|
||||
self,
|
||||
*,
|
||||
id: str | None = None,
|
||||
version: int | None = None,
|
||||
id: str,
|
||||
version: int,
|
||||
) -> "_Graph":
|
||||
from backend.data.graph import Graph as _Graph
|
||||
from backend.data.graph import Link as _Link
|
||||
from backend.data.graph import Node as _Node
|
||||
|
||||
return _Graph(
|
||||
id=id if id is not None else (self.id or ""),
|
||||
version=version if version is not None else self.version,
|
||||
id=id, # "" triggers UUID generation
|
||||
version=version,
|
||||
is_active=self.is_active,
|
||||
name=self.name,
|
||||
description=self.description,
|
||||
|
||||
Reference in New Issue
Block a user