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

Add VertexAI extension #4428

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions docs/src/pages/docs/remote-models/vertexai.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
title: VertexAI API
description: A step-by-step guide on integrating Jan with VertexAI.
keywords:
[
Jan,
Customizable Intelligence, LLM,
local AI,
privacy focus,
free and open source,
private and offline,
conversational AI,
no-subscription fee,
large language models,
integration,
VertexAI,
Google,
GCP
]
---

import { Callout, Steps } from 'nextra/components'



# VertexAI API

<Callout type='info'>
The VertexAI Extension can be used select models that [support the openai endpoints](https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/call-vertex-using-openai-library) on vertexAI's.
</Callout>

## How to Integrate VertexAI API with Jan
This guide provides step-by-step instructions for integrating the VertexAI API with Jan, allowing users to utilize VertexAI's capabilities within Jan's conversational interface.

## Integration Steps
<Steps>
### Step 1: Configure GCP Service Account
1. Open the [Credentials page](https://console.cloud.google.com/apis/credentials) in GCP
2. Select your project
3. Create Credentials -> Service Account
4. Give your service account a name
5. Give at least the "Vertex AI Online Prediction Service Agent" role
6. Click on the account, then the "Keys" tab
7. Create new key -> select json.
8. Copy the exact project id, private key id, private key, and client email into your JAN configuration.
9. Set the region to what is appropriate for your instance

### Step 2: Start Chatting with the Model

1. Select the VertexAI model you want to use.
2. Specify the model's parameters.
3. Start the conversation with the VertexAI model.
</Steps>

### VertexAI Models

You can also use specific VertexAI models you cannot find in the **Hub** section by customizing the `model.yaml` file, which you can see in the `~/jan/data/models/`. Follow the steps in the [Manage Models](/docs/models/manage-models) to manually add a model.

<Callout type='info'>
- You can find the list of available models in the [VertexAI documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/call-vertex-using-openai-library).
- The `id` property must match the model name in the list.
- For example, if you want to use the Gemini 1.0 Pro model you must set the `id` property to `google/gemini-1.0-pro-002`.
</Callout>

## Troubleshooting

If you encounter any issues during the integration process or while using VertexAI with Jan, consider the following troubleshooting steps:

- Double-check your service account is active.
- Confirm the model you selected is available in your selected region.
- Ensure the model is enabled in VertexAI model garden.
- Check for error messages or logs that may provide insight into the issue.
79 changes: 79 additions & 0 deletions extensions/inference-vertexai-extension/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# VertexAI Engine Extension

Created using Jan extension example

# Create a Jan Extension using Typescript

Use this template to bootstrap the creation of a TypeScript Jan extension. 🚀

## Create Your Own Extension

To create your own extension, you can use this repository as a template! Just follow the below instructions:

1. Click the Use this template button at the top of the repository
2. Select Create a new repository
3. Select an owner and name for your new repository
4. Click Create repository
5. Clone your new repository

## Initial Setup

After you've cloned the repository to your local machine or codespace, you'll need to perform some initial setup steps before you can develop your extension.

> [!NOTE]
>
> You'll need to have a reasonably modern version of
> [Node.js](https://nodejs.org) handy. If you are using a version manager like
> [`nodenv`](https://github.com/nodenv/nodenv) or
> [`nvm`](https://github.com/nvm-sh/nvm), you can run `nodenv install` in the
> root of your repository to install the version specified in
> [`package.json`](./package.json). Otherwise, 20.x or later should work!

1. :hammer_and_wrench: Install the dependencies

```bash
npm install
```

1. :building_construction: Package the TypeScript for distribution

```bash
npm run bundle
```

1. :white_check_mark: Check your artifact

There will be a tgz file in your extension directory now

## Update the Extension Metadata

The [`package.json`](package.json) file defines metadata about your extension, such as
extension name, main entry, description and version.

When you copy this repository, update `package.json` with the name, description for your extension.

## Update the Extension Code

The [`src/`](./src/) directory is the heart of your extension! This contains the
source code that will be run when your extension functions are invoked. You can replace the
contents of this directory with your own code.

There are a few things to keep in mind when writing your extension code:

- Most Jan Extension functions are processed asynchronously.
In `index.ts`, you will see that the extension function will return a `Promise<any>`.

```typescript
import { events, MessageEvent, MessageRequest } from '@janhq/core'

function onStart(): Promise<any> {
return events.on(MessageEvent.OnMessageSent, (data: MessageRequest) =>
this.inference(data)
)
}
```

For more information about the Jan Extension Core module, see the
[documentation](https://github.com/janhq/jan/blob/main/core/README.md).

So, what are you waiting for? Go ahead and start customizing your extension!
9 changes: 9 additions & 0 deletions extensions/inference-vertexai-extension/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
transform: {
'node_modules/@janhq/core/.+\\.(j|t)s?$': 'ts-jest',
},
transformIgnorePatterns: ['node_modules/(?!@janhq/core/.*)'],
}
43 changes: 43 additions & 0 deletions extensions/inference-vertexai-extension/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "@janhq/inference-vertexai-extension",
"productName": "VertexAI Inference Engine",
"version": "1.0.0",
"description": "This extension enables Vertex chat completion API calls",
"main": "dist/index.js",
"module": "dist/module.js",
"engine": "vertexai",
"author": "Jan <[email protected]>",
"license": "AGPL-3.0",
"scripts": {
"build": "rolldown -c rolldown.config.mjs",
"build:publish": "rimraf *.tgz --glob || true && yarn build && npm pack && cpx *.tgz ../../pre-install"
},
"devDependencies": {
"cpx": "^1.5.0",
"rimraf": "^3.0.2",
"rolldown": "1.0.0-beta.1",
"ts-loader": "^9.5.0",
"typescript": "^5.7.2"
},
"dependencies": {
"@janhq/core": "../../core/package.tgz",
"fetch-retry": "^5.0.6",
"jose": "^5.9.6",
"ulidx": "^2.3.0"
},
"engines": {
"node": ">=18.0.0"
},
"files": [
"dist/*",
"package.json",
"README.md"
],
"bundleDependencies": [
"fetch-retry"
],
"installConfig": {
"hoistingLimits": "workspaces"
},
"packageManager": "[email protected]"
}
98 changes: 98 additions & 0 deletions extensions/inference-vertexai-extension/resources/models.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
[
{
"sources": [
{
"url": "https://cloud.google.com/vertex-ai"
}
],
"id": "google/gemini-1.5-flash-002",
"object": "model",
"name": "Gemini 1.5 Flash",
"version": "1.5",
"description": "Gemini 1.5 Flash is a high-performance general-purpose model designed for fast and efficient use cases.",
"format": "api",
"settings": {
"vision_model": true
},
"parameters": {
"max_tokens": 8192,
"temperature": 0.7,
"top_p": 0.95,
"stream": true,
"stop": [],
"frequency_penalty": 0,
"presence_penalty": 0
},
"metadata": {
"author": "Google",
"tags": [
"General"
]
},
"engine": "vertexai"
},
{
"sources": [
{
"url": "https://cloud.google.com/vertex-ai"
}
],
"id": "google/gemini-2.0-flash-exp",
"object": "model",
"name": "Gemini 2.0 Flash",
"version": "2.0",
"description": "Gemini 2.0 Flash is an enhanced version of the Flash series, offering robust performance for general tasks",
"format": "api",
"settings": {
"vision_model": true
},
"parameters": {
"max_tokens": 8192,
"temperature": 0.7,
"top_p": 0.95,
"stream": true,
"stop": [],
"frequency_penalty": 0,
"presence_penalty": 0
},
"metadata": {
"author": "Google",
"tags": [
"General"
]
},
"engine": "vertexai"
},
{
"sources": [
{
"url": "https://cloud.google.com/vertex-ai"
}
],
"id": "google/gemini-1.5-pro-002",
"object": "model",
"name": "Gemini 1.5 Pro",
"version": "1.5",
"description": "Gemini 1.5 Pro is a professional-grade model optimized for versatile and high-quality applications",
"format": "api",
"settings": {
"vision_model": true
},
"parameters": {
"max_tokens": 8192,
"temperature": 0.7,
"top_p": 0.95,
"stream": true,
"stop": [],
"frequency_penalty": 0,
"presence_penalty": 0
},
"metadata": {
"author": "Google",
"tags": [
"General"
]
},
"engine": "vertexai"
}
]
52 changes: 52 additions & 0 deletions extensions/inference-vertexai-extension/resources/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[
{
"key": "projectId",
"title": "Project ID",
"description": "The specific GCP project ID you want to use.",
"controllerType": "input",
"controllerProps": {
"placeholder": "Project Id",
"value": ""
}
},
{
"key": "location",
"title": "location",
"description": "The location of your GCP instance",
"controllerType": "input",
"controllerProps": {
"placeholder": "us-central1",
"value": "us-central1"
}
},
{
"key": "privateKey",
"title": "Private Key",
"description": "The private key of your service account Learn more: https://cloud.google.com/iam/docs/keys-create-delete",
"controllerType": "input",
"controllerProps": {
"placeholder": "Insert Private Key",
"value": ""
}
},
{
"key": "serviceEmail",
"title": "service Email",
"description": "Service Account Email",
"controllerType": "input",
"controllerProps": {
"placeholder": "Enter service email here",
"value": ""
}
},
{
"key": "vertexai-api-key",
"title": "Private Key ID",
"description": "The Private Key ID for your service account",
"controllerType": "input",
"controllerProps": {
"placeholder": "Enter private key id here",
"value": ""
}
}
]
18 changes: 18 additions & 0 deletions extensions/inference-vertexai-extension/rolldown.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { defineConfig } from 'rolldown'
import pkgJson from './package.json' with { type: 'json' }
import settingJson from './resources/settings.json' with { type: 'json' }
import modelsJson from './resources/models.json' with { type: 'json' }

export default defineConfig({
input: 'src/index.ts',
output: {
format: 'esm',
file: 'dist/index.js',
},
platform: 'browser',
define: {
MODELS: JSON.stringify(modelsJson),
SETTINGS: JSON.stringify(settingJson),
ENGINE: JSON.stringify(pkgJson.engine),
},
})
2 changes: 2 additions & 0 deletions extensions/inference-vertexai-extension/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const SETTINGS: SettingComponentProps[]
declare const MODELS: Model[]
Loading