Skip to content
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

Cannot resolve langchain/core version incompatibilities in Deno scopes #6817

Open
5 tasks done
fjnoyp opened this issue Sep 16, 2024 · 1 comment
Open
5 tasks done
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@fjnoyp
Copy link

fjnoyp commented Sep 16, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain.js documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain.js rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

Deno import_map.json

{
  "imports": {
    "http/": "https://deno.land/[email protected]/http/",
    "langchain/": "https://esm.sh/v135/[email protected]/",
    "@langchain/core/": "https://esm.sh/v135/@langchain/[email protected]/",
    "@langchain/groq": "https://esm.sh/v135/@langchain/[email protected]/",
    "@langchain/openai": "https://esm.sh/v135/@langchain/[email protected]/",
  },
  "scopes": {
    "https://esm.sh/v135/": {
      "@langchain/core": "https://esm.sh/v135/@langchain/[email protected]/"
    },
    "https://esm.sh/v135/@langchain/[email protected]/": {
      "@langchain/core/": "https://esm.sh/v135/@langchain/[email protected]/"
    }
  }
}

NOTE: I get the type mismatch error if I do not manually find and choose the version of langchain/groq that uses the exact same version of langchain/core.

Code Usage

    const openAi = new ChatOpenAI(...);    
    const groq = new ChatGroq(...);

    const prompt = ChatPromptTemplate.fromMessages([...]);

    // TYPE MISMATCH ERROR 
    const wontCompileChain = prompt.pipe(openAi);
    const compilingChain = prompt.pipe(groq);

Error Message and Stack Trace (if applicable)

I get what appears to be a type mismatch because my openai import uses a different version langchain/core ...

Argument of type 'ChatOpenAI' is not assignable to parameter of type 'RunnableLike<ChatPromptValueInterface, AIMessageChunk>'.
Type 'ChatOpenAI' is not assignable to type 'RunnableInterface<ChatPromptValueInterface, AIMessageChunk, RunnableConfig> | RunnableMapLike<ChatPromptValueInterface, AIMessageChunk>'.
Type 'ChatOpenAI' is missing the following properties from type 'RunnableMapLike<ChatPromptValueInterface, AIMessageChunk>': _getType, _printableFields, concat, text, and 6 more.

Description

I'm trying to import langchain as part of my supabase edge function deno environment. Despite using scopes to force a common version of langchain/core the type mismatch error persists (https://js.langchain.com/docs/how_to/installation/#installing-integration-packages).

I've read online trying many different variations on scopes to fix this but keep getting the same type mismatch. I wrote a detailed stack overflow question with the other variations I tried as well: https://stackoverflow.com/questions/78941151/langchain-deno-import-map-cannot-use-common-langchain-core

When I go into ChatOpenAI class such as:
https://esm.sh/v135/@langchain/[email protected]/dist/chat_model.d.ts

I see it always using:
import { Runnable } from "https://esm.sh/v135/@langchain/[email protected]/runnables.d.ts";
Even though I specified the scope:

  "@langchain/core/": "https://esm.sh/v135/@langchain/[email protected]/",
  "scopes": {
    "https://esm.sh/v135/": {
      "@langchain/core": "https://esm.sh/v135/@langchain/[email protected]/"
    }
  }

I have reloaded and cleared the deno cache multiple times:
deno cache --reload ./ai_logic.ts --import-map=../../import_map.json

I'm unsure if this is a bug with deno or langchain but it does not seem possible to properly resolve to the same version of langchain/core.

Thank you in advance for your help and consideration here.

System Info

.vscode/settings.json

{
    "deno.enable": true,
    "deno.unstable": true,
    "deno.importMap": "./functions/import_map.json"
}

full import_map.json

{
  "imports": {
    "http/": "https://deno.land/[email protected]/http/",
    "supabase/supabase-js": "https://esm.sh/v135/@supabase/[email protected]",
    "langchain/": "https://esm.sh/v135/[email protected]/",
    "@langchain/core/": "https://esm.sh/v135/@langchain/[email protected]/",
    "@langchain/groq": "https://esm.sh/v135/@langchain/[email protected]/",
    "@langchain/openai": "https://esm.sh/v135/@langchain/[email protected]/",
    "@langchain/cohere": "https://esm.sh/v135/@langchain/[email protected]/",
    "langsmith/": "https://esm.sh/v135/[email protected]/",
    "zod": "https://esm.sh/v135/[email protected]/"
  },
  "scopes": {
    "https://esm.sh/v135/": {
      "@langchain/core": "https://esm.sh/v135/@langchain/[email protected]/"
    },
    "https://esm.sh/v135/@langchain/[email protected]/": {
      "@langchain/core/": "https://esm.sh/v135/@langchain/[email protected]/"
    }
  }
}
Copy link

dosubot bot commented Sep 16, 2024

Hey @fjnoyp! 👋 I'm here to help you with bug fixes, answer questions, and guide you to become a contributor. Let's squash those bugs together!

To resolve the type mismatch error in Deno when using different versions of @langchain/core with ChatOpenAI and ChatGroq, you need to ensure that all related packages are using the same version of @langchain/core. In your import_map.json, you have specified @langchain/core as version 0.2.29, but it seems that ChatOpenAI is still using a different version.

Update your import_map.json to ensure that both langchain/ and @langchain/core/ are using the same version. For example, you can set both to 0.2.29:

{
  "imports": {
    "http/": "https://deno.land/[email protected]/http/",
    "langchain/": "https://esm.sh/v135/[email protected]/",
    "@langchain/core/": "https://esm.sh/v135/@langchain/[email protected]/",
    "@langchain/groq": "https://esm.sh/v135/@langchain/[email protected]/",
    "@langchain/openai": "https://esm.sh/v135/@langchain/[email protected]/",
    "@langchain/cohere": "https://esm.sh/v135/@langchain/[email protected]/",
    "langsmith/": "https://esm.sh/v135/[email protected]/",
    "zod": "https://esm.sh/v135/[email protected]/"
  },
  "scopes": {
    "https://esm.sh/v135/": {
      "@langchain/core": "https://esm.sh/v135/@langchain/[email protected]/"
    },
    "https://esm.sh/v135/@langchain/[email protected]/": {
      "@langchain/core/": "https://esm.sh/v135/@langchain/[email protected]/"
    }
  }
}

Additionally, ensure that the imports for ChatOpenAI and ChatGroq are correctly aligned with the same version of @langchain/core. The _initChatModelHelper function in langchain/src/chat_models/universal.ts dynamically imports the appropriate chat model based on the provider, ensuring that the correct version is used. This should help in maintaining consistency across different chat models and avoid type mismatches [1][2].

For more information on installation and ensuring consistent versions, refer to the LangChain installation guide. It is crucial to ensure that all packages in the LangChain ecosystem depend on the same version of @langchain/core to avoid type errors [3].

To continue talking to Dosu, mention @dosu.

@dosubot dosubot bot added the auto:bug Related to a bug, vulnerability, unexpected error with an existing feature label Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

1 participant