-
Notifications
You must be signed in to change notification settings - Fork 42
Adding APIs to CreateGraphTemplate #132
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2aa3608
added models to create graph_template
NiveditJain e023ee6
fixed spell check
NiveditJain a897eea
fixed comments by @coderabbitai
NiveditJain 1999bbc
added graph create apis
NiveditJain 3f122f7
removed extra f
NiveditJain 12a10df
added GrpahTemplate to main
NiveditJain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| from app.singletons.logs_manager import LogsManager | ||
| from app.models.graph_models import UpsertGraphTemplateRequest, UpsertGraphTemplateResponse | ||
| from app.models.db.graph_template_model import GraphTemplate | ||
| from app.models.graph_template_validation_status import GraphTemplateValidationStatus | ||
| from beanie.operators import Set | ||
|
|
||
| logger = LogsManager().get_logger() | ||
|
|
||
| async def upsert_graph_template(namespace_name: str, graph_name: str, body: UpsertGraphTemplateRequest, x_exosphere_request_id: str) -> UpsertGraphTemplateResponse: | ||
| try: | ||
| graph_template = await GraphTemplate.find_one( | ||
| GraphTemplate.name == graph_name, | ||
| GraphTemplate.namespace == namespace_name | ||
| ) | ||
| if graph_template: | ||
| logger.info( | ||
| "Graph template already exists in namespace", graph_template=graph_template, | ||
| namespace_name=namespace_name, | ||
| x_exosphere_request_id=x_exosphere_request_id) | ||
|
|
||
| await graph_template.update( | ||
| Set({ | ||
| GraphTemplate.nodes: body.nodes, # type: ignore | ||
| GraphTemplate.validation_status: GraphTemplateValidationStatus.PENDING, # type: ignore | ||
| GraphTemplate.validation_errors: [] # type: ignore | ||
| }) | ||
| ) | ||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| else: | ||
| logger.info( | ||
| "Graph template does not exist in namespace", | ||
| namespace_name=namespace_name, | ||
| graph_name=graph_name, | ||
| x_exosphere_request_id=x_exosphere_request_id) | ||
|
|
||
| graph_template = await GraphTemplate.insert( | ||
| GraphTemplate( | ||
| name=graph_name, | ||
| namespace=namespace_name, | ||
| nodes=body.nodes, | ||
| validation_status=GraphTemplateValidationStatus.PENDING, | ||
| validation_errors=[] | ||
| ) | ||
| ) | ||
|
|
||
| return UpsertGraphTemplateResponse( | ||
| name=graph_template.name, | ||
| namespace=graph_template.namespace, | ||
| nodes=graph_template.nodes, | ||
| validation_status=graph_template.validation_status, | ||
| validation_errors=graph_template.validation_errors, | ||
| created_at=graph_template.created_at, | ||
| updated_at=graph_template.updated_at | ||
| ) | ||
|
|
||
| except Exception as e: | ||
| logger.error("Error upserting graph template", error=e, x_exosphere_request_id=x_exosphere_request_id) | ||
| raise e | ||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| from .base import BaseDatabaseModel | ||
| from pydantic import Field | ||
| from typing import Optional, List | ||
| from ..graph_template_validation_status import GraphTemplateValidationStatus | ||
| from ..node_template_model import NodeTemplate | ||
| from pymongo import IndexModel | ||
|
|
||
|
|
||
| class GraphTemplate(BaseDatabaseModel): | ||
| name: str = Field(..., description="Name of the graph") | ||
| namespace: str = Field(..., description="Namespace of the graph") | ||
| nodes: List[NodeTemplate] = Field(..., description="Nodes of the graph") | ||
| validation_status: GraphTemplateValidationStatus = Field(..., description="Validation status of the graph") | ||
| validation_errors: Optional[List[str]] = Field(None, description="Validation errors of the graph") | ||
|
|
||
| class Settings: | ||
| indexes = [ | ||
| IndexModel( | ||
| keys=[("name", 1), ("namespace", 1)], | ||
| unique=True, | ||
| name="unique_name_namespace" | ||
| ) | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| from .node_template_model import NodeTemplate | ||
| from pydantic import BaseModel, Field | ||
| from typing import List, Optional | ||
| from datetime import datetime | ||
| from .graph_template_validation_status import GraphTemplateValidationStatus | ||
|
|
||
|
|
||
| class UpsertGraphTemplateRequest(BaseModel): | ||
| name: str = Field(..., description="The name of the graph template") | ||
| namespace: str = Field(..., description="The namespace where the graph template will be stored") | ||
| nodes: List[NodeTemplate] = Field(..., description="List of node templates that define the graph structure") | ||
|
|
||
|
|
||
| class UpsertGraphTemplateResponse(BaseModel): | ||
| name: str = Field(..., description="The name of the graph template") | ||
| namespace: str = Field(..., description="The namespace where the graph template is stored") | ||
| nodes: List[NodeTemplate] = Field(..., description="List of node templates that define the graph structure") | ||
| created_at: datetime = Field(..., description="Timestamp when the graph template was created") | ||
| updated_at: datetime = Field(..., description="Timestamp when the graph template was last updated") | ||
| validation_status: GraphTemplateValidationStatus = Field(..., description="Current validation status of the graph template") | ||
| validation_errors: Optional[List[str]] = Field(None, description="List of validation errors if the graph template is invalid") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| from enum import Enum | ||
|
|
||
|
|
||
| class GraphTemplateValidationStatus(str, Enum): | ||
| VALID = "VALID" | ||
| INVALID = "INVALID" | ||
| PENDING = "PENDING" | ||
| ONGOING = "ONGOING" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| from pydantic import Field, BaseModel | ||
| from typing import Any, Optional, List | ||
|
|
||
|
|
||
| class NodeTemplate(BaseModel): | ||
| node_name: str = Field(..., description="Name of the node") | ||
| namespace: str = Field(..., description="Namespace of the node") | ||
| identifier: str = Field(..., description="Identifier of the node") | ||
| inputs: dict[str, Any] = Field(..., description="Inputs of the node") | ||
| store: dict[str, Any] = Field(..., description="Upsert data to store object for the node") | ||
| next_nodes: Optional[List[str]] = Field(None, description="Next nodes to execute") | ||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.