Quickstart Guide¶
Welcome to the GenSphere Quickstart Guide! This guide will walk you through creating and executing your first GenSphere workflow. By the end of this guide, you will have a functional workflow that interacts with the GenSphere platform.
Table of Contents¶
Setting Up Environment Variables¶
Before you can run GenSphere workflows, you need to set up the necessary environment variables, including your API keys.
1. Obtain API Keys¶
Ensure you have the following API keys:
- OpenAI API Key: Obtain here.
- Composio API Key (optional): Obtain here.
2. Define Environment Variables¶
Set your environment variables in your terminal or include them in a .env
file. Using a .env
file is recommended for convenience and security.
Using a .env
File¶
Create a file named .env
in your project directory and add the following lines:
OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
Substitute "YOUR_API_KEY" by your actual api key.
Loading Environment Variables¶
Ensure that your Python environment loads the .env
file. GenSphere uses the python-dotenv
package to load environment variables from a .env
file automatically.
If you haven't installed python-dotenv
, install it using pip
:
pip install python-dotenv
Alternatively, you can manually set environment variables in your terminal session:
# On Windows
set OPENAI_API_KEY=YOUR_OPENAI_API_KEY
# On macOS and Linux
export OPENAI_API_KEY=YOUR_OPENAI_API_KEY
Importing GenSphere Modules¶
Begin by importing the necessary GenSphere modules in your Python script or Jupyter Notebook.
import logging
import traceback
# Set up logging configuration before importing other modules
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler("app.log", mode='w'),
logging.StreamHandler()
]
)
from gensphere import genflow, yaml_utils
from gensphere.genflow import GenFlow
from gensphere.yaml_utils import YamlCompose
from gensphere.visualizer import Visualizer
from gensphere.hub import Hub
Explanation of Imports¶
- logging & traceback: For logging and debugging.
- gensphere modules: Core classes and utilities for defining and running workflows.
Running Your First Flow¶
This section guides you through pulling a pre-built workflow from the GenSphere platform, executing it, and accessing its outputs.
Pulling a Project from the Platform¶
GenSphere allows you to pull pre-built workflows from its open platform using a unique push_id
. This enables you to quickly start with existing workflows.
# Initialize the Hub
hub = Hub()
# Define the push_id and filenames to save the pulled files
push_id = '2c03079c-0e33-489e-bbbe-777da744d56f'
yaml_filename = 'simple_examples.yaml' #this will be the path of your YAML file after downloading it
functions_filename = 'simple_examples_functions.py' #this will be the path of your functions file after downloading it
# Pull the project from the platform
hub.pull(
push_id=push_id,
yaml_filename=yaml_filename,
functions_filename=functions_filename,
save_to_disk=True
)
Explanation:
- Hub: The
Hub
class manages interactions with the GenSphere platform. - push_id: Unique identifier for the project you want to pull.
- yaml_filename & functions_filename: Names of the files to save locally.
Result:
This command downloads the specified YAML workflow and associated Python functions, saving them to your current working directory.
Executing the Flow¶
Once you've pulled the workflow files, you can execute the workflow using the GenFlow
class.
# Initialize GenFlow with the pulled YAML and functions files
flow = GenFlow('simple_examples.yaml', 'simple_examples_functions.py')
# Parse the YAML file to construct the execution graph
flow.parse_yaml()
# Run the workflow
flow.run()
Explanation:
- GenFlow: Core class responsible for parsing, building, and executing workflows.
- parse_yaml(): Parses the YAML file and constructs the execution graph.
- run(): Executes the workflow based on the constructed graph.
Accessing Outputs¶
After running the workflow, you can access the outputs generated by each node.
# Access the outputs of the workflow
outputs = flow.outputs
# Print the outputs
for node_name, output in outputs.items():
print(f"Outputs from node '{node_name}': {output}")
Explanation:
- flow.outputs: A dictionary containing the outputs from each node in the workflow.
- Iterating through outputs: Print or utilize the outputs as needed.
Example Output:
Outputs from node 'get_current_date': {'current_date': '2024-04-27'}
Outputs from node 'get_timewindow': {'time_window': 'last month'}
Outputs from node 'product_hunt_scrape': {'product_hunt_scrape_results': ...}
Next Steps¶
Congratulations! You've successfully installed GenSphere, pulled a workflow from the platform, executed it, and accessed its outputs. Here are some suggested next steps to further enhance your understanding and usage of GenSphere:
- Explore the Tutorials: Dive into the Quickstart Tutorial for more detailed guidance.
- Define Your Own Workflows: Start creating your own workflows by defining YAML files, custom functions, and schemas.
- Integrate with Tools: Leverage integrations with LangChain and Composio to enhance your workflows.
- Visualize Your Workflows: Use the
Visualizer
class to get a graphical representation of your workflows. - Contribute to GenSphere: Share your workflows and contribute to the GenSphere community by pushing your projects to the platform.
Continue to the Tutorials section to deepen your understanding of GenSphere's capabilities! ```