diff --git a/04_secrets/db_to_sheet.py b/04_secrets/db_to_sheet.py index d1dff63fe..94ffe5762 100644 --- a/04_secrets/db_to_sheet.py +++ b/04_secrets/db_to_sheet.py @@ -1,6 +1,5 @@ # --- # deploy: true -# env: {"MODAL_ENVIRONMENT": "main"} # --- # # Write to Google Sheets from Postgres @@ -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 @@ -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.: @@ -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"]) @@ -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"], ) @@ -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"] ) ], ) diff --git a/06_gpu_and_ml/dreambooth/diffusers_lora_finetune.py b/06_gpu_and_ml/dreambooth/diffusers_lora_finetune.py index b589c0977..60f10555a 100644 --- a/06_gpu_and_ml/dreambooth/diffusers_lora_finetune.py +++ b/06_gpu_and_ml/dreambooth/diffusers_lora_finetune.py @@ -1,6 +1,5 @@ # --- # deploy: true -# env: {"MODAL_ENVIRONMENT": "main"} # --- # # Create a character LoRA for Flux with Hugging Face and Gradio @@ -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( @@ -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 @@ -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 diff --git a/06_gpu_and_ml/embeddings/text_embeddings_inference.py b/06_gpu_and_ml/embeddings/text_embeddings_inference.py index 02bb1ca2d..8f6060996 100644 --- a/06_gpu_and_ml/embeddings/text_embeddings_inference.py +++ b/06_gpu_and_ml/embeddings/text_embeddings_inference.py @@ -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 @@ -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]) diff --git a/06_gpu_and_ml/langchains/potus_speech_qanda.py b/06_gpu_and_ml/langchains/potus_speech_qanda.py index 4c67221b9..e8ee27a0a 100644 --- a/06_gpu_and_ml/langchains/potus_speech_qanda.py +++ b/06_gpu_and_ml/langchains/potus_speech_qanda.py @@ -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 diff --git a/06_gpu_and_ml/llm-structured/instructor_generate.py b/06_gpu_and_ml/llm-structured/instructor_generate.py index 3d5d3ef74..bb2e2eb4a 100644 --- a/06_gpu_and_ml/llm-structured/instructor_generate.py +++ b/06_gpu_and_ml/llm-structured/instructor_generate.py @@ -1,6 +1,5 @@ # --- # output-directory: "/tmp/instructor_generate" -# env: {"MODAL_ENVIRONMENT": "main"} # --- # # Structured Data Extraction using `instructor` @@ -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"] ) ], ) diff --git a/06_gpu_and_ml/yolo/finetune_yolo.py b/06_gpu_and_ml/yolo/finetune_yolo.py index 95e28ebe2..8c6ee2d2c 100644 --- a/06_gpu_and_ml/yolo/finetune_yolo.py +++ b/06_gpu_and_ml/yolo/finetune_yolo.py @@ -1,6 +1,5 @@ # --- # args: ["--no-quick-check"] -# env: {"MODAL_ENVIRONMENT": "main"} # --- # # Fine-tune open source YOLO models for object detection diff --git a/10_integrations/cloud_bucket_mount_loras.py b/10_integrations/cloud_bucket_mount_loras.py index f156fceaf..edab18aca 100644 --- a/10_integrations/cloud_bucket_mount_loras.py +++ b/10_integrations/cloud_bucket_mount_loras.py @@ -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 @@ -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 @@ -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() diff --git a/10_integrations/dbt/dbt_duckdb.py b/10_integrations/dbt/dbt_duckdb.py index f4605dcc2..0f6160f4b 100644 --- a/10_integrations/dbt/dbt_duckdb.py +++ b/10_integrations/dbt/dbt_duckdb.py @@ -1,6 +1,5 @@ # --- # deploy: true -# env: {"MODAL_ENVIRONMENT": "main"} # --- # # Build your own data warehouse with DuckDB, DBT, and Modal diff --git a/10_integrations/s3_bucket_mount.py b/10_integrations/s3_bucket_mount.py index cd28ad28c..e49316531 100644 --- a/10_integrations/s3_bucket_mount.py +++ b/10_integrations/s3_bucket_mount.py @@ -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 diff --git a/10_integrations/webscraper.py b/10_integrations/webscraper.py index 241aaecbb..27d64b7b4 100644 --- a/10_integrations/webscraper.py +++ b/10_integrations/webscraper.py @@ -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. diff --git a/12_datasets/imagenet.py b/12_datasets/imagenet.py index 8822d46c7..9faf6d0d5 100644 --- a/12_datasets/imagenet.py +++ b/12_datasets/imagenet.py @@ -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/) diff --git a/13_sandboxes/codelangchain/README.md b/13_sandboxes/codelangchain/README.md index e614f995d..67d585ff6 100644 --- a/13_sandboxes/codelangchain/README.md +++ b/13_sandboxes/codelangchain/README.md @@ -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 @@ -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: @@ -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 diff --git a/13_sandboxes/codelangchain/agent.py b/13_sandboxes/codelangchain/agent.py index 997014564..705377cfe 100644 --- a/13_sandboxes/codelangchain/agent.py +++ b/13_sandboxes/codelangchain/agent.py @@ -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 @@ -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"] ), ], ) diff --git a/13_sandboxes/codelangchain/langserve.py b/13_sandboxes/codelangchain/langserve.py index 88690f8dc..dc2dddfe6 100644 --- a/13_sandboxes/codelangchain/langserve.py +++ b/13_sandboxes/codelangchain/langserve.py @@ -1,7 +1,6 @@ # --- # pytest: false # cmd: ["modal", "serve", "13_sandboxes.codelangchain.langserve"] -# env: {"MODAL_ENVIRONMENT": "main"} # --- # # Deploy LangChain and LangGraph applications with LangServe @@ -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"] ), ], )