diff --git a/examples/05-interoperability/08-converting-blocks-to-react-email/package.json b/examples/05-interoperability/08-converting-blocks-to-react-email/package.json index 39fce8c55..2257ca2ba 100644 --- a/examples/05-interoperability/08-converting-blocks-to-react-email/package.json +++ b/examples/05-interoperability/08-converting-blocks-to-react-email/package.json @@ -26,4 +26,4 @@ "@vitejs/plugin-react": "^4.3.1", "vite": "^5.3.4" } -} +} \ No newline at end of file diff --git a/examples/06-custom-schema/06-toggleable-blocks/index.html b/examples/06-custom-schema/06-toggleable-blocks/index.html index 010b3479d..421101062 100644 --- a/examples/06-custom-schema/06-toggleable-blocks/index.html +++ b/examples/06-custom-schema/06-toggleable-blocks/index.html @@ -5,7 +5,7 @@ - Toggleable Blocks + Toggleable Custom Blocks
diff --git a/examples/06-custom-schema/06-toggleable-blocks/package.json b/examples/06-custom-schema/06-toggleable-blocks/package.json index b93ea2504..7d7aa33ff 100644 --- a/examples/06-custom-schema/06-toggleable-blocks/package.json +++ b/examples/06-custom-schema/06-toggleable-blocks/package.json @@ -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", diff --git a/examples/09-ai/02-playground/.bnexample.json b/examples/09-ai/02-playground/.bnexample.json index dc5849f4d..247d188e8 100644 --- a/examples/09-ai/02-playground/.bnexample.json +++ b/examples/09-ai/02-playground/.bnexample.json @@ -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", diff --git a/examples/09-ai/02-playground/App.tsx b/examples/09-ai/02-playground/App.tsx index 6ecba038c..3f34639bc 100644 --- a/examples/09-ai/02-playground/App.tsx +++ b/examples/09-ai/02-playground/App.tsx @@ -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"; @@ -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"; @@ -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; } diff --git a/examples/09-ai/02-playground/data/aimodels.ts b/examples/09-ai/02-playground/data/aimodels.ts index 174618d11..6ec7562dc 100644 --- a/examples/09-ai/02-playground/data/aimodels.ts +++ b/examples/09-ai/02-playground/data/aimodels.ts @@ -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", ]; diff --git a/examples/09-ai/02-playground/package.json b/examples/09-ai/02-playground/package.json index f2874ba52..48d4c32e2 100644 --- a/examples/09-ai/02-playground/package.json +++ b/examples/09-ai/02-playground/package.json @@ -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", diff --git a/packages/xl-ai-server/.env.example b/packages/xl-ai-server/.env.example index 719aa7c60..971ce1f72 100644 --- a/packages/xl-ai-server/.env.example +++ b/packages/xl-ai-server/.env.example @@ -2,4 +2,5 @@ TOKEN= GROQ_API_KEY= MISTRAL_API_KEY= OPENAI_API_KEY= +GOOGLE_API_KEY= MY_PROVIDER_API_KEY= diff --git a/packages/xl-ai-server/src/index.ts b/packages/xl-ai-server/src/index.ts index 4d784b8d1..f5ce73b3a 100644 --- a/packages/xl-ai-server/src/index.ts +++ b/packages/xl-ai-server/src/index.ts @@ -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", }; } @@ -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); }); diff --git a/packages/xl-ai/package.json b/packages/xl-ai/package.json index 3e29b2156..ce09741ef 100644 --- a/packages/xl-ai/package.json +++ b/packages/xl-ai/package.json @@ -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", diff --git a/packages/xl-ai/src/api/LLMRequest.ts b/packages/xl-ai/src/api/LLMRequest.ts index c11a19d62..46494bfc2 100644 --- a/packages/xl-ai/src/api/LLMRequest.ts +++ b/packages/xl-ai/src/api/LLMRequest.ts @@ -176,6 +176,7 @@ export async function doLLMRequest( content: `USER_MESSAGE: ${m.content}`, }; } + return m; }); /* @@ -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(), ), diff --git a/packages/xl-ai/src/streamTool/callLLMWithStreamTools.ts b/packages/xl-ai/src/streamTool/callLLMWithStreamTools.ts index 78f7dd008..1dd310ff8 100644 --- a/packages/xl-ai/src/streamTool/callLLMWithStreamTools.ts +++ b/packages/xl-ai/src/streamTool/callLLMWithStreamTools.ts @@ -105,9 +105,14 @@ export async function generateOperations[]>( // - 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, @@ -215,9 +220,14 @@ export async function streamOperations[]>( // - 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, diff --git a/playground/package.json b/playground/package.json index e85842670..703bb8f41 100644 --- a/playground/package.json +++ b/playground/package.json @@ -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", diff --git a/playground/src/examples.gen.tsx b/playground/src/examples.gen.tsx index 890b5b3ca..e136417a6 100644 --- a/playground/src/examples.gen.tsx +++ b/playground/src/examples.gen.tsx @@ -1185,7 +1185,7 @@ "Basic" ] }, - "title": "Toggleable Blocks", + "title": "Toggleable Custom Blocks", "group": { "pathFromRoot": "examples/06-custom-schema", "slug": "custom-schema" @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a5b3e5319..0be32afc3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2908,6 +2908,9 @@ importers: '@ai-sdk/anthropic': specifier: ^1.2.11 version: 1.2.11(zod@3.24.2) + '@ai-sdk/google': + specifier: ^1.2.20 + version: 1.2.20(zod@3.24.2) '@ai-sdk/groq': specifier: ^1.2.9 version: 1.2.9(zod@3.24.2) @@ -3862,6 +3865,9 @@ importers: '@ai-sdk/anthropic': specifier: ^1.2.12 version: 1.2.12(zod@3.24.2) + '@ai-sdk/google': + specifier: ^1.2.20 + version: 1.2.20(zod@3.24.2) '@ai-sdk/groq': specifier: ^1.2.9 version: 1.2.9(zod@3.24.2) @@ -4279,6 +4285,9 @@ importers: '@ai-sdk/anthropic': specifier: ^1.2.11 version: 1.2.11(zod@3.24.2) + '@ai-sdk/google': + specifier: ^1.2.20 + version: 1.2.20(zod@3.24.2) '@ai-sdk/groq': specifier: ^1.2.9 version: 1.2.9(zod@3.24.2) @@ -4560,6 +4569,12 @@ packages: peerDependencies: zod: ^3.0.0 + '@ai-sdk/google@1.2.20': + resolution: {integrity: sha512-XJcJPazNmvd1WQ/CHS17EDiJs1kPU0eakOgBin0o1DgXsnhX9OKdDxz+tgtriWE8HliN9edU0mhzMiiraz7EQA==} + engines: {node: '>=18'} + peerDependencies: + zod: ^3.0.0 + '@ai-sdk/groq@1.2.9': resolution: {integrity: sha512-7MoDaxm8yWtiRbD1LipYZG0kBl+Xe0sv/EeyxnHnGPZappXdlgtdOgTZVjjXkT3nWP30jjZi9A45zoVrBMb3Xg==} engines: {node: '>=18'} @@ -15182,6 +15197,12 @@ snapshots: '@ai-sdk/provider-utils': 2.2.8(zod@3.24.2) zod: 3.24.2 + '@ai-sdk/google@1.2.20(zod@3.24.2)': + dependencies: + '@ai-sdk/provider': 1.1.3 + '@ai-sdk/provider-utils': 2.2.8(zod@3.24.2) + zod: 3.24.2 + '@ai-sdk/groq@1.2.9(zod@3.24.2)': dependencies: '@ai-sdk/provider': 1.1.3