Skip to content

Commit

Permalink
move examples that use Secrets out of main (#1011)
Browse files Browse the repository at this point in the history
* move examples that use Secrets out of main

* typo
  • Loading branch information
charlesfrye authored Dec 4, 2024
1 parent 0ba6350 commit 7564e5c
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 40 deletions.
11 changes: 5 additions & 6 deletions 04_secrets/db_to_sheet.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# ---
# deploy: true
# env: {"MODAL_ENVIRONMENT": "main"}
# ---

# # Write to Google Sheets from Postgres
Expand All @@ -21,7 +20,7 @@

# First we will enter our database credentials. The easiest way to do this is to click **New
# secret** and select the **Postgres compatible** Secret preset and fill in the requested
# information. Then we press **Next** and name our Secret `example-postgres-secret` and click **Create**.
# information. Then we press **Next** and name our Secret `postgres-secret` and click **Create**.

# ### Google Sheets/GCP

Expand Down Expand Up @@ -52,7 +51,7 @@
# 8. A json key file should be downloaded to your computer at this point. Copy the contents of that
# file and use it as the value for the `SERVICE_ACCOUNT_JSON` field in your new secret.

# We'll name this other Secret `"my-gsheets-secret"`.
# We'll name this other Secret `"gsheets-secret"`.

# Now you can access the values of your Secrets from Modal Functions that you annotate with the
# corresponding `modal.Secret`s, e.g.:
Expand All @@ -64,7 +63,7 @@
app = modal.App("example-db-to-sheet")


@app.function(secrets=[modal.Secret.from_name("example-postgres-secret")])
@app.function(secrets=[modal.Secret.from_name("postgres-secret")])
def show_host():
# automatically filled from the specified secret
print("Host is " + os.environ["PGHOST"])
Expand All @@ -76,7 +75,7 @@ def show_host():
# You can additionally specify

pg_secret = modal.Secret.from_name(
"example-postgres-secret",
"postgres-secret",
required_keys=["PGHOST", "PGPORT", "PGDATABASE", "PGUSER", "PGPASSWORD"],
)

Expand Down Expand Up @@ -225,7 +224,7 @@ def main():
image=pygsheets_image,
secrets=[
modal.Secret.from_name(
"my-gsheets-secret", required_keys=["SERVICE_ACCOUNT_JSON"]
"gsheets-secret", required_keys=["SERVICE_ACCOUNT_JSON"]
)
],
)
Expand Down
9 changes: 4 additions & 5 deletions 06_gpu_and_ml/dreambooth/diffusers_lora_finetune.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# ---
# deploy: true
# env: {"MODAL_ENVIRONMENT": "main"}
# ---

# # Create a character LoRA for Flux with Hugging Face and Gradio
Expand Down Expand Up @@ -133,10 +132,10 @@ class SharedConfig:
# [gated by a license agreement](https://huggingface.co/docs/hub/en/models-gated) which
# you must agree to [here](https://huggingface.co/black-forest-labs/FLUX.1-dev).
# After you have accepted the license, [create a Modal Secret](https://modal.com/secrets)
# with the name `huggingface` following the instructions in the template.
# with the name `huggingface-secret` following the instructions in the template.

huggingface_secret = modal.Secret.from_name(
"huggingface", required_keys=["HF_TOKEN"]
"huggingface-secret", required_keys=["HF_TOKEN"]
)

