Skip to content

feat: Support Google Gemini AI #1805

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

Merged
merged 2 commits into from
Jul 3, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
"@vitejs/plugin-react": "^4.3.1",
"vite": "^5.3.4"
}
}
}
2 changes: 1 addition & 1 deletion examples/06-custom-schema/06-toggleable-blocks/index.html
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should split these changes to a different PR? Seems unrelated

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nvm, pnpm gen just wasn't run on main before

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</script>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Toggleable Blocks</title>
<title>Toggleable Custom Blocks</title>
</head>
<body>
<div id="root"></div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@blocknote/example-toggleable-blocks",
"name": "@blocknote/example-custom-schema-toggleable-blocks",
"description": "AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY",
"private": true,
"version": "0.12.4",
Expand Down
1 change: 1 addition & 0 deletions examples/09-ai/02-playground/.bnexample.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@blocknote/xl-ai": "latest",
"@mantine/core": "^7.10.1",
"ai": "^4.3.15",
"@ai-sdk/google": "^1.2.20",
"@ai-sdk/openai": "^1.3.22",
"@ai-sdk/openai-compatible": "^0.2.14",
"@ai-sdk/groq": "^1.2.9",
Expand Down
8 changes: 8 additions & 0 deletions examples/09-ai/02-playground/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createAnthropic } from "@ai-sdk/anthropic";
import { createGoogleGenerativeAI } from "@ai-sdk/google";
import { createGroq } from "@ai-sdk/groq";
import { createMistral } from "@ai-sdk/mistral";
import { createOpenAI } from "@ai-sdk/openai";
Expand Down Expand Up @@ -32,6 +33,7 @@ import { en as aiEn } from "@blocknote/xl-ai/locales";
import "@blocknote/xl-ai/style.css";
import { Fieldset, MantineProvider, Switch } from "@mantine/core";


import { LanguageModelV1 } from "ai";
import { useEffect, useMemo, useState } from "react";
import { useStore } from "zustand";
Expand Down Expand Up @@ -72,6 +74,12 @@ function getModel(aiModelString: string) {
return createAnthropic({
...client.getProviderSettings("anthropic"),
})(modelName);
} else if (provider === "google.generative-ai") {
return createGoogleGenerativeAI({
...client.getProviderSettings("google"),
})(modelName, {
structuredOutputs: false,
});
} else {
return "unknown-model" as const;
}
Expand Down
4 changes: 4 additions & 0 deletions examples/09-ai/02-playground/data/aimodels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ export const AI_MODELS = [
"anthropic.chat/claude-3-7-sonnet-latest",
"anthropic.chat/claude-3-5-haiku-latest",
"albert-etalab.chat/neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8",
"google.generative-ai/gemini-1.5-pro",
"google.generative-ai/gemini-1.5-flash",
"google.generative-ai/gemini-2.5-pro",
"google.generative-ai/gemini-2.5-flash",
];
1 change: 1 addition & 0 deletions examples/09-ai/02-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@blocknote/xl-ai": "latest",
"@mantine/core": "^7.10.1",
"ai": "^4.3.15",
"@ai-sdk/google": "^1.2.20",
"@ai-sdk/openai": "^1.3.22",
"@ai-sdk/openai-compatible": "^0.2.14",
"@ai-sdk/groq": "^1.2.9",
Expand Down
1 change: 1 addition & 0 deletions packages/xl-ai-server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ TOKEN=<Token to secure the /ai endpoint of the proxy server>
GROQ_API_KEY=<API Key for Groq>
MISTRAL_API_KEY=<API Key for Mistral>
OPENAI_API_KEY=<API Key for OpenAI>
GOOGLE_API_KEY=<API Key for Google Gemini>
MY_PROVIDER_API_KEY=<You can support any provider by setting the *_API_KEY pattern>
16 changes: 14 additions & 2 deletions packages/xl-ai-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,22 @@ function getProviderInfo(provider: string) {
if (!key || !key.length) {
return "not-found";
}
if (provider === "google") {
return {
key,
header: "x-goog-api-key",
};
}
if (provider === "anthropic") {
return {
key,
header: "x-api-key",
};
}

return {
key,
header: provider === "anthropic" ? "x-api-key" : "Authorization",
header: "Authorization",
};
}

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

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

