# Learn detailed information about the fields of an extension.yaml file in the docs:
# https://firebase.google.com/docs/extensions/alpha/ref-extension-yaml

name: firestore-palm-summarize-text # Identifier for your extension
version: 0.1.11 # Follow semver versioning
specVersion: v1beta # Version of the Firebase Extensions specification

# Friendly display name for your extension (~3-5 words)
displayName: Summarize Text with PaLM API

# Brief description of the task your extension performs (~1 sentence)
description: >-
  Summarizes text in Firestore documents using PaLM API.

license: Apache-2.0 # https://spdx.org/licenses/

icon: icon.png

tags:
  [
    ai,
    palm,
    summarization-api,
    generative-ai,
    text-ai,
    language-ai,
    large-language-models,
    llm,
    nlp,
    google-ai,
  ]

author:
  authorName: Google Cloud
  url: https://cloud.google.com/

contributors:
  - authorName: Invertase
    email: oss@invertase.io
    url: https://github.com/invertase

# Public URL for the source code of your extension
sourceUrl: https://github.com/GoogleCloudPlatform/firebase-extensions/tree/main/firestore-palm-summarize-text
releaseNotesUrl: https://github.com/GoogleCloudPlatform/firebase-extensions/tree/main/firestore-palm-summarize-text/CHANGELOG.md
# Specify whether a paid-tier billing plan is required to use your extension.
# Learn more in the docs: https://firebase.google.com/docs/extensions/alpha/ref-extension-yaml#billing-required-field
billingRequired: true

# In an `apis` field, list any Google APIs (like Cloud Translation, BigQuery, etc.)
# required for your extension to operate.
# Learn more in the docs: https://firebase.google.com/docs/extensions/alpha/ref-extension-yaml#apis-field
apis:
  - apiName: aiplatform.googleapis.com
    reason: For access to the PaLM API if the Vertex AI PaLM provider is chosen.
# In a `roles` field, list any IAM access roles required for your extension to operate.
# Learn more in the docs: https://firebase.google.com/docs/extensions/alpha/ref-extension-yaml#roles-field
roles:
  - role: datastore.user
    reason:
      Allows this extension to access Cloud Firestore to read and process added
      text.

  - role: aiplatform.user
    reason:
      Allows this extension to access the PaLM API via Vertex AI if this
      provider is chosen.

# In the `resources` field, list each of your extension's functions, including the trigger for each function.
# Learn more in the docs: https://firebase.google.com/docs/extensions/alpha/ref-extension-yaml#resources-field
resources:
  - name: generateSummary
    type: firebaseextensions.v1beta.function
    description: >-
      Listens to Firestore data writes to generate summaries.
    properties:
      # LOCATION is a user-configured parameter value specified by the user during installation.
      location: ${LOCATION}
      # httpsTrigger is used for an HTTP triggered function.
      eventTrigger:
        eventType: providers/cloud.firestore/eventTypes/document.write
        resource: projects/${PROJECT_ID}/databases/(default)/documents/${COLLECTION_NAME}/{summaryId}
      runtime: 'nodejs18'

