Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions spec/v2/providers/ai.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,25 +255,10 @@ describe("v2.ai", () => {
});
});
});
describe("Typings", () => {
it("should allow regional webhooks to specify multiple locations", () => {
ai.beforeGenerateContent(
{ regionalWebhook: true, location: ["us-central1", "europe-west1"] },
() => {}
);
});

it("should allow global webhooks to specify a single location", () => {
ai.beforeGenerateContent({ region: "us-central1" }, () => {});
describe("Typings & Options", () => {
it("should allow webhooks to specify a single region and populate __endpoint", () => {
const func = ai.beforeGenerateContent({ region: "us-central1" }, () => {});
expect(func.__endpoint.region).to.deep.equal(["us-central1"]);
});

it("should allow regional webhooks to specify a single location", () => {
ai.beforeGenerateContent({ regionalWebhook: true, region: "us-central1" }, () => {});
});

// Compilation failure tests (commented out):
// it("should NOT allow global webhooks to specify multiple locations", () => {
// ai.beforeGenerateContent({ region: ["us-central1", "europe-west1"] }, () => {});
// });
});
});
30 changes: 5 additions & 25 deletions src/v2/providers/ai/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ import { withInit } from "../../../common/onInit";
import { initV2Endpoint } from "../../../runtime/manifest";
import * as options from "../../options";

import { Expression } from "../../../params";
import { ResetValue } from "../../../common/options";
import * as logger from "../../../logger";

export { HttpsError };
Expand Down Expand Up @@ -83,22 +81,10 @@ export {
type GeminiV1BetaGenerateContentRequest,
type GeminiV1BetaGenerateContentResponse,
};
type MultipleLocationsIf<Allowed extends boolean> = Allowed extends true ? string[] : never;

/**
* Options for configuring AI webhook triggers.
*/
export interface WebhookOptions<Regional extends boolean = false>
extends Omit<EventHandlerOptions, "location"> {
/**
* Region where functions should be deployed. Deployed to `us-central1` by default.
*/
location?: string | Expression<string> | MultipleLocationsIf<Regional> | ResetValue;
/**
* Whether to handle regional webhooks.
*/
regionalWebhook?: Regional;
}
export interface WebhookOptions extends EventHandlerOptions {}

/**
* Metadata about the server prompt template used, if applicable.
Expand Down Expand Up @@ -239,8 +225,8 @@ export function beforeGenerateContent(
* @param callback - Event handler run before content generation.
* @returns A blocking function that can be exported and deployed.
*/
export function beforeGenerateContent<Regional extends boolean = false>(
options: WebhookOptions<Regional>,
export function beforeGenerateContent(
options: WebhookOptions,
callback: (
event: AIBlockingEvent<BeforeGenerateContentData>
) => MaybeAsync<void | Partial<AnyValidAIRequest>>
Expand Down Expand Up @@ -331,9 +317,6 @@ export function beforeGenerateContent(
},
blockingTrigger: {
eventType: beforeGenerateEventType,
options: {
regionalWebhook: opts.regionalWebhook,
},
},
};

Expand All @@ -357,8 +340,8 @@ export function afterGenerateContent(
* @param callback - Event handler run after content generation.
* @returns A blocking function that can be exported and deployed.
*/
export function afterGenerateContent<Regional extends boolean = false>(
options: WebhookOptions<Regional>,
export function afterGenerateContent(
options: WebhookOptions,
callback: (
event: AIBlockingEvent<AfterGenerateContentData>
) => MaybeAsync<void | Partial<AnyValidAIResponse>>
Expand Down Expand Up @@ -449,9 +432,6 @@ export function afterGenerateContent(
},
blockingTrigger: {
eventType: afterGenerateEventType,
options: {
regionalWebhook: opts.regionalWebhook,
},
},
};

Expand Down
5 changes: 1 addition & 4 deletions src/v2/providers/ai/types/gemini/v1beta/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,7 @@ export declare interface GenerateContentRequest extends BaseParams {
cachedContent?: string;
}
/**
* Individual response from `generateContent` and
* `generateContentStream`.
* `generateContentStream()` will return one in each chunk until
* the stream is done.
* Individual response from `generateContent`.
* @public
*/
export declare interface GenerateContentResponse {
Expand Down
5 changes: 0 additions & 5 deletions src/v2/providers/ai/types/vertex/v1beta1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,6 @@ export declare interface GenerateContentRequest extends BaseModelParams {
* This is the name of a `CachedContent` and not the cache object itself.
*/
cachedContent?: string;
/**
* Optional. Custom metadata labels for organizing API calls and managing costs at scale. See
* https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/add-labels-to-api-calls
*/
labels?: Record<string, string>;
}
/**
* Base params for initializing a model or calling GenerateContent.
Expand Down
Loading