@computesdk/modal 1.8.2 → 1.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +63 -48
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -20,23 +20,16 @@ export MODAL_TOKEN_ID=your_token_id_here
20
20
  export MODAL_TOKEN_SECRET=your_token_secret_here
21
21
  ```
22
22
 
23
- ## Usage
23
+ ## Quick Start
24
24
 
25
- ### With ComputeSDK
25
+ ### Gateway Mode (Recommended)
26
26
 
27
- ```typescript
28
- import { createCompute } from 'computesdk';
29
- import { modal } from '@computesdk/modal';
27
+ Use the gateway for zero-config auto-detection:
30
28
 
31
- // Set as default provider
32
- const compute = createCompute({
33
- provider: modal({
34
- tokenId: process.env.MODAL_TOKEN_ID,
35
- tokenSecret: process.env.MODAL_TOKEN_SECRET
36
- })
37
- });
29
+ ```typescript
30
+ import { compute } from 'computesdk';
38
31
 
39
- // Create sandbox
32
+ // Auto-detects Modal from MODAL_TOKEN_ID/MODAL_TOKEN_SECRET environment variables
40
33
  const sandbox = await compute.sandbox.create();
41
34
 
42
35
  // Execute Python code with GPU acceleration
@@ -60,25 +53,30 @@ print(f"Mean: {y.mean().item():.4f}")
60
53
  `);
61
54
 
62
55
  console.log(result.stdout);
63
-
64
- // Clean up
65
- await compute.sandbox.destroy(sandbox.sandboxId);
56
+ await sandbox.destroy();
66
57
  ```
67
58
 
68
- ### Direct Usage
59
+ ### Direct Mode
60
+
61
+ For direct SDK usage without the gateway:
69
62
 
70
63
  ```typescript
71
64
  import { modal } from '@computesdk/modal';
72
65
 