image = image.env(
Expand Down Expand Up @@ -220,7 +219,7 @@ def load_images(image_urls: list[str]) -> Path:
# This is especially important if you're fiddling around with the configuration parameters.

# This example can optionally use [Weights & Biases](https://wandb.ai) to track all of this training information.
# Just sign up for an account, switch the flag below, and add your API key as a [Modal secret](https://modal.com/docs/guide/secrets).
# Just sign up for an account, switch the flag below, and add your API key as a [Modal Secret](https://modal.com/secrets).

USE_WANDB = False

Expand Down Expand Up @@ -275,7 +274,7 @@ class TrainConfig(SharedConfig):
+ (
[
modal.Secret.from_name(
"my-wandb-secret", required_keys=["WANDB_API_KEY"]
"wandb-secret", required_keys=["WANDB_API_KEY"]
)
]
if USE_WANDB
Expand Down
3 changes: 1 addition & 2 deletions 06_gpu_and_ml/embeddings/text_embeddings_inference.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# ---
# cmd: ["modal", "run", "06_gpu_and_ml/embeddings/text_embeddings_inference.py::embed_dataset"]
# env: {"MODAL_ENVIRONMENT": "main"}
# ---

# # Run TextEmbeddingsInference (TEI) on Modal
Expand Down Expand Up @@ -118,7 +117,7 @@ def download_data():
"bigquery-public-data.hacker_news.full",
max_results=100_000,
)
df = iterator.to_dataframe(progress_bar_type="tqdm")
df = iterator.to_dataframe(progress_bar_type="tqdm").dropna()

df["id"] = df["id"].astype(int)
df["text"] = df["text"].apply(lambda x: x[:512])
Expand Down
1 change: 0 additions & 1 deletion 06_gpu_and_ml/langchains/potus_speech_qanda.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# ---
# args: ["--query", "How many oil barrels were released from reserves?"]
# env: {"MODAL_ENVIRONMENT": "main"}
# ---

# # Retrieval-augmented generation (RAG) for question-answering with LangChain
Expand Down
3 changes: 1 addition & 2 deletions 06_gpu_and_ml/llm-structured/instructor_generate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# ---
# output-directory: "/tmp/instructor_generate"
# env: {"MODAL_ENVIRONMENT": "main"}
# ---

# # Structured Data Extraction using `instructor`
Expand Down Expand Up @@ -46,7 +45,7 @@
image=image,
secrets=[
modal.Secret.from_name(
"my-anthropic-secret", required_keys=["ANTHROPIC_API_KEY"]
"anthropic-secret", required_keys=["ANTHROPIC_API_KEY"]
)
],
)
Expand Down
1 change: 0 additions & 1 deletion 06_gpu_and_ml/yolo/finetune_yolo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# ---
# args: ["--no-quick-check"]
# env: {"MODAL_ENVIRONMENT": "main"}
# ---

# # Fine-tune open source YOLO models for object detection
Expand Down
5 changes: 2 additions & 3 deletions 10_integrations/cloud_bucket_mount_loras.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# ---
# output-directory: "/tmp/stable-diffusion-xl"
# deploy: true
# env: {"MODAL_ENVIRONMENT": "main"}
# ---

# # LoRAs Galore: Create a LoRA Playground with Modal, Gradio, and S3
Expand All @@ -17,7 +16,7 @@

# By the end of this example, we've deployed a "playground" app where anyone with a browser can try
# out these custom models. That's the power of Modal: custom, autoscaling AI applications, deployed in seconds.
# You can try out our deployment [here](https://modal-labs--loras-galore-ui.modal.run).
# You can try out our deployment [here](https://modal-labs-examples--loras-galore-ui.modal.run).

# ## Basic setup

Expand Down Expand Up @@ -86,7 +85,7 @@
# We went with 800 MiB, but feel free to adapt to what works best for you.


@app.function()
@app.function(secrets=[bucket_secret])
def search_loras(limit: int, max_model_size: int = 1024 * 1024 * 1024):
api = huggingface_hub.HfApi()

Expand Down
1 change: 0 additions & 1 deletion 10_integrations/dbt/dbt_duckdb.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# ---
# deploy: true
# env: {"MODAL_ENVIRONMENT": "main"}
# ---

# # Build your own data warehouse with DuckDB, DBT, and Modal
Expand Down
1 change: 0 additions & 1 deletion 10_integrations/s3_bucket_mount.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# ---
# output-directory: "/tmp/s3_bucket_mount"
# env: {"MODAL_ENVIRONMENT": "main"}
# ---

