The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | import * as GCP from "@alchemy.run/gcp"; |
| 2 | import { GcpEnvironment } from "@alchemy.run/gcp/Environment"; |
| 3 | import { expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as aiplatform from "@distilled.cloud/gcp/aiplatform_v1"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import { MinimumLogLevel } from "effect/References"; |
| 8 | import * as Schedule from "effect/Schedule"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: GCP.providers() }); |
| 11 | |
| 12 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 13 | |
| 14 | const waitUntilGone = (name: string) => |
| 15 | aiplatform.getProjectsLocationsHyperparameterTuningJobs({ name }).pipe( |
| 16 | Effect.as("found" as const), |
| 17 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 18 | Effect.repeat({ |
| 19 | schedule: Schedule.spaced("2 seconds"), |
| 20 | until: (status) => status === "gone", |
| 21 | times: 10, |
| 22 | }), |
| 23 | ); |
| 24 | |
| 25 | const studySpec = { |
| 26 | metrics: [{ metricId: "accuracy", goal: "MAXIMIZE" as const }], |
| 27 | parameters: [ |
| 28 | { |
| 29 | parameterId: "lr", |
| 30 | doubleValueSpec: { minValue: 0.001, maxValue: 0.1 }, |
| 31 | }, |
| 32 | ], |
| 33 | }; |
| 34 | |
| 35 | const trialJobSpec = { |
| 36 | workerPoolSpecs: [ |
| 37 | { |
| 38 | machineSpec: { machineType: "n1-standard-4" }, |
| 39 | replicaCount: "1", |
| 40 | containerSpec: { |
| 41 | imageUri: "us-docker.pkg.dev/vertex-ai/training/tf-cpu.2-12.py310:latest", |
| 42 | command: ["echo", "ok"], |
| 43 | }, |
| 44 | }, |
| 45 | ], |
| 46 | }; |
| 47 | |
| 48 | test.provider( |
| 49 | "getProjectsLocationsHyperparameterTuningJobs on a missing job fails with a typed tag", |
| 50 | (stack) => |
| 51 | Effect.gen(function* () { |
| 52 | const { project } = yield* GcpEnvironment.current; |
| 53 | const parent = `projects/${project}/locations/us-central1`; |
| 54 | yield* stack.destroy(); |
| 55 | |
| 56 | const error = yield* Effect.flip( |
| 57 | aiplatform.getProjectsLocationsHyperparameterTuningJobs({ |
| 58 | name: `${parent}/hyperparameterTuningJobs/1234567890123456789`, |
| 59 | }), |
| 60 | ); |
| 61 | expect(error._tag).toEqual("NotFound"); |
| 62 | const page = yield* aiplatform.listProjectsLocationsHyperparameterTuningJobs({ |
| 63 | parent, |
| 64 | pageSize: 10, |
| 65 | }); |
| 66 | expect((page.hyperparameterTuningJobs ?? []).map((item) => item.name)).not.toContain( |
| 67 | `${parent}/hyperparameterTuningJobs/1234567890123456789`, |
| 68 | ); |
| 69 | |
| 70 | yield* stack.destroy(); |
| 71 | }).pipe(logLevel), |
| 72 | { |
| 73 | tags: ["provider:gcp", "provider:gcp:aiplatform", "live"], |
| 74 | timeout: 90_000, |
| 75 | }, |
| 76 | ); |
| 77 | |
| 78 | test.provider( |
| 79 | "create and delete a hyperparameter tuning job", |
| 80 | (stack) => |
| 81 | Effect.gen(function* () { |
| 82 | yield* stack.destroy(); |
| 83 | |
| 84 | const created = yield* stack.deploy( |
| 85 | Effect.gen(function* () { |
| 86 | return yield* GCP.AIPlatform.HyperparameterTuningJob("Tune", { |
| 87 | location: "us-central1", |
| 88 | displayName: "alchemy-hpt", |
| 89 | maxTrialCount: 1, |
| 90 | parallelTrialCount: 1, |
| 91 | studySpec, |
| 92 | trialJobSpec, |
| 93 | labels: { env: "test" }, |
| 94 | }); |
| 95 | }), |
| 96 | ); |
| 97 | |
| 98 | expect(created.name).toContain("/hyperparameterTuningJobs/"); |
| 99 | expect(created.location).toEqual("us-central1"); |
| 100 | expect(created.labels).toMatchObject({ env: "test" }); |
| 101 | |
| 102 | const fetched = yield* aiplatform.getProjectsLocationsHyperparameterTuningJobs({ |
| 103 | name: created.name, |
| 104 | }); |
| 105 | expect(fetched.name).toEqual(created.name); |
| 106 | |
| 107 | yield* stack.destroy(); |
| 108 | |
| 109 | const gone = yield* waitUntilGone(created.name); |
| 110 | expect(gone).toEqual("gone"); |
| 111 | }).pipe(logLevel), |
| 112 | { |
| 113 | tags: ["provider:gcp", "provider:gcp:aiplatform", "live"], |
| 114 | timeout: 180_000, |
| 115 | }, |
| 116 | ); |