-
Notifications
You must be signed in to change notification settings - Fork 43
Adding Store and cleaning Trigger APIs and Create State APIs #331
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 2 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
12b2576
Refactor state management and enhance graph execution capabilities
NiveditJain 32feb67
Refactor validation and input handling in state management models
NiveditJain 815921a
Fix error message formatting in trigger_graph function
NiveditJain de3f590
Refactor dependency validation in GraphTemplate model
NiveditJain 5248a80
Refactor secrets validation in GraphTemplate model
NiveditJain 43d6108
Remove deprecated create_states functionality and update tests
NiveditJain cd526ba
fixed ruff
NiveditJain 957cae2
fixed all failing tests
NiveditJain a376538
updated sdk
NiveditJain b6c2ccc
Enhance graph execution with beta store support
NiveditJain 438689b
Add comprehensive tests for StateManager and Runtime functionality
NiveditJain 942e854
Add warning filters for coroutine and unraisable exceptions in tests
NiveditJain 8695081
Remove unused asyncio import from comprehensive StateManager tests
NiveditJain 9ade70b
Add tests for get_store_value function in create_next_states
NiveditJain 089a806
Update README and StateManager for Graph Store enhancements
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 was deleted.
Oops, something went wrong.
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,80 @@ | ||
| from fastapi import HTTPException | ||
|
|
||
| from app.singletons.logs_manager import LogsManager | ||
| from app.models.trigger_model import TriggerGraphRequestModel, TriggerGraphResponseModel | ||
| from app.models.state_status_enum import StateStatusEnum | ||
| from app.models.db.state import State | ||
| from app.models.db.store import Store | ||
| from app.models.db.graph_template_model import GraphTemplate | ||
| from app.models.node_template_model import NodeTemplate | ||
| import uuid | ||
|
|
||
| logger = LogsManager().get_logger() | ||
|
|
||
| def check_required_store_keys(graph_template: GraphTemplate, store: dict[str, str]) -> None: | ||
| required_keys = set(graph_template.store_config.required_keys) | ||
| provided_keys = set(store.keys()) | ||
|
|
||
| missing_keys = required_keys - provided_keys | ||
| if missing_keys: | ||
| raise HTTPException(status_code=400, detail=f"Missing store keys: {missing_keys}") | ||
|
|
||
|
NiveditJain marked this conversation as resolved.
|
||
|
|
||
| def construct_inputs(node: NodeTemplate, inputs: dict[str, str]) -> dict[str, str]: | ||
| return {key: inputs.get(key, value) for key, value in node.inputs.items()} | ||
|
|
||
|
NiveditJain marked this conversation as resolved.
|
||
|
|
||
| async def trigger_graph(namespace_name: str, graph_name: str, body: TriggerGraphRequestModel, x_exosphere_request_id: str) -> TriggerGraphResponseModel: | ||
| try: | ||
| run_id = str(uuid.uuid4()) | ||
| logger.info(f"Triggering graph {graph_name} with run_id {run_id}", x_exosphere_request_id=x_exosphere_request_id) | ||
|
|
||
| try: | ||
| graph_template = await GraphTemplate.get(namespace_name, graph_name) | ||
| except ValueError as e: | ||
| logger.error(f"Graph template not found for namespace {namespace_name} and graph {graph_name}", x_exosphere_request_id=x_exosphere_request_id) | ||
| if "Graph template not found" in str(e): | ||
| raise HTTPException(status_code=404, detail=f"Graph template not found for namespace {namespace_name} and graph {graph_name}") | ||
| else: | ||
| raise e | ||
|
NiveditJain marked this conversation as resolved.
|
||
|
|
||
| if not graph_template.is_valid(): | ||
| raise HTTPException(status_code=400, detail=f"Graph template is not valid") | ||
|
|
||
| check_required_store_keys(graph_template, body.store) | ||
|
|
||
| new_stores = [ | ||
| Store( | ||
| run_id=run_id, | ||
| namespace=namespace_name, | ||
| graph_name=graph_name, | ||
| key=key, | ||
| value=value | ||
| ) for key, value in body.store.items() | ||
| ] | ||
|
|
||
| await Store.insert_many(new_stores) | ||
|
|
||
| root = graph_template.get_root_node() | ||
|
|
||
| new_state = State( | ||
| node_name=root.node_name, | ||
| namespace_name=namespace_name, | ||
| identifier=root.identifier, | ||
| graph_name=graph_name, | ||
| run_id=run_id, | ||
| status=StateStatusEnum.CREATED, | ||
| inputs=construct_inputs(root, body.inputs), | ||
| outputs={}, | ||
| error=None | ||
| ) | ||
| await new_state.insert() | ||
|
|
||
| return TriggerGraphResponseModel( | ||
| status=StateStatusEnum.CREATED, | ||
| run_id=run_id | ||
| ) | ||
|
|
||
| except Exception as e: | ||
| logger.error(f"Error triggering graph {graph_name} for namespace {namespace_name}", x_exosphere_request_id=x_exosphere_request_id) | ||
| raise e | ||
|
NiveditJain marked this conversation as 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 was deleted.
Oops, something went wrong.
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,36 @@ | ||
| from beanie import Document | ||
| from pydantic import Field | ||
| from pymongo import IndexModel | ||
|
|
||
| class Store(Document): | ||
| run_id: str = Field(..., description="Run ID of the corresponding graph execution") | ||
| namespace: str = Field(..., description="Namespace of the graph") | ||
| graph_name: str = Field(..., description="Name of the graph") | ||
| key: str = Field(..., description="Key of the store") | ||
| value: str = Field(..., description="Value of the store") | ||
|
|
||
|
NiveditJain marked this conversation as resolved.
|
||
| class Settings: | ||
| indexes = [ | ||
| IndexModel( | ||
| [ | ||
| ("run_id", 1), | ||
| ("namespace", 1), | ||
| ("graph_name", 1), | ||
| ("key", 1), | ||
| ], | ||
| unique=True, | ||
| name="uniq_run_id_namespace_graph_name_key", | ||
| ) | ||
| ] | ||
|
NiveditJain marked this conversation as resolved.
|
||
|
|
||
| @staticmethod | ||
| async def get_value(run_id: str, namespace: str, graph_name: str, key: str) -> str | None: | ||
| store = await Store.find_one( | ||
| Store.run_id == run_id, | ||
| Store.namespace == namespace, | ||
| Store.graph_name == graph_name, | ||
| Store.key == key, | ||
| ) | ||
| if store is None: | ||
| return None | ||
| return store.value | ||
|
NiveditJain marked this conversation as 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
Oops, something went wrong.
Oops, something went wrong.
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.