mirror of
https://github.com/logancyang/obsidian-copilot.git
synced 2026-07-22 07:50:24 +00:00
perf(deps): route Cohere & Mistral through OpenAI-compat to cut bundle by 1.8MB (#2402)
Replace ChatCohere / ChatMistralAI / CohereEmbeddings with ChatOpenAI / OpenAIEmbeddings pointed at each provider's OpenAI-compatible endpoint: - Cohere: https://api.cohere.ai/compatibility/v1 - Mistral: https://api.mistral.ai/v1 (already OpenAI-shaped) Dropping @langchain/cohere, @langchain/mistralai, cohere-ai, and @mistralai/mistralai also eliminates the @aws-sdk/* and @smithy/* chain that cohere-ai dragged in for Bedrock auth (a path this plugin doesn't use). Production bundle: 5.21MB -> 3.39MB. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
2fb1552a49
commit
b7ad36624a
5 changed files with 413 additions and 588 deletions
964
package-lock.json
generated
964
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -87,13 +87,11 @@
|
|||
"@koa/cors": "^5.0.0",
|
||||
"@langchain/anthropic": "^1.0.0",
|
||||
"@langchain/classic": "^1.0.9",
|
||||
"@langchain/cohere": "^1.0.0",
|
||||
"@langchain/community": "^1.0.0",
|
||||
"@langchain/core": "^1.1.29",
|
||||
"@langchain/deepseek": "^1.0.0",
|
||||
"@langchain/google-genai": "^2.1.23",
|
||||
"@langchain/groq": "^1.0.0",
|
||||
"@langchain/mistralai": "^1.0.0",
|
||||
"@langchain/openai": "^1.0.0",
|
||||
"@langchain/textsplitters": "^1.0.0",
|
||||
"@langchain/xai": "^1.0.0",
|
||||
|
|
@ -125,7 +123,6 @@
|
|||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"codemirror-companion-extension": "^0.0.11",
|
||||
"cohere-ai": "^7.13.0",
|
||||
"crypto-js": "^4.1.1",
|
||||
"diff": "^7.0.0",
|
||||
"esbuild-plugin-svg": "^0.1.0",
|
||||
|
|
|
|||
|
|
@ -27,13 +27,11 @@ import {
|
|||
} from "@/utils";
|
||||
import { HarmBlockThreshold, HarmCategory } from "@google/generative-ai";
|
||||
import { ChatAnthropic } from "@langchain/anthropic";
|
||||
import { ChatCohere } from "@langchain/cohere";
|
||||
import { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
||||
import { BaseLanguageModel } from "@langchain/core/language_models/base";
|
||||
import { ChatDeepSeek } from "@langchain/deepseek";
|
||||
import { ChatGoogleGenerativeAI } from "@langchain/google-genai";
|
||||
import { ChatGroq } from "@langchain/groq";
|
||||
import { ChatMistralAI } from "@langchain/mistralai";
|
||||
import { ChatOllama } from "@langchain/ollama";
|
||||
import { ChatOpenAI } from "@langchain/openai";
|
||||
import { ChatXAI } from "@langchain/xai";
|
||||
|
|
@ -68,7 +66,7 @@ const CHAT_PROVIDER_CONSTRUCTORS = {
|
|||
[ChatModelProviders.OPENAI]: ChatOpenAI,
|
||||
[ChatModelProviders.AZURE_OPENAI]: ChatOpenAI,
|
||||
[ChatModelProviders.ANTHROPIC]: ChatAnthropic,
|
||||
[ChatModelProviders.COHEREAI]: ChatCohere,
|
||||
[ChatModelProviders.COHEREAI]: ChatOpenAI,
|
||||
[ChatModelProviders.GOOGLE]: ChatGoogleGenerativeAI,
|
||||
[ChatModelProviders.XAI]: ChatXAI,
|
||||
[ChatModelProviders.OPENROUTERAI]: ChatOpenRouter,
|
||||
|
|
@ -78,7 +76,7 @@ const CHAT_PROVIDER_CONSTRUCTORS = {
|
|||
[ChatModelProviders.OPENAI_FORMAT]: ChatOpenAI,
|
||||
[ChatModelProviders.SILICONFLOW]: ChatOpenAI,
|
||||
[ChatModelProviders.COPILOT_PLUS]: ChatOpenRouter,
|
||||
[ChatModelProviders.MISTRAL]: ChatMistralAI,
|
||||
[ChatModelProviders.MISTRAL]: ChatOpenAI,
|
||||
[ChatModelProviders.DEEPSEEK]: ChatDeepSeek,
|
||||
[ChatModelProviders.AMAZON_BEDROCK]: BedrockChatModel,
|
||||
[ChatModelProviders.GITHUB_COPILOT]: GitHubCopilotChatModel,
|
||||
|
|
@ -281,8 +279,12 @@ export default class ChatModelManager {
|
|||
};
|
||||
})(),
|
||||
[ChatModelProviders.COHEREAI]: {
|
||||
modelName,
|
||||
apiKey: await getDecryptedKey(customModel.apiKey || settings.cohereApiKey),
|
||||
model: modelName,
|
||||
configuration: {
|
||||
baseURL: customModel.baseUrl || ProviderInfo[ChatModelProviders.COHEREAI].host,
|
||||
fetch: customModel.enableCors ? safeFetch : undefined,
|
||||
},
|
||||
},
|
||||
[ChatModelProviders.GOOGLE]: {
|
||||
apiKey: await getDecryptedKey(customModel.apiKey || settings.googleApiKey),
|
||||
|
|
@ -412,9 +414,12 @@ export default class ChatModelManager {
|
|||
},
|
||||
},
|
||||
[ChatModelProviders.MISTRAL]: {
|
||||
model: modelName,
|
||||
modelName,
|
||||
apiKey: await getDecryptedKey(customModel.apiKey || settings.mistralApiKey),
|
||||
serverURL: customModel.baseUrl,
|
||||
configuration: {
|
||||
baseURL: customModel.baseUrl || ProviderInfo[ChatModelProviders.MISTRAL].host,
|
||||
fetch: customModel.enableCors ? safeFetch : undefined,
|
||||
},
|
||||
},
|
||||
[ChatModelProviders.DEEPSEEK]: {
|
||||
modelName: modelName,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import { getDecryptedKey } from "@/encryptionService";
|
|||
import { CustomError } from "@/error";
|
||||
import { getModelKeyFromModel, getSettings, subscribeToSettingsChange } from "@/settings/model";
|
||||
import { err2String, safeFetch } from "@/utils";
|
||||
import { CohereEmbeddings } from "@langchain/cohere";
|
||||
import { Embeddings } from "@langchain/core/embeddings";
|
||||
import { GoogleGenerativeAIEmbeddings } from "@langchain/google-genai";
|
||||
import { OllamaEmbeddings } from "@langchain/ollama";
|
||||
|
|
@ -21,7 +20,7 @@ const EMBEDDING_PROVIDER_CONSTRUCTORS = {
|
|||
[EmbeddingModelProviders.COPILOT_PLUS]: CustomOpenAIEmbeddings,
|
||||
[EmbeddingModelProviders.COPILOT_PLUS_JINA]: CustomJinaEmbeddings,
|
||||
[EmbeddingModelProviders.OPENAI]: OpenAIEmbeddings,
|
||||
[EmbeddingModelProviders.COHEREAI]: CohereEmbeddings,
|
||||
[EmbeddingModelProviders.COHEREAI]: OpenAIEmbeddings,
|
||||
[EmbeddingModelProviders.GOOGLE]: GoogleGenerativeAIEmbeddings,
|
||||
[EmbeddingModelProviders.AZURE_OPENAI]: AzureOpenAIEmbeddings,
|
||||
[EmbeddingModelProviders.OLLAMA]: OllamaEmbeddings,
|
||||
|
|
@ -241,8 +240,14 @@ export default class EmbeddingManager {
|
|||
},
|
||||
},
|
||||
[EmbeddingModelProviders.COHEREAI]: {
|
||||
model: modelName,
|
||||
modelName,
|
||||
apiKey: await getDecryptedKey(customModel.apiKey || settings.cohereApiKey),
|
||||
timeout: 10000,
|
||||
batchSize: getSettings().embeddingBatchSize,
|
||||
configuration: {
|
||||
baseURL: customModel.baseUrl || ProviderInfo[EmbeddingModelProviders.COHEREAI].host,
|
||||
fetch: customModel.enableCors ? safeFetch : undefined,
|
||||
},
|
||||
},
|
||||
[EmbeddingModelProviders.GOOGLE]: {
|
||||
modelName: modelName,
|
||||
|
|
|
|||
|
|
@ -662,8 +662,8 @@ export const ProviderInfo: Record<Provider, ProviderMetadata> = {
|
|||
},
|
||||
[ChatModelProviders.COHEREAI]: {
|
||||
label: "Cohere",
|
||||
host: "https://api.cohere.com",
|
||||
curlBaseURL: "https://api.cohere.com/v1",
|
||||
host: "https://api.cohere.ai/compatibility/v1",
|
||||
curlBaseURL: "https://api.cohere.ai/compatibility/v1",
|
||||
keyManagementURL: "https://dashboard.cohere.ai/api-keys",
|
||||
listModelURL: "https://api.cohere.com/v1/models",
|
||||
testModel: ChatModels.COMMAND_R,
|
||||
|
|
|
|||
Loading…
Reference in a new issue