Skip to content

feat(ai): Add support for AbortSignal #8890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Conversation

dlarocque
Copy link
Contributor

@dlarocque dlarocque commented Apr 2, 2025

Add an AbortSignal to a new SingleRequestOptions that can be passed to all methods that make requests to the backend, allowing them to be aborted.

Fixes #8859

API Proposal: go/vinf-abort-request-api (internal)

Copy link

changeset-bot bot commented Apr 2, 2025

🦋 Changeset detected

Latest commit: 931972d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
firebase Minor
@firebase/ai Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Apr 2, 2025

Changeset File Check ✅

  • No modified packages are missing from the changeset file.
  • No changeset formatting errors detected.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Apr 2, 2025

Size Report 1

Affected Products

  • @firebase/ai

    TypeBase (40be2db)Merge (37bdd41)Diff
    browser42.5 kB43.9 kB+1.40 kB (+3.3%)
    main43.7 kB45.1 kB+1.40 kB (+3.2%)
    module42.5 kB43.9 kB+1.40 kB (+3.3%)
  • firebase

    TypeBase (40be2db)Merge (37bdd41)Diff
    firebase-ai.js33.8 kB34.5 kB+717 B (+2.1%)
    firebase-vertexai.js33.8 kB34.5 kB+717 B (+2.1%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/yNYEnbRZFj.html

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Apr 2, 2025

Size Analysis Report 1

Affected Products

  • @firebase/ai

    • ChatSession

      Size

      TypeBase (40be2db)Merge (37bdd41)Diff
      size20.0 kB20.5 kB+517 B (+2.6%)
      size-with-ext-deps39.0 kB39.5 kB+516 B (+1.3%)

      Dependency

      TypeBase (40be2db)Merge (37bdd41)Diff
      variables

      32 dependencies

      AI_TYPE
      BackendType
      BlockReason
      DEFAULT_API_VERSION
      DEFAULT_BASE_URL
      DEFAULT_FETCH_TIMEOUT_MS
      DEFAULT_LOCATION
      FinishReason
      FunctionCallingMode
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      ImagenAspectRatio
      ImagenPersonFilterLevel
      ImagenSafetyFilterLevel
      LANGUAGE_TAG
      Modality
      PACKAGE_VERSION
      POSSIBLE_ROLES
      SILENT_ERROR
      SchemaType
      Task
      VALID_PARTS_PER_ROLE
      VALID_PART_FIELDS
      VALID_PREVIOUS_CONTENT_ROLES
      badFinishReasons
      logger
      name
      responseLineRE
      version

      34 dependencies

      ABORT_ERROR_NAME
      AI_TYPE
      BackendType
      BlockReason
      DEFAULT_API_VERSION
      DEFAULT_BASE_URL
      DEFAULT_FETCH_TIMEOUT_MS
      DEFAULT_LOCATION
      FinishReason
      FunctionCallingMode
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      ImagenAspectRatio
      ImagenPersonFilterLevel
      ImagenSafetyFilterLevel
      LANGUAGE_TAG
      Modality
      PACKAGE_VERSION
      POSSIBLE_ROLES
      SILENT_ERROR
      SchemaType
      TIMEOUT_EXPIRED_MESSAGE
      Task
      VALID_PARTS_PER_ROLE
      VALID_PART_FIELDS
      VALID_PREVIOUS_CONTENT_ROLES
      badFinishReasons
      logger
      name
      responseLineRE
      version

      + ABORT_ERROR_NAME
      + TIMEOUT_EXPIRED_MESSAGE

    • GenerativeModel

      Size

      TypeBase (40be2db)Merge (37bdd41)Diff
      size23.6 kB24.3 kB+655 B (+2.8%)
      size-with-ext-deps42.6 kB43.3 kB+647 B (+1.5%)

      Dependency

      TypeBase (40be2db)Merge (37bdd41)Diff
      variables

      32 dependencies

      AI_TYPE
      BackendType
      BlockReason
      DEFAULT_API_VERSION
      DEFAULT_BASE_URL
      DEFAULT_FETCH_TIMEOUT_MS
      DEFAULT_LOCATION
      FinishReason
      FunctionCallingMode
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      ImagenAspectRatio
      ImagenPersonFilterLevel
      ImagenSafetyFilterLevel
      LANGUAGE_TAG
      Modality
      PACKAGE_VERSION
      POSSIBLE_ROLES
      SILENT_ERROR
      SchemaType
      Task
      VALID_PARTS_PER_ROLE
      VALID_PART_FIELDS
      VALID_PREVIOUS_CONTENT_ROLES
      badFinishReasons
      logger
      name
      responseLineRE
      version

      34 dependencies

      ABORT_ERROR_NAME
      AI_TYPE
      BackendType
      BlockReason
      DEFAULT_API_VERSION
      DEFAULT_BASE_URL
      DEFAULT_FETCH_TIMEOUT_MS
      DEFAULT_LOCATION
      FinishReason
      FunctionCallingMode
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      ImagenAspectRatio
      ImagenPersonFilterLevel
      ImagenSafetyFilterLevel
      LANGUAGE_TAG
      Modality
      PACKAGE_VERSION
      POSSIBLE_ROLES
      SILENT_ERROR
      SchemaType
      TIMEOUT_EXPIRED_MESSAGE
      Task
      VALID_PARTS_PER_ROLE
      VALID_PART_FIELDS
      VALID_PREVIOUS_CONTENT_ROLES
      badFinishReasons
      logger
      name
      responseLineRE
      version

      + ABORT_ERROR_NAME
      + TIMEOUT_EXPIRED_MESSAGE

    • ImagenModel

      Size

      TypeBase (40be2db)Merge (37bdd41)Diff
      size11.3 kB11.8 kB+510 B (+4.5%)
      size-with-ext-deps29.3 kB29.9 kB+516 B (+1.8%)

      Dependency

      TypeBase (40be2db)Merge (37bdd41)Diff
      variables

      25 dependencies

      AI_TYPE
      BackendType
      BlockReason
      DEFAULT_API_VERSION
      DEFAULT_BASE_URL
      DEFAULT_FETCH_TIMEOUT_MS
      DEFAULT_LOCATION
      FinishReason
      FunctionCallingMode
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      ImagenAspectRatio
      ImagenPersonFilterLevel
      ImagenSafetyFilterLevel
      LANGUAGE_TAG
      Modality
      PACKAGE_VERSION
      SchemaType
      Task
      logger
      name
      version

      27 dependencies

      ABORT_ERROR_NAME
      AI_TYPE
      BackendType
      BlockReason
      DEFAULT_API_VERSION
      DEFAULT_BASE_URL
      DEFAULT_FETCH_TIMEOUT_MS
      DEFAULT_LOCATION
      FinishReason
      FunctionCallingMode
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      ImagenAspectRatio
      ImagenPersonFilterLevel
      ImagenSafetyFilterLevel
      LANGUAGE_TAG
      Modality
      PACKAGE_VERSION
      SchemaType
      TIMEOUT_EXPIRED_MESSAGE
      Task
      logger
      name
      version

      + ABORT_ERROR_NAME
      + TIMEOUT_EXPIRED_MESSAGE

    • getGenerativeModel

      Size

      TypeBase (40be2db)Merge (37bdd41)Diff
      size23.8 kB24.4 kB+655 B (+2.8%)
      size-with-ext-deps42.8 kB43.4 kB+647 B (+1.5%)

      Dependency

      TypeBase (40be2db)Merge (37bdd41)Diff
      variables

      32 dependencies

      AI_TYPE
      BackendType
      BlockReason
      DEFAULT_API_VERSION
      DEFAULT_BASE_URL
      DEFAULT_FETCH_TIMEOUT_MS
      DEFAULT_LOCATION
      FinishReason
      FunctionCallingMode
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      ImagenAspectRatio
      ImagenPersonFilterLevel
      ImagenSafetyFilterLevel
      LANGUAGE_TAG
      Modality
      PACKAGE_VERSION
      POSSIBLE_ROLES
      SILENT_ERROR
      SchemaType
      Task
      VALID_PARTS_PER_ROLE
      VALID_PART_FIELDS
      VALID_PREVIOUS_CONTENT_ROLES
      badFinishReasons
      logger
      name
      responseLineRE
      version

      34 dependencies

      ABORT_ERROR_NAME
      AI_TYPE
      BackendType
      BlockReason
      DEFAULT_API_VERSION
      DEFAULT_BASE_URL
      DEFAULT_FETCH_TIMEOUT_MS
      DEFAULT_LOCATION
      FinishReason
      FunctionCallingMode
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      ImagenAspectRatio
      ImagenPersonFilterLevel
      ImagenSafetyFilterLevel
      LANGUAGE_TAG
      Modality
      PACKAGE_VERSION
      POSSIBLE_ROLES
      SILENT_ERROR
      SchemaType
      TIMEOUT_EXPIRED_MESSAGE
      Task
      VALID_PARTS_PER_ROLE
      VALID_PART_FIELDS
      VALID_PREVIOUS_CONTENT_ROLES
      badFinishReasons
      logger
      name
      responseLineRE
      version

      + ABORT_ERROR_NAME
      + TIMEOUT_EXPIRED_MESSAGE

    • getImagenModel

      Size

      TypeBase (40be2db)Merge (37bdd41)Diff
      size11.5 kB12.0 kB+510 B (+4.4%)
      size-with-ext-deps29.5 kB30.0 kB+516 B (+1.7%)

      Dependency

      TypeBase (40be2db)Merge (37bdd41)Diff
      variables

      25 dependencies

      AI_TYPE
      BackendType
      BlockReason
      DEFAULT_API_VERSION
      DEFAULT_BASE_URL
      DEFAULT_FETCH_TIMEOUT_MS
      DEFAULT_LOCATION
      FinishReason
      FunctionCallingMode
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      ImagenAspectRatio
      ImagenPersonFilterLevel
      ImagenSafetyFilterLevel
      LANGUAGE_TAG
      Modality
      PACKAGE_VERSION
      SchemaType
      Task
      logger
      name
      version

      27 dependencies

      ABORT_ERROR_NAME
      AI_TYPE
      BackendType
      BlockReason
      DEFAULT_API_VERSION
      DEFAULT_BASE_URL
      DEFAULT_FETCH_TIMEOUT_MS
      DEFAULT_LOCATION
      FinishReason
      FunctionCallingMode
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      ImagenAspectRatio
      ImagenPersonFilterLevel
      ImagenSafetyFilterLevel
      LANGUAGE_TAG
      Modality
      PACKAGE_VERSION
      SchemaType
      TIMEOUT_EXPIRED_MESSAGE
      Task
      logger
      name
      version

      + ABORT_ERROR_NAME
      + TIMEOUT_EXPIRED_MESSAGE

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/uPl3IpmhV0.html

Copy link
Contributor

github-actions bot commented Apr 2, 2025

Vertex AI Mock Responses Check ⚠️

A newer major version of the mock responses for Vertex AI unit tests is available. update_vertexai_responses.sh should be updated to clone the latest version of the responses: v8.0

@dlarocque dlarocque marked this pull request as ready for review May 12, 2025 17:05
@dlarocque dlarocque requested review from a team as code owners May 12, 2025 17:05
Copy link
Contributor

@DellaBitta DellaBitta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but won't approve until council review.


If provided, calling `abort()` on the corresponding `AbortController` will attempt to cancel the underlying HTTP request. An `AbortError` will be thrown if cancellation is successful.

Note that this will not cancel the request in the backend, so billing will still be applied despite cancellation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

@hsubox76 hsubox76 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, pending merge of #9011 where you'll have to update the changeset and regenerate docs and the api.md.

@dlarocque dlarocque requested a review from rachelsaunders May 22, 2025 15:11
@dlarocque dlarocque requested a review from aashishpatil-g as a code owner May 22, 2025 15:27
@dlarocque dlarocque requested a review from rachelsaunders May 27, 2025 14:49
@dlarocque dlarocque changed the title feat(vertexai): Add support for AbortSignal feat(ai): Add support for AbortSignal May 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FR: Support AbortSignal in generateContent() for firebase/vertexai
5 participants