# In the `params` field, set up your extension's user-configured parameters.
# Learn more in the docs: https://firebase.google.com/docs/extensions/alpha/ref-extension-yaml#params-field
params:
  - param: PALM_API_PROVIDER
    label: Palm API Provider
    description: >-
      There are two services which provide access to the PaLM API. Which would
      you like to use? If Vertex AI is selected, the service will be
      automatically enabled. If Generative Language is selected, you can provide
      an API key obtained through MakerSuite or your GCP console, or use
      Application Default Credentials if the Generative Language AI is enabled
      in your google cloud project.
    type: select
    options:
      - label: Vertex AI
        value: vertex
      - label: Generative Language AI for Developers
        value: generative
    required: true
    default: vertex
    immutable: false

  - param: API_KEY
    label: API Key (Generative Language AI for Developers Provider ONLY)
    description: >-
      If you selected Generative AI for Developers as your PaLM API provider,
      you can optionally choose to provide an API key. If you do not provide an
      API key, the extension will use Application Default Credentials, but will
      need the service enabled in GCP.
    type: secret
    required: false
    immutable: false

  - param: COLLECTION_NAME
    label: Collection Name
    description: >-
      Path to the Firestore collection where messages will be generated.
    type: string
    validationRegex: '^[^/]+(/[^/]+/[^/]+)*$'
    validationErrorMessage: Must be a valid Cloud Firestore Collection
    example: text_documents
    required: true
    immutable: false

  - param: TEXT_FIELD
    label: Text field
    description: >-
      The field of the document containing text to summarize.
    type: string
    default: text
    required: true
    immutable: false

  - param: RESPONSE_FIELD
    label: Response Field
    description: >-
      The field in the message document into which to put the response.
    type: string
    default: summary
    required: true
    immutable: false

  - param: TARGET_SUMMARY_LENGTH
    label: Target Summary Length
    description: >-
      Number of sentences you would like the summary to be.
    type: string
    example: 10
    validationRegex: ^([1-9]|10)$
    validationErrorMessage:
      Invalid TARGET_SUMMARY_LENGTH, must be an integer between 1 and 10.
    required: false
    immutable: false

  - param: MAX_OUTPUT_TOKENS
    label: Maximum number of tokens
    description: >-
      If you have selected the Vertex AI service as your PaLM API provider, this
      parameter will be used to set the max_tokens parameter in the Vertex API
      request. It should be an integer in the range [1,1024]. The default value
      for the extension is 1024.
    type: string
    validationRegex: ^(102[0-4]|10[01][0-9]|100[0-9]|[1-9][0-9]{0,2})$
    validationErrorMessage: Please specify an integer in the range [1,1024]
    required: false
    default: 1024
    immutable: false

  - param: CONTENT_FILTER_THRESHOLD
    label: Content Filter Threshold
    description: >-
      Threshold for harmful content. Specify what level of harmful content is
      blocked by the PaLM provider. This threshold is applicable only to the
      Generative Language PaLM API.
    type: select
    options:
      - label: Default
        value: HARM_BLOCK_THRESHOLD_UNSPECIFIED
      - label: Block low and above
        value: BLOCK_LOW_AND_ABOVE
      - label: Block medium and above
        value: BLOCK_MEDIUM_AND_ABOVE
      - label: Block only high
        value: BLOCK_ONLY_HIGH
      - label: Block none
        value: BLOCK_NONE
    required: false
    default: HARM_BLOCK_THRESHOLD_UNSPECIFIED
    immutable: false

  - param: LOCATION
    label: Cloud Functions location
    description: >-
      Where do you want to deploy the functions created for this extension? For
      help selecting a location, refer to the [location selection
      guide](https://firebase.google.com/docs/functions/locations).
    type: select
    options:
      - label: Iowa (us-central1)
        value: us-central1
      - label: South Carolina (us-east1)
        value: us-east1
      - label: Northern Virginia (us-east4)
        value: us-east4
      - label: Los Angeles (us-west2)
        value: us-west2
      - label: Salt Lake City (us-west3)
        value: us-west3
      - label: Las Vegas (us-west4)
        value: us-west4
      - label: Warsaw (europe-central2)
        value: europe-central2
      - label: Belgium (europe-west1)
        value: europe-west1
      - label: London (europe-west2)
        value: europe-west2
      - label: Frankfurt (europe-west3)
        value: europe-west3
      - label: Zurich (europe-west6)
        value: europe-west6
      - label: Hong Kong (asia-east2)
        value: asia-east2
      - label: Tokyo (asia-northeast1)
        value: asia-northeast1
      - label: Osaka (asia-northeast2)
        value: asia-northeast2
      - label: Seoul (asia-northeast3)
        value: asia-northeast3
      - label: Mumbai (asia-south1)
        value: asia-south1
      - label: Jakarta (asia-southeast2)
        value: asia-southeast2
      - label: Montreal (northamerica-northeast1)
        value: northamerica-northeast1
      - label: Sao Paulo (southamerica-east1)
        value: southamerica-east1
      - label: Sydney (australia-southeast1)
        value: australia-southeast1
    required: true
    immutable: true
