Skip to content
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

feat: Add gemini sample #132

Merged
merged 11 commits into from
Dec 25, 2024
67 changes: 67 additions & 0 deletions samples/google/gemini/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
title: Gemini
description: Simple usage of Gemini API
mario99logic marked this conversation as resolved.
Show resolved Hide resolved
integrations: ["gemini"]
categories: ["Samples"]
---

# Gemini Sample

This [AutoKitteh](https://github.com/autokitteh/autokitteh) project
demonstrates integration with [Gemini](https://gemini.google.com).

It sends a couple of requests to the Gemini API, and prints the responses
back to the user.

API details:

- [Gemini API](https://ai.google.dev)
- [Python client library](https://github.com/google-gemini/generative-ai-python/blob/main/docs/api/google/generativeai.md)

## How It Works

1. Send an HTTP GET request to trigger the workflow.
2. The workflow prints the responses of Gemini
mario99logic marked this conversation as resolved.
Show resolved Hide resolved

## Deployment & Configuration

### Cloud Usage

- Initialize your connection with Gemini through the UI

daabr marked this conversation as resolved.
Show resolved Hide resolved
### self-hosted
mario99logic marked this conversation as resolved.
Show resolved Hide resolved

#### Prerequisites

- [Install AutoKitteh](https://docs.autokitteh.com/get_started/install)

#### Installation Steps

1. Clone the repository:
```shell
git clone https://github.com/autokitteh/kittehub.git
cd kittehub/samples/google/gemini
```

2. Start the AutoKitteh server:
```shell
ak up --mode dev
```

3. Deploy the project:
```shell
ak deploy --manifest autokitteh.yaml
```

The output will show your connection IDs, which you'll need for the next step. Look for lines like:
```shell
[exec] create_connection "gemini_sample/gemini_connection": con_01je39d6frfdtshstfg5qpk8sz created
```

In this example, `con_01je39d6frfdtshstfg5qpk8sz` is the connection ID.

4. Initialize your connections using the CLI:
```shell
ak connection init gemini_connection <connection ID>
```

15 changes: 15 additions & 0 deletions samples/google/gemini/autokitteh.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This YAML file is a declarative manifest that describes the setup
# of an AutoKitteh project that demonstrates integration with Gemini
mario99logic marked this conversation as resolved.
Show resolved Hide resolved

version: v1

project:
name: gemini_sample
connections:
- name: gemini_connection
mario99logic marked this conversation as resolved.
Show resolved Hide resolved
integration: googlegemini
triggers:
- name: on_http_get
type: webhook
event_type: get
call: program.py:on_http_get
36 changes: 36 additions & 0 deletions samples/google/gemini/program.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
Demonstration of AutoKitteh's Gemini integration.
mario99logic marked this conversation as resolved.
Show resolved Hide resolved

A single entry-point function is implemented, it sends a couple of requests to the Gemini API, and prints the responses
daabr marked this conversation as resolved.
Show resolved Hide resolved
in the AutoKitteh session log.
"""

from autokitteh.google import gemini_client

MODEL = "gemini-1.5-flash"

gemini = gemini_client("gemini_connection", model_name=MODEL)


def on_http_get(event):
"""Entry-point function for handling HTTP GET requests in this workflow."""
# Example 1: trivial interaction with Gemini
mario99logic marked this conversation as resolved.
Show resolved Hide resolved
prompt = "say meow in different languages"
response = gemini.generate_content(prompt)

mario99logic marked this conversation as resolved.
Show resolved Hide resolved
print(response.text)

# Example 2: interactive chat using the Gemini
mario99logic marked this conversation as resolved.
Show resolved Hide resolved
chat = gemini.start_chat(
history=[
{"role": "user", "parts": "Hello"},
{
"role": "model",
"parts": "Great to meet you. What would you like to know?",
},
]
)
response = chat.send_message("I have 2 cats in my house.")
print(response.text)
response = chat.send_message("How many paws are in my house?")
print(response.text)
Loading