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.
Before you can run GenSphere workflows, you need to set up the necessary environment variables, including your API keys.
Ensure you have the following API keys:
Set your environment variables in your terminal or include them in a .env
file. Using a .env
file is recommended for convenience and security.
.env
FileCreate 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.
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
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
This section guides you through pulling a pre-built workflow from the GenSphere platform, executing it, and accessing its outputs.
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
class manages interactions with the GenSphere platform.Result:
This command downloads the specified YAML workflow and associated Python functions, saving them to your current working directory.
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:
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:
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': ...}
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:
Visualizer
class to get a graphical representation of your workflows.Continue to the Tutorials section to deepen your understanding of GenSphere’s capabilities! ```