This a fully functioning example project for serverless Generative AI-as-a-Service and combining the apps and ecosystems of Google and Apple for practical automation and use cases.
Learn how to use Google Gemini, Apple Siri, and Google's serverless Google Cloud Run Functions together.
When deployed, this project is a self-contained scalable serverless environment for Generative AI in google cloud using google cloud run functions. While you are likely familiar with serverless web services, for the purposes of this project this means that you do not have to maintain servers and infrastructure. Google Cloud Platform (GCP) handles horizontal scaling, and you only pay for the time and resources used (which is perfect for a project like this or many types of large scale services). In many cases, running this project and services within GCP will be completely free if you are within the free tier limits.
This project and the associated videos also show a practical use case of calling google cloud run functions from apps and clients like Apple Shortcuts.
- Yes, anyone can run script on iOS with the built-in workflow app Apple Shortcuts (which is available on iOS, iPadOS, macOS, tabletOS, and watchOS).
- Yes, this is using Gemini and Siri together.
- Yes, this has function calling to enable Gemini to have access to Google search results.
Watch the intro and overview video, https://youtu.be/WUHeLYqgo3w.
Watch the longer explainer video for additional background and context, https://youtu.be/zqkeiW9V5ew.
It even mentions HyperCard.
- π Python 3.12 or greater
- Google Cloud CLI
- Google Gemini API Key
- Clone this repository locally
- Set up a
virtual environmentfrom the local directory that the repository was cloned into from the command-line:$ python3 -m pip install virtualenv $ python3 -m virtualenv venv
Note
virtual environments may be created in a different way, depending on your python installation and configuration. For example, for some setups the virtual environment setup will look similar to this without a python version and using the venv package:
$ python -m venv venv-
Activate the
virtual environmentfrom within the directory of the local repository:$ venv/bin/activate # Note: The relative path to the activate script # may be at a location like the following: # $ venv\scripts\activate # Optionally, you may run one of the `activate` # script helper files in the top-level directory # of the source for this repository. # For example, on `windows` run `activate.bat` # from the command-line (which this will do): # > activate
-
If you do not already have the
google cloud cliinstalled and configured on your system:
- Install the
google cloud cli(akagcloud cli,google cloud sdk)- https://cloud.google.com/sdk/docs/install-sdk
- Setup or configure the
gcloud cli
gcloud init- You may need to enable the Google Cloud APIs and capabilities for
artifact registry,cloud build,cloud run admin, andcloud loggingfor yourgoogle cloud project.
- Get/set your
GEMINI_API_KEY. Create a new API key atgoogle cloudif you do not already have API a key(s).
- See: https://ai.google.dev/gemini-api/docs/api-key and/or https://aistudio.google.com/app/apikey
- Copy the key to a storage mechanism of your choice
- Set the value for
gemini_api_keyorgemini_api_key_fallback = "REPLACE_WITH_YOUR_GEMINI_API_KEY"to yourGEMINI_API_KEY.- Optionally, set the
GEMINI_API_KEYenvironment variable in a manner that is accessible within a Google Cloud Run Function
- Optionally, set the
- Install the requirements needed to run the application locally with the following command from the same activated
virtual environmentcommand-line window:
$ pip install -r requirements.txtThe following will create a serverless Google Cloud Run Function in the Google Cloud Platform (GCP) and give you a URL that is externally accessible.
- Run the following command (it will error if you do not have the
Google Cloud/gcloud CLIconfigured locally) from an activatedvirtual environmentcommand-line window:
Note
The list of available Google Cloud regions and zones is available at: https://cloud.google.com/compute/docs/regions-zones
gcloud functions deploy cloud-jokes \
--gen2 \
--region=REPLACE_WITH_YOUR_REGION_OF_CHOICE \
--runtime=python312 \
--source=. \
--entry-point=my_cloud_function \
--trigger-httpor
gcloud functions deploy cloud-jokes --gen2 --region=REPLACE_WITH_YOUR_REGION_OF_CHOICE --runtime=python312 --source=. --entry-point=my_cloud_function --trigger-httpThe command line output will look similar to the following as the service deploys:
Preparing function...
state: ACTIVE
url: https://{your-region}-{generated-function-instance-name}.cloudfunctions.net/cloud-jokesNote
The externally accessible function invocation URL will have a format and pattern similar to: https://{your-region}-{generated-function-instance-name}.cloudfunctions.net/{your-function-name}
The URL that is provided as part of the deploy or update process is a publicly accessible URL that you may access, share, run, etc. π
- If you make any changes to the service and wish to redeploy it (and replace all running instances) then just re-run deploy command you used to originally deploy the service from an activated
virtual environmentcommand-line window
Note
To teardown the resources (deprovision) and make the URL inaccessible run the gcloud function delete command:
$ gcloud functions delete cloud-jokes --region={REPLACE_WITH_YOUR_REGION_OF_CHOICE}Generate AI or Large Language Model (LLM) output at the /cloud-jokes route, e.g. https://{your-region}-{generated-function-instance-name}.cloudfunctions.net/cloud-jokes. You may also customize the prompt by appending the ?prompt=<value of prompt> querystring like https://{your-region}-{generated-function-instance-name}.cloudfunctions.net/cloud-jokes?prompt=What is the meaning of life?.
Click/tap the video link to learn more about how to call google cloud run functions from Apple Shortcuts.
Tip
If you want to use a different voice for siri on your ios and Apple-related operating system, navigate to Settings -> Accessibility -> Spoken Content -> Voices -> {Language: English} and select from the list of available voices.

