generative-ts

Function createVertexAiModelProvider

  • Creates a Google Cloud VertexAI ModelProvider with the GoogleGeminiApi.

    import { createVertexAiModelProvider } from "@packages/gcloud-vertex-ai";

    const gemini = await createVertexAiModelProvider({
    modelId: "gemini-1.0-pro", // VertexAI defined model ID
    // you can explicitly pass auth here, otherwise by default it is read from process.env
    });

    const response = await gemini.sendRequest({
    $prompt: "Brief History of NY Mets:",
    // all other Gemini options available here
    });

    console.log(response.data.candidates[0]);

    Provider Setup and Notes

    Enable VertexAI in your Google Cloud Console. Note: VertexAI is currently only available in certain regions.

    By default, this provider uses Google Cloud Application Default Credentials, meaning auth credentials will be found automatically based on the application environment. This is the preferred method of authentication if your app is running in Google Cloud.

    Please follow instructions in "Set up Application Default Credentials" to set up ADC credentials.

    If you pass in a custom client, Application Default Credentials will NOT be used, and auth logic will be left to the custom client. See google-auth-library for possible strategies about different ways to authenticate.

    If you do not pass a VertexAiAuthConfig to auth, the values will be read from the environment as GCLOUD_LOCATION and GCLOUD_PROJECT_ID.

    Model Parameters

    Model IDs

    Type Parameters

    • THttpClientOptions = HttpClientOptions

    Parameters

    • params: {
          auth?: VertexAiAuthConfig;
          client?: HttpClient<THttpClientOptions>;
          modelId: string;
      }
      • Optional auth?: VertexAiAuthConfig

        Authorization configuration for VertexAI. If not supplied, it will be loaded from the environment.

      • Optional client?: HttpClient<THttpClientOptions>

        HTTP client to use for requests. If not supplied, a client implementing Google Cloud Application Default Credentials will be used.

      • modelId: string

        The model ID as defined by Google Cloud VertexAI.

    Returns Promise<any>

    The VertexAI Model Provider

    See

    Throws

    If no auth is passed and GCLOUD_LOCATION or GCLOUD_PROJECT_ID are not found in process.env

    Example: Usage

    import { createVertexAiModelProvider } from "@packages/gcloud-vertex-ai";

    const gemini = await createVertexAiModelProvider({
    modelId: "gemini-1.0-pro", // VertexAI defined model ID
    // you can explicitly pass auth here, otherwise by default it is read from process.env
    });

    const response = await gemini.sendRequest({
    $prompt: "Brief History of NY Mets:",
    // all other Gemini options available here
    });

    console.log(response.data.candidates[0]);