| 1 | import { Action } from "@/Action"; |
| 2 | import * as GCP from "@/GCP"; |
| 3 | import * as Test from "@/Test/Alchemy"; |
| 4 | import { expect } from "alchemy-test"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | |
| 7 | const { test } = Test.make({ providers: GCP.providers() }); |
| 8 | |
| 9 | test.provider( |
| 10 | "GenerateContent calls Gemini through the HTTP binding", |
| 11 | (stack) => |
| 12 | Effect.gen(function* () { |
| 13 | yield* stack.destroy(); |
| 14 | |
| 15 | const out = yield* stack.deploy( |
| 16 | Effect.gen(function* () { |
| 17 | const Probe = Action( |
| 18 | "Probe", |
| 19 | Effect.gen(function* () { |
| 20 | const global = |
| 21 | yield* GCP.AIPlatform.GenerateContent("gemini-2.5-flash"); |
| 22 | const regional = yield* GCP.AIPlatform.GenerateContent({ |
| 23 | model: "gemini-2.5-flash", |
| 24 | location: "us-central1", |
| 25 | }); |
| 26 | return Effect.fn(function* () { |
| 27 | const text = yield* global.text("Reply with exactly: pong"); |
| 28 | const response = yield* regional.generate({ |
| 29 | contents: [ |
| 30 | { |
| 31 | role: "user", |
| 32 | parts: [{ text: "Reply with exactly: ping" }], |
| 33 | }, |
| 34 | ], |
| 35 | }); |
| 36 | return { |
| 37 | text, |
| 38 | regional: |
| 39 | response.candidates?.[0]?.content?.parts |
| 40 | ?.map((part) => part.text ?? "") |
| 41 | .join("") ?? "", |
| 42 | modelVersion: response.modelVersion, |
| 43 | }; |
| 44 | }); |
| 45 | }), |
| 46 | ); |
| 47 | return yield* Probe({}); |
| 48 | }), |
| 49 | ); |
| 50 | |
| 51 | expect(out.text.toLowerCase()).toContain("pong"); |
| 52 | expect(out.regional.toLowerCase()).toContain("ping"); |
| 53 | expect(out.modelVersion).toContain("gemini-2.5-flash"); |
| 54 | |
| 55 | yield* stack.destroy(); |
| 56 | }), |
| 57 | { |
| 58 | tags: ["provider:gcp", "provider:gcp:aiplatform", "live"], |
| 59 | timeout: 120_000, |
| 60 | }, |
| 61 | ); |