# # Analyze NYC yellow taxi data with DuckDB on Parquet files from S3
Expand Down
4 changes: 0 additions & 4 deletions 10_integrations/webscraper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# ---
# env: {"MODAL_ENVIRONMENT": "main"}
# ---

# # Web Scraping on Modal

# This example shows how you can scrape links from a website and post them to a Slack channel using Modal.
Expand Down
1 change: 0 additions & 1 deletion 12_datasets/imagenet.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# ---
# deploy: true
# lambda-test: false
# env: {"MODAL_ENVIRONMENT": "main"}
# ---
#
# This scripts demonstrates how to ingest the famous ImageNet (https://www.image-net.org/)
Expand Down
18 changes: 9 additions & 9 deletions 13_sandboxes/codelangchain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
This example deploys a "code agent": a language model that can write and execute
code in a flexible control flow aimed at completing a task or goal.

It is implemented in LangChain, using the LangGraph library to structure the agent
and the LangServe framework to turn it into a FastAPI app.
It is implemented in LangChain, using the LangGraph library to structure the
agent and the LangServe framework to turn it into a FastAPI app.

We use Modal to turn that app into a web endpoint. We also use Modal to
"sandbox" the agent's code execution, so that it can't accidentally (or when
Expand All @@ -19,14 +19,13 @@ the project's context and implementation. Check it out if you're curious!
To run this app, you need to `pip install modal` and then create the following
[secrets](https://modal.com/docs/guide/secrets):

- `openai-secret` with an OpenAI API key, so that we can query OpenAI's
models to power the agent,
- and `my-langsmith-secret` with a LangSmith API key, so that we can monitor the
- `openai-secret` with an OpenAI API key, so that we can query OpenAI's models
to power the agent,
- and `langsmith-secret` with a LangSmith API key, so that we can monitor the
agent's behavior with LangSmith.

Head to the
[secret creation dashboard](https://modal.com/secrets/)
and follow the instructions for each secret type.
Head to the [secret creation dashboard](https://modal.com/secrets/) and follow
the instructions for each secret type.

Then, you can deploy the app with:

Expand All @@ -42,7 +41,8 @@ You can also navigate to the `/docs` path to see OpenAPI/Swagger docs, for
everything you'd need to see how to incorporate the agent into your downstream
applications via API requests.

When developing the app, use `modal serve codelangchain.py` to get a hot-reloading server.
When developing the app, use `modal serve codelangchain.py` to get a
hot-reloading server.

## Repo structure

Expand Down
4 changes: 2 additions & 2 deletions 13_sandboxes/codelangchain/agent.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ---
# cmd: ["modal", "run", "13_sandboxes.codelangchain.agent", "--question", "Use gpt2 and transformers to generate text"]
# pytest: false
# env: {"MODAL_AUTOMOUNT": "True", "MODAL_ENVIRONMENT": "main"}
# env: {"MODAL_AUTOMOUNT": "True"}
# ---

# # Build a coding agent with Modal Sandboxes and LangGraph
Expand Down Expand Up @@ -36,7 +36,7 @@
"openai-secret", required_keys=["OPENAI_API_KEY"]
),
modal.Secret.from_name(
"my-langsmith-secret", required_keys=["LANGCHAIN_API_KEY"]
"langsmith-secret", required_keys=["LANGCHAIN_API_KEY"]
),
],
)
Expand Down
3 changes: 1 addition & 2 deletions 13_sandboxes/codelangchain/langserve.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# ---
# pytest: false
# cmd: ["modal", "serve", "13_sandboxes.codelangchain.langserve"]
# env: {"MODAL_ENVIRONMENT": "main"}
# ---

# # Deploy LangChain and LangGraph applications with LangServe
Expand Down Expand Up @@ -33,7 +32,7 @@
"openai-secret", required_keys=["OPENAI_API_KEY"]
),
modal.Secret.from_name(
"my-langsmith-secret", required_keys=["LANGCHAIN_API_KEY"]
"langsmith-secret", required_keys=["LANGCHAIN_API_KEY"]
),
],
)
Expand Down

0 comments on commit 7564e5c

Please sign in to comment.