UNPKG

@copilotkit/runtime

Version:

<img src="https://github.com/user-attachments/assets/0a6b64d9-e193-4940-a3f6-60334ac34084" alt="banner" style="border-radius: 12px; border: 2px solid #d6d4fa;" />

53 lines (51 loc) 2.23 kB
import "reflect-metadata"; import { __require } from "../../_virtual/_rolldown/runtime.mjs"; import { LangChainAdapter } from "../langchain/langchain-adapter.mjs"; //#region src/service-adapters/google/google-genai-adapter.ts /** * Copilot Runtime adapter for Google Generative AI (e.g. Gemini). * * ## Example * * ```ts * import { CopilotRuntime, GoogleGenerativeAIAdapter } from "@copilotkit/runtime"; * const { GoogleGenerativeAI } = require("@google/generative-ai"); * * const genAI = new GoogleGenerativeAI(process.env["GOOGLE_API_KEY"]); * * const copilotKit = new CopilotRuntime(); * * return new GoogleGenerativeAIAdapter({ model: "gemini-2.5-flash", apiVersion: "v1" }); * ``` */ const DEFAULT_MODEL = "gemini-2.5-flash"; const DEFAULT_API_VERSION = "v1"; let hasWarnedDefaultGoogleModel = false; var GoogleGenerativeAIAdapter = class extends LangChainAdapter { constructor(options) { if (!hasWarnedDefaultGoogleModel && !options?.model && !options?.apiVersion) { console.warn(`You are using the GoogleGenerativeAIAdapter without explicitly setting a model or apiVersion. CopilotKit will default to apiVersion="v1" and model="${DEFAULT_MODEL}". To silence this warning, pass model and apiVersion when constructing the adapter.`); hasWarnedDefaultGoogleModel = true; } super({ chainFn: async ({ messages, tools, threadId }) => { const { ChatGoogle } = __require("@langchain/google-gauth"); const { AIMessage } = __require("@langchain/core/messages"); const filteredMessages = messages.filter((message) => { if (!(message instanceof AIMessage)) return true; const aiMsg = message; return aiMsg.content && String(aiMsg.content).trim().length > 0 || aiMsg.tool_calls && aiMsg.tool_calls.length > 0; }); this.model = options?.model ?? DEFAULT_MODEL; return new ChatGoogle({ apiKey: options?.apiKey ?? process.env.GOOGLE_API_KEY, modelName: this.model, apiVersion: options?.apiVersion ?? DEFAULT_API_VERSION }).bindTools(tools).stream(filteredMessages, { metadata: { conversation_id: threadId } }); } }); this.provider = "google"; this.model = DEFAULT_MODEL; } }; //#endregion export { GoogleGenerativeAIAdapter }; //# sourceMappingURL=google-genai-adapter.mjs.map