Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yukinagae/genkit-golang-cloud-functions-sample
Sample LLM app with Firebase Genkit, Golang, and Google Cloud Functions
https://github.com/yukinagae/genkit-golang-cloud-functions-sample
cloud-functions gemini genkit golang
Last synced: 11 days ago
JSON representation
Sample LLM app with Firebase Genkit, Golang, and Google Cloud Functions
- Host: GitHub
- URL: https://github.com/yukinagae/genkit-golang-cloud-functions-sample
- Owner: yukinagae
- Created: 2024-08-23T13:00:14.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-08-23T14:29:50.000Z (4 months ago)
- Last Synced: 2024-11-05T15:44:55.435Z (about 2 months ago)
- Topics: cloud-functions, gemini, genkit, golang
- Language: Go
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# genkit-golang-cloud-functions-sample
`genkit-golang-cloud-functions-sample` is a sample repository designed to help you learn how to build Large Language Model (LLM) applications using Firebase Genkit with Golang, deployed to Google Cloud Functions.
- [Requirements](#requirements)
- [Usage](#usage)
- [License](#license)## Requirements
- **Go**: Follow the [Go - Download and install](https://go.dev/doc/install) to install Go.
- **Genkit**: Follow the [Firebase Genkit - Get started](https://firebase.google.com/docs/genkit/get-started) to install Genkit.
- **Google Cloud CLI (gcloud)**: Follow the [Google Cloud - Install the gcloud CLI](https://cloud.google.com/sdk/docs/install) to install gcloud.
- **Docker**: Follow the [Docker - Install Docker Engine](https://docs.docker.com/engine/install/) to install Docker.
- **Pack**: Follow the [Buildpacks.io - Pack](https://buildpacks.io/docs/for-platform-operators/how-to/integrate-ci/pack/) to install Pack.
- **golangci-lint**: Follow the [golangci-lint - Install](https://golangci-lint.run/welcome/install/) to install golangci-lint.Verify your installations:
```bash
$ go version
v22.4.1
$ genkit --version
0.5.4
$ gcloud --version
Google Cloud SDK 489.0.0
alpha 2024.08.16
bq 2.1.8
core 2024.08.16
gcloud-crc32c 1.0.0
gsutil 5.30
$ docker --version
Docker version 20.10.20, build 9fdeb9c
$ docker ps # make sure docker is running
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
$ pack --version
0.35.1+git-3a22a7f.build-6099
$ golangci-lint --version
golangci-lint has version 1.60.3 built with go1.23.0 from c2e095c on 2024-08-22T21:45:24Z
```## Usage
### Run Genkit
Set your API key and start Genkit:
```bash
$ export GOOGLE_GENAI_API_KEY=your_api_key
$ make genkit # Starts Genkit
```Open your browser and navigate to [http://localhost:4000](http://localhost:4000) to access the Genkit UI.
### Run HTTP Server Locally
To start the local http server, run the following command:
```bash
$ make dev
```To test the function, use the following curl command:
```bash
$ curl -X POST -H "Content-Type: application/json" \
-d '{"url":"https://firebase.blog/posts/2024/04/next-announcements/"}' http://localhost:8080
Firebase announces new updates, including vector search for Firestore, Vertex AI SDKs, and public preview of Gemini.
```## Run Cloud Functions Emulator
**Note**: To enable alpha components, run the following command:
```bash
$ gcloud components install alpha
```To run the emulator, set your secret values in `./.env.yaml`:
```bash
$ cp -p ./.env.example.yaml ./.env.yaml
$ vim ./.env.yaml # replace the secrets with your own values
GOOGLE_GENAI_API_KEY: your_api_key
```To start the emulator, run the following command:
```bash
$ make start-emulator
```To test the function on the emulator, use the following gcloud or curl command:
```bash
$ gcloud alpha functions local call summarize-function --data='{"url": "https://firebase.blog/posts/2024/04/next-announcements/"}'
# or
$ curl -X POST -H "Content-Type: application/json" \
-d '{"url":"https://firebase.blog/posts/2024/04/next-announcements/"}' http://localhost:8080
```To remove the emulator, run the following command:
```bash
$ make remove-emulator
```### Deploy
Follow these steps to deploy the function:
```bash
$ gcloud auth application-default login
$ gcloud config set core/project [your-project-id]
$ make deploy
```**CAUTION**: This deployment uses `.env.yaml` for environment variables, including the API key. This is not recommended for production. Instead, use Google Cloud Secret Manager for better security.
To test the deployed function, use the following curl command:
```bash
$ curl -X POST -H "Content-Type: application/json" \
-d '{"url":"https://firebase.blog/posts/2024/04/next-announcements/"}' \
https://us-central1-[your-project-id].cloudfunctions.net/summarize-function
```### Code Formatting
To ensure your code is properly formatted, run the following command:
```bash
$ make tidy
```## License
MIT