Skip to content
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

Add Griptape Utility for determining whether or not a structure is in a Managed environment #1650

Open
collindutter opened this issue Feb 5, 2025 · 0 comments · May be fixed by #1651
Open

Comments

@collindutter
Copy link
Member

Discussed in https://github.com/orgs/griptape-ai/discussions/1632

Originally posted by shhlife January 31, 2025
All of our Sample Structures have code to determine whether or not the structure is running in a managed template. Each one does this slightly differently.

It would be helpful for users if the Griptape Framework had a utility to do this in a consistent way so they didn't need to figure it out themselves.

I'm thinking of two things we might need.. one is to know whether or not the user is in a managed environment, and the other would be a way to automatically publish a FinishStructureRunEvent to the EventBus.

Currently you need to do something like this to find out if you're in the griptape cloud environment

def is_running_in_managed_environment() -> bool:
    return "GT_CLOUD_STRUCTURE_RUN_ID" in os.environ

then this to publish something to the event bus

task_input = TextArtifact(value=input)
task_output = TextArtifact(value=result)
done_event = FinishStructureRunEvent(
    output_task_input=task_input, output_task_output=task_output
)


if is_running_in_managed_environment():
    event_driver = GriptapeCloudEventListenerDriver(api_key=get_listener_api_key())
    EventBus.add_event_listener(EventListener(event_listener_driver=event_driver))
    EventBus.publish_event(done_event, flush=True)

Is there a way to make a Utility that makes this easier?

So the user could do something like:

from griptape.utils import ManagedEnv

env =  ManagedEnv()

if env.is_managed:
  env.finish_structure_run_event(input=input_artifact, output=output_artifact)
```</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant