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: Gemini and Bedrock for AI Proxy #7831

Merged
merged 12 commits into from
Sep 11, 2024
Merged
6 changes: 6 additions & 0 deletions app/_data/docs_nav_gateway_3.8.x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,12 @@ items:
url: /hub/kong-inc/ai-proxy/how-to/llm-provider-integration-guides/llama2/
generate: false
absolute_url: true
- text: AI Platform Integration Guides
items:
- text: Gemini
url: /hub/kong-inc/ai-proxy/how-to/machine-learning-platform-integration-guides/gemini/
generate: false
absolute_url: true
- text: AI Gateway Analytics
url: /ai-gateway/ai-analytics/
generate: false
Expand Down
4 changes: 4 additions & 0 deletions app/_data/tables/support/gateway/third-party.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,7 @@ _third_party:
- Raw
- OLLAMA
- OpenAI
bedrock: &bedrock
name: Amazon Bedrock
gemini: &gemini
name: Gemini
2 changes: 2 additions & 0 deletions app/_data/tables/support/gateway/versions/38.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,5 @@ third-party:
- *anthropic
- *mistral
- *llama2
- *bedrock
- *gemini
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
nav_title: Gemini
title: Set up AI Proxy Advanced with Gemini
---

This guide walks you through setting up the AI Proxy Advanced plugin with [Gemini](https://gemini.google.com/).

For all providers, the Kong AI Proxy Advanced plugin attaches to route entities.

## Prerequisites
* [{{site.base_gateway}} is installed and running](/gateway/latest/get-started/)
* [Create or retrieve an API key](https://ai.google.dev/gemini-api/docs/api-key) on the Google Cloud API Credentials Page to access Google’s AI services

## Configure the AI Proxy Advanced plugin

1. Create a service in {{site.base_gateway}} that will represent the Google Gemini API:
```sh
curl -i -X POST http://localhost:8001/services \
--data "name=gemini-service" \
--data "url=https://generativelanguage.googleapis.com"
```
1. Create a route that maps to the service you defined:
```sh
curl -i -X POST http://localhost:8001/routes \
--data "paths[]=/gemini" \
--data "service.id=$(curl -s http://localhost:8001/services/gemini-service | jq -r '.id')"
```
1. Use the Kong Admin API to configure the AI Proxy Advanced plugin to route requests to Google Gemini:
```sh
curl -i -X POST http://localhost:8001/services/gemini-service/plugins \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "ai-proxy-advanced",
"config": {
"targets": [
{
"route_type": "llm/v1/chat",
"auth": {
"param_name": "key",
"param_value": "<GEMINI_API_TOKEN>",
"param_location": "query"
},
"model": {
"provider": "gemini",
"name": "gemini-1.5-flash"
}
}
]
}
}
'
```

Be sure to replace `GEMINI_API_TOKEN` with your API token.

### Test the configuration

Make an `llm/v1/chat` type request to test your new endpoint:

```sh
curl -X POST http://localhost:8000/gemini \
-H 'Content-Type: application/json' \
--data-raw '{ "messages": [ { "role": "system", "content": "You are a mathematician" }, { "role": "user", "content": "What is 1+1?"} ] }'
```
10 changes: 9 additions & 1 deletion app/_hub/kong-inc/ai-proxy-advanced/overview/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ The following table describes which providers and requests the AI Proxy Advanced
| Mistral (mistral.ai, OpenAI, raw, and OLLAMA formats) | ✅ | ✅ | ✅ |
| Llama2 (raw, OLLAMA, and OpenAI formats) | ✅ | ✅ | ✅ |
| Llama3 (OLLAMA and OpenAI formats) | ✅ | ✅ | ✅ |
| Amazon Bedrock | ✅ | ✅ | ✅ |
| Gemini | ✅ | ✅ | ✅ |

## How it works

Expand Down Expand Up @@ -81,6 +83,11 @@ The plugin's [`config.route_type`](/hub/kong-inc/ai-proxy-advanced/configuration
| Llama2 | User-defined | `llm/v1/completions` | User-defined |
| Mistral | User-defined | `llm/v1/chat` | User-defined |
| Mistral | User-defined | `llm/v1/completions` | User-defined |
| Amazon Bedrock | Use the LLM `chat` upstream path | `llm/v1/chat` | [Use the model name for the specific LLM provider](https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html) |
| Amazon Bedrock | Use the LLM `completions` upstream path | `llm/v1/completions` | [Use the model name for the specific LLM provider](https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html) |
| Gemini | `llm/v1/chat` | `llm/v1/chat` | `gemini-1.5-flash` or `gemini-1.5-pro` |
| Gemini | `llm/v1/completions` | `llm/v1/completions` | `gemini-1.5-flash` or `gemini-1.5-pro` |


The following upstream URL patterns are used:

Expand All @@ -92,7 +99,8 @@ The following upstream URL patterns are used:
| Anthropic | `https://api.anthropic.com:443/{route_type_path}` |
| Llama2 | As defined in `config.model.options.upstream_url` |
| Mistral | As defined in `config.model.options.upstream_url` |

| Amazon Bedrock | `https://bedrock-runtime.{region}.amazonaws.com` |
| Gemini | `https://generativelanguage.googleapis.com` |

{:.important}
> While only the **Llama2** and **Mistral** models are classed as self-hosted, the target URL can be overridden for any of the supported providers.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
nav_title: Gemini
title: Set up AI Proxy with Gemini
---

This guide walks you through setting up the AI Proxy plugin with [Gemini](https://gemini.google.com/).

For all providers, the Kong AI Proxy plugin attaches to route entities.

## Prerequisites
* [{{site.base_gateway}} is installed and running](/gateway/latest/get-started/)
* [Create or retrieve an API key](https://ai.google.dev/gemini-api/docs/api-key) on the Google Cloud API Credentials Page to access Google’s AI services

## Configure the AI Proxy plugin

1. Create a service in {{site.base_gateway}} that will represent the Google Gemini API:
```sh
curl -i -X POST http://localhost:8001/services \
--data "name=gemini-service" \
--data "url=https://generativelanguage.googleapis.com"
```
1. Create a route that maps to the service you defined:
```sh
curl -i -X POST http://localhost:8001/routes \
--data "paths[]=/gemini" \
--data "service.id=$(curl -s http://localhost:8001/services/gemini-service | jq -r '.id')"
```
1. Use the Kong Admin API to configure the AI Proxy Plugin to route requests to Google Gemini:
```sh
curl -i -X POST http://localhost:8001/services/gemini-service/plugins \
--data 'name=ai-proxy' \
--data 'config.auth.param_name=key' \
--data 'config.auth.param_value=<GEMINI_API_TOKEN>' \
--data 'config.auth.param_location=query' \
--data 'config.route_type=llm/v1/chat' \
--data 'config.model.provider=gemini' \
--data 'config.model.name=gemini-1.5-flash'
```

Be sure to replace `GEMINI_API_TOKEN` with your API token.

### Test the configuration

Make an `llm/v1/chat` type request to test your new endpoint:

```sh
curl -X POST http://localhost:8000/gemini \
-H 'Content-Type: application/json' \
--data-raw '{ "messages": [ { "role": "system", "content": "You are a mathematician" }, { "role": "user", "content": "What is 1+1?"} ] }'
```
15 changes: 15 additions & 0 deletions app/_hub/kong-inc/ai-proxy/overview/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ The following table describes which providers and requests the AI Proxy plugin s
| Llama2 (raw, OLLAMA, and OpenAI formats) | ✅ | ✅ | ✅ |
| Llama3 (OLLAMA and OpenAI formats) | ✅ | ✅ | ✅ |
{% endif_version %}
{% if_version gte:3.8.x %}
| Amazon Bedrock | ✅ | ✅ | ✅ |
| Gemini | ✅ | ✅ | ✅ |
{% endif_version %}

## How it works

Expand Down Expand Up @@ -77,6 +81,13 @@ The plugin's [`config.route_type`](/hub/kong-inc/ai-proxy/configuration/#config-
| Mistral | User-defined | `llm/v1/chat` | User-defined |
| Mistral | User-defined | `llm/v1/completions` | User-defined |

{% if_version gte:3.8.x %}
| Amazon Bedrock | Use the LLM `chat` upstream path | `llm/v1/chat` | [Use the model name for the specific LLM provider](https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html) |
| Amazon Bedrock | Use the LLM `completions` upstream path | `llm/v1/completions` | [Use the model name for the specific LLM provider](https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html) |
| Gemini | `llm/v1/chat` | `llm/v1/chat` | `gemini-1.5-flash` or `gemini-1.5-pro` |
| Gemini | `llm/v1/completions` | `llm/v1/completions` | `gemini-1.5-flash` or `gemini-1.5-pro` |
{% endif_version %}

The following upstream URL patterns are used:

| Provider | URL |
Expand All @@ -88,6 +99,10 @@ The following upstream URL patterns are used:
| Llama2 | As defined in `config.model.options.upstream_url` |
| Mistral | As defined in `config.model.options.upstream_url` |

{% if_version gte:3.8.x %}
| Amazon Bedrock | `https://bedrock-runtime.{region}.amazonaws.com` |
| Gemini | `https://generativelanguage.googleapis.com` |
{% endif_version %}

{:.important}
> While only the **Llama2** and **Mistral** models are classed as self-hosted, the target URL can be overridden for any of the supported providers.
Expand Down
Loading