Python client library for Modal, a serverless cloud computing platform that enables developers to run Python code in the cloud with on-demand access to compute resources.
85
A utility that demonstrates the difference between local and remote execution in Modal by logging execution context information.
Write a program that uses Modal execution context functions to detect and log whether code is running in a local or remote environment. The program should run a simple function both locally and remotely, logging execution details.
@generates
import modal
app = modal.App("context-logger")
@app.function()
def log_context(message: str) -> dict:
"""
A Modal function that logs execution context information.
Args:
message: A message to include in the log
Returns:
A dictionary containing:
- 'is_local': Boolean indicating if running locally
- 'message': The input message
- 'function_call_id': The function call ID (or None if local)
- 'input_id': The input ID (or None if local)
"""
pass
@app.local_entrypoint()
def main():
"""
Local entrypoint that demonstrates the difference between
local and remote execution contexts.
"""
passProvides serverless cloud compute capabilities and execution context functions.
Install with Tessl CLI
npx tessl i tessl/pypi-modaldocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10