Expand Down
1 change: 1 addition & 0 deletions packages/xl-ai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"@ai-sdk/openai": "^1.3.22",
"@ai-sdk/openai-compatible": "^0.2.14",
"@ai-sdk/anthropic": "^1.2.12",
"@ai-sdk/google": "^1.2.20",
"@mswjs/interceptors": "^0.37.5",
"@types/diff": "^6.0.0",
"@types/json-diff": "^1.0.3",
Expand Down
5 changes: 3 additions & 2 deletions packages/xl-ai/src/api/LLMRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export async function doLLMRequest(
content: `USER_MESSAGE: ${m.content}`,
};
}

return m;
});
/*
Expand All @@ -191,9 +192,9 @@ export async function doLLMRequest(
For now, this approach works ok.
*/
previousMessages.push({
role: "assistant",
role: "system", // using "assistant" here doesn't work with gemini because we can't mix system / assistant messages
content:
"These are the operations returned by a previous LLM call: \n" +
"ASSISTANT_MESSAGE: These are the operations returned by a previous LLM call: \n" +
JSON.stringify(
await previousResponse.llmResult.getGeneratedOperations(),
),
Expand Down
14 changes: 12 additions & 2 deletions packages/xl-ai/src/streamTool/callLLMWithStreamTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,14 @@ export async function generateOperations<T extends StreamTool<any>[]>(
// - optional, with defaults

// mistral somehow needs "auto", while groq/llama needs "tool"
// google needs "auto" because https://github.com/vercel/ai/issues/6959
// TODO: further research this and / or make configurable
// for now stick to "tool" by default as this has been tested mostly
mode: rest.model.provider === "mistral.chat" ? "auto" : "tool",
mode:
rest.model.provider === "mistral.chat" ||
rest.model.provider === "google.generative-ai"
? "auto"
: "tool",
// - mandatory ones:
...rest,

Expand Down Expand Up @@ -215,9 +220,14 @@ export async function streamOperations<T extends StreamTool<any>[]>(

// - optional, with defaults
// mistral somehow needs "auto", while groq/llama needs "tool"
// google needs "auto" because https://github.com/vercel/ai/issues/6959
// TODO: further research this and / or make configurable
// for now stick to "tool" by default as this has been tested mostly
mode: rest.model.provider === "mistral.chat" ? "auto" : "tool",
mode:
rest.model.provider === "mistral.chat" ||
rest.model.provider === "google.generative-ai"
? "auto"
: "tool",
// - mandatory ones:
...rest,

Expand Down
1 change: 1 addition & 0 deletions playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"dependencies": {
"@ai-sdk/anthropic": "^1.2.11",
"@ai-sdk/google": "^1.2.20",
"@ai-sdk/groq": "^1.2.9",
"@ai-sdk/mistral": "^1.2.8",
"@ai-sdk/openai": "^1.3.22",
Expand Down
3 changes: 2 additions & 1 deletion playground/src/examples.gen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@
"Basic"
]
},
"title": "Toggleable Blocks",
"title": "Toggleable Custom Blocks",
"group": {
"pathFromRoot": "examples/06-custom-schema",
"slug": "custom-schema"
Expand Down Expand Up @@ -1492,6 +1492,7 @@
"@blocknote/xl-ai": "latest",
"@mantine/core": "^7.10.1",
"ai": "^4.3.15",
"@ai-sdk/google": "^1.2.20",
"@ai-sdk/openai": "^1.3.22",
"@ai-sdk/openai-compatible": "^0.2.14",
"@ai-sdk/groq": "^1.2.9",
Expand Down
21 changes: 21 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading