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

docs: user guide for publishing via Modal #551

Merged
merged 6 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ New to Garden? Here are some great places to begin:
- [FAQs](user_guide/faqs.md) - Find answers to common questions and troubleshooting tips
- [Docker Guide](user_guide/docker.md) - Learn about Garden's use of Docker for consistent reproducible environments
- ["Seedlings" Repository](https://github.com/Garden-AI/seedlings) - Example projects to help you get started
- [Publishing via Modal](user_guide/modal-publishing.md) - Learn how to publish a Garden using [Modal](https://modal.com)

## Additional Resources

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
151 changes: 151 additions & 0 deletions docs/user_guide/modal-publishing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
## 1. Create a Modal Account

**NOTE:** This step requires a free [GitHub](https://github.com) account to authenticate with Modal.

Create a free Modal account: [signup](https://modal.com/signup)

## 2. Author a Modal App

### Create a Modal file

Modal files are regular python scripts. Create a new python file in your project:

```bash
$ touch my_app.py
```

### Imports

```python
# my_app.py

# Import the Modal SDK
import modal
```

### Define the Modal App

Create a `modal.App` obeject where your custom functions will be registered.
Modal apps need to be assigned to a variable named `app` and in the global scope.

```
app = modal.App("my-cool-app")
```

### Define Modal functions

Modal functions are regular python functions that have been decorated with `@app.function()`.
The `@app.function()` decorator registers the function with the `modal.App` created above.
Like Modal Apps, Modal functions need to be defined in the global scope.

```python
# Define a function and register it with the app
# Functions can be named anything you like
@app.function()
def my_awesome_function(data):
result = sum(data)
return result


# You can register multiple functions to the same app
@app.function()
def my_other_cool_function(data):
# you can call modal functions from within other modal functions
inital_results = my_awesome_function.remote(data)
result = inital_results + 42
return result

```

### The Complete Modal File

That is all we need to do to define a Modal App that can be published with Garden! See the complete modal file below:
See the [Modal docs](https://modal.com/docs/guide) for more details on defining Modal Apps and functions.

```python
# my_app.py

# Import the Modal SDK
import modal

# Define your App -- this is the top-level entity that holds references to functions
# It must be assigned to a variable named 'app' for Garden to extact it properly
app = modal.App("my-cool-app")

# Define a function and register it with the app
# Functions can be named anything you like
@app.function()
def my_awesome_function(data):
result = sum(data)
return result

# You can register multiple functions to the same app
@app.function()
def my_other_cool_function(data):
# you can call modal functions from within other modal functions
inital_results = my_awesome_function.remote(data)
result = inital_results + 42
return result
```

## 3. Upload your App to Garden

### Create a new Garden

Create a Garden and upload your Modal App on the [Create Garden](https://thegardens.ai/#/garden/create) page.

Or Click 'Create a Garden' from the [Garden Home Page](https://thegardens.ai)

![Create a Garden](./images/modal_publishing/create_a_garden.png)

Then click 'Get Started' on the option to create a garden from a Modal App.

![Create a Garden from Modal App](./images/modal_publishing/create_garden_from_modal_app.png)

### Fill in Garden Details

Fill in the general details about your garden including a title, description of the Garden, and any tags you want to add.

![Fill in Garden Details](./images/modal_publishing/garden_general_info.png)

### Upload the Modal App

Upload the Modal App by clicking 'Browse' and selecting the python file defining your Modal App.

![Upload Modal App](./images/modal_publishing/garden_modal_app.png)

### Add Contributors

Fill in information about the authors and any contributors to the Garden.

![Add Contributors](./images/modal_publishing/garden_contributors_and_submit.png)

### Submit

When the information is correct click 'Create Garden'!

It may take a few minutes for the deployment process to finish.

Check the 'My Gardens' tab on your [Profile](https://thegardens.ai/#/user) page for the new Garden and note the DOI for the next step.

## 4. Run your functions using Garden

After uploading your Modal App to Garden, you should have a new DOI referencing the Garden you created.

You can run your Modal functions like any other Entrypoint published on Garden:

```python
from garden_ai import GardenClient

# the doi of the Garden created in step 3
garden_doi = "10.1234/567-8910f"


data = [1, 2, 3, 4, 5]

client = GardenClient()
garden = client.get_garden(garden_doi)

# Function is executed remotely on Modal!
result = garden.my_awesome_function(data)
```
Loading