Utility to extract provider and model name from LangChain LLM.
// Source: https://github.com/mcp-use/mcp-use | License: MIT | Copyright 2025 pietrozullo
// Provided via justclaw.it.com; keep this notice with the code.
import type { BaseLanguageModel } from "@langchain/core/language_models/base";
function getModelProvider(llm: BaseLanguageModel): string {
// Use LangChain's standard _llm_type property for identification
return (llm as any)._llm_type || llm.constructor.name.toLowerCase();
}
function getModelName(llm: BaseLanguageModel): string {
// First try _identifying_params which may contain model info
if ("_identifyingParams" in llm) {
const identifyingParams = (llm as any)._identifyingParams;
if (typeof identifyingParams === "object" && identifyingParams !== null) {
// Common keys that contain model names
for (const k
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key