Skip to content

Commit 9d3a542

Browse files
authored
feat: Support Google Gemini AI (#1805)
* fix google ai * fix lint
1 parent ce87392 commit 9d3a542

File tree

15 files changed

+72
-10
lines changed

15 files changed

+72
-10
lines changed

examples/05-interoperability/08-converting-blocks-to-react-email/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626
"@vitejs/plugin-react": "^4.3.1",
2727
"vite": "^5.3.4"
2828
}
29-
}
29+
}

examples/06-custom-schema/06-toggleable-blocks/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</script>
66
<meta charset="UTF-8" />
77
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
8-
<title>Toggleable Blocks</title>
8+
<title>Toggleable Custom Blocks</title>
99
</head>
1010
<body>
1111
<div id="root"></div>

examples/06-custom-schema/06-toggleable-blocks/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@blocknote/example-toggleable-blocks",
2+
"name": "@blocknote/example-custom-schema-toggleable-blocks",
33
"description": "AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY",
44
"private": true,
55
"version": "0.12.4",

examples/09-ai/02-playground/.bnexample.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"@blocknote/xl-ai": "latest",
88
"@mantine/core": "^7.10.1",
99
"ai": "^4.3.15",
10+
"@ai-sdk/google": "^1.2.20",
1011
"@ai-sdk/openai": "^1.3.22",
1112
"@ai-sdk/openai-compatible": "^0.2.14",
1213
"@ai-sdk/groq": "^1.2.9",

examples/09-ai/02-playground/App.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createAnthropic } from "@ai-sdk/anthropic";
2+
import { createGoogleGenerativeAI } from "@ai-sdk/google";
23
import { createGroq } from "@ai-sdk/groq";
34
import { createMistral } from "@ai-sdk/mistral";
45
import { createOpenAI } from "@ai-sdk/openai";
@@ -32,6 +33,7 @@ import { en as aiEn } from "@blocknote/xl-ai/locales";
3233
import "@blocknote/xl-ai/style.css";
3334
import { Fieldset, MantineProvider, Switch } from "@mantine/core";
3435

36+
3537
import { LanguageModelV1 } from "ai";
3638
import { useEffect, useMemo, useState } from "react";
3739
import { useStore } from "zustand";
@@ -72,6 +74,12 @@ function getModel(aiModelString: string) {
7274
return createAnthropic({
7375
...client.getProviderSettings("anthropic"),
7476
})(modelName);
77+
} else if (provider === "google.generative-ai") {
78+
return createGoogleGenerativeAI({
79+
...client.getProviderSettings("google"),
80+
})(modelName, {
81+
structuredOutputs: false,
82+
});
7583
} else {
7684
return "unknown-model" as const;
7785
}

examples/09-ai/02-playground/data/aimodels.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ export const AI_MODELS = [
1414
"anthropic.chat/claude-3-7-sonnet-latest",
1515
"anthropic.chat/claude-3-5-haiku-latest",
1616
"albert-etalab.chat/neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8",
17+
"google.generative-ai/gemini-1.5-pro",
18+
"google.generative-ai/gemini-1.5-flash",
19+
"google.generative-ai/gemini-2.5-pro",
20+
"google.generative-ai/gemini-2.5-flash",
1721
];

examples/09-ai/02-playground/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@blocknote/xl-ai": "latest",
2121
"@mantine/core": "^7.10.1",
2222
"ai": "^4.3.15",
23+
"@ai-sdk/google": "^1.2.20",
2324
"@ai-sdk/openai": "^1.3.22",
2425
"@ai-sdk/openai-compatible": "^0.2.14",
2526
"@ai-sdk/groq": "^1.2.9",

packages/xl-ai-server/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ TOKEN=<Token to secure the /ai endpoint of the proxy server>
22
GROQ_API_KEY=<API Key for Groq>
33
MISTRAL_API_KEY=<API Key for Mistral>
44
OPENAI_API_KEY=<API Key for OpenAI>
5+
GOOGLE_API_KEY=<API Key for Google Gemini>
56
MY_PROVIDER_API_KEY=<You can support any provider by setting the *_API_KEY pattern>

packages/xl-ai-server/src/index.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,22 @@ function getProviderInfo(provider: string) {
6161
if (!key || !key.length) {
6262
return "not-found";
6363
}
64+
if (provider === "google") {
65+
return {
66+
key,
67+
header: "x-goog-api-key",
68+
};
69+
}
70+
if (provider === "anthropic") {
71+
return {
72+
key,
73+
header: "x-api-key",
74+
};
75+
}
76+
6477
return {
6578
key,
66-
header: provider === "anthropic" ? "x-api-key" : "Authorization",
79+
header: "Authorization",
6780
};
6881
}
6982

@@ -111,7 +124,6 @@ app.use("/ai", cors(), async (c) => {
111124
request.headers.set(providerInfo.header, `${providerInfo.key}`);
112125
}
113126

114-
request.headers.set("x-api-key", `${providerInfo.key}`);
115127
return proxyFetch(request);
116128
});
117129

packages/xl-ai/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"@ai-sdk/openai": "^1.3.22",
9494
"@ai-sdk/openai-compatible": "^0.2.14",
9595
"@ai-sdk/anthropic": "^1.2.12",
96+
"@ai-sdk/google": "^1.2.20",
9697
"@mswjs/interceptors": "^0.37.5",
9798
"@types/diff": "^6.0.0",
9899
"@types/json-diff": "^1.0.3",

0 commit comments

Comments
 (0)