73
- // Create provider
74
- const provider = modal({
75
- tokenId: 'your_token_id',
76
- tokenSecret: 'your_token_secret',
77
- timeout: 600000 // 10 minutes
66
+ const compute = modal({
67
+ tokenId: process.env.MODAL_TOKEN_ID,
68
+ tokenSecret: process.env.MODAL_TOKEN_SECRET
78
69
  });
79
70
 
80
- // Use with compute singleton
81
- const sandbox = await compute.sandbox.create({ provider });
71
+ const sandbox = await compute.sandbox.create();
72
+
73
+ const result = await sandbox.runCode(`
74
+ import torch
75
+ print(f"PyTorch version: {torch.__version__}")
76
+ `);
77
+
78
+ console.log(result.stdout);
79
+ await sandbox.destroy();
82
80
  ```
83
81
 
84
82
  ## Configuration
@@ -149,24 +147,25 @@ const url = await sandbox.getUrl({ port: 3000 });
149
147
  console.log(`Server accessible at: ${url}`);
150
148
  ```
151
149
 
152
- #### Direct SDK Usage with Ports
150
+ #### Direct Mode with Ports
153
151
 
154
152
  ```typescript
155
153
  import { modal } from '@computesdk/modal';
156
154
 
157
- // Create provider with ports
158
- const provider = modal({
159
- tokenId: 'your_token_id',
160
- tokenSecret: 'your_token_secret',
155
+ const compute = modal({
156
+ tokenId: process.env.MODAL_TOKEN_ID,
157
+ tokenSecret: process.env.MODAL_TOKEN_SECRET,
161
158
  ports: [3000, 5000, 8080], // Multiple ports can be exposed
162
159
  timeout: 600000 // 10 minutes
163
160
  });
164
161
 
165
- const sandbox = await compute.sandbox.create({ provider });
162
+ const sandbox = await compute.sandbox.create();
166
163
 
167
164
  // Access different services on different ports
168
165
  const webUrl = await sandbox.getUrl({ port: 3000 });
169
166
  const apiUrl = await sandbox.getUrl({ port: 8080 });
167
+
168
+ await sandbox.destroy();
170
169
  ```
171
170
 
172
171
  **Note**: Ports are exposed with unencrypted tunnels by default for maximum compatibility. The tunnels are publicly accessible URLs managed by Modal.
@@ -356,7 +355,15 @@ const provider = modal({
356
355
  ## Error Handling
357
356
 
358
357
  ```typescript
358
+ import { modal } from '@computesdk/modal';
359
+
359
360
  try {
361
+ const compute = modal({
362
+ tokenId: process.env.MODAL_TOKEN_ID,
363
+ tokenSecret: process.env.MODAL_TOKEN_SECRET
364
+ });
365
+ const sandbox = await compute.sandbox.create();
366
+
360
367
  const result = await sandbox.runCode('invalid python code');
361
368
  } catch (error) {
362
369
  if (error.message.includes('Missing Modal API credentials')) {
@@ -371,30 +378,18 @@ try {
371
378
  }
372
379
  ```
373
380
 
374
- ## Web Framework Integration
381
+ ## Examples
375
382
 
376
- Use with web frameworks via the request handler:
383
+ ### Machine Learning Pipeline
377
384
 
378
385
  ```typescript
379
- import { handleComputeRequest } from 'computesdk';
380
386
  import { modal } from '@computesdk/modal';
381
387
 
382
- export async function POST(request: Request) {
383
- return handleComputeRequest({
384
- request,
385
- provider: modal({
386
- tokenId: process.env.MODAL_TOKEN_ID,
387
- tokenSecret: process.env.MODAL_TOKEN_SECRET
388
- })
389
- });
390
- }
391
- ```
392
-
393
- ## Examples
394
-
395
- ### Machine Learning Pipeline
388
+ const compute = modal({
389
+ tokenId: process.env.MODAL_TOKEN_ID,
390
+ tokenSecret: process.env.MODAL_TOKEN_SECRET
391
+ });
396
392
 
397
- ```typescript
398
393
  const sandbox = await compute.sandbox.create();
399
394
 
400
395
  // Create ML project structure
@@ -463,11 +458,20 @@ console.log(result.stdout);
463
458
  // Verify model was saved
464
459
  const modelExists = await sandbox.filesystem.exists('/ml-project/models/model.pt');
465
460
  console.log('Model saved:', modelExists);
461
+
462
+ await sandbox.destroy();
466
463
  ```
467
464
 
468
465
  ### GPU-Accelerated Inference
469
466
 
470
467
  ```typescript
468
+ import { modal } from '@computesdk/modal';
469
+
470
+ const compute = modal({
471
+ tokenId: process.env.MODAL_TOKEN_ID,
472
+ tokenSecret: process.env.MODAL_TOKEN_SECRET
473
+ });
474
+
471
475
  const sandbox = await compute.sandbox.create();
472
476
 
473
477
  // GPU inference example
@@ -519,11 +523,19 @@ print(f"Device: {outputs.device}")
519
523
  `);
520
524
 
521
525
  console.log(result.stdout);
526
+ await sandbox.destroy();
522
527
  ```
523
528
 
524
529
  ### Distributed Processing
525
530
 
526
531
  ```typescript
532
+ import { modal } from '@computesdk/modal';
533
+
534
+ const compute = modal({
535
+ tokenId: process.env.MODAL_TOKEN_ID,
536
+ tokenSecret: process.env.MODAL_TOKEN_SECRET
537
+ });
538
+
527
539
  // Process multiple tasks in parallel
528
540
  const tasks = [
529
541
  'task1_data.json',
@@ -556,6 +568,9 @@ results = {
556
568
 
557
569
  print(json.dumps(results))
558
570
  `);
571
+
572
+ await sandbox.destroy();
573
+ return result;
559
574
  })
560
575
  );
561
576
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@computesdk/modal",
3
- "version": "1.8.2",
3
+ "version": "1.8.3",
4
4
  "description": "Modal provider for ComputeSDK - serverless Python execution with GPU support and zero cold starts",
5
5
  "author": "Garrison",
6
6
  "license": "MIT",
@@ -19,8 +19,8 @@
19
19
  ],
20
20
  "dependencies": {
21
21
  "modal": "^0.3.16",
22
- "computesdk": "1.10.1",
23
- "@computesdk/provider": "1.0.1"
22
+ "@computesdk/provider": "1.0.2",
23
+ "computesdk": "1.10.2"
24
24
  },
25
25
  "keywords": [
26
26
  "computesdk",