langchainjs icon indicating copy to clipboard operation
langchainjs copied to clipboard

Openai TypeError: t.Completions is not a constructor

Open krankos opened this issue 8 months ago • 7 comments

Checked other resources

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

Example Code


import { ChatOpenAI } from "https://esm.sh/v135/@langchain/openai";

Error Message and Stack Trace (if applicable)

TypeError: t.Completions is not a constructor
    at new r (https://esm.sh/v135/[email protected]/denonext/openai.mjs:12:131)
    at E._getClientOptions (https://esm.sh/v135/@langchain/[email protected]/denonext/openai.mjs:9:24539)
    at E.completionWithRetry (https://esm.sh/v135/@langchain/[email protected]/denonext/openai.mjs:9:23756)
    at E._streamResponseChunks (https://esm.sh/v135/@langchain/[email protected]/denonext/openai.mjs:9:17637)
    at _streamResponseChunks.next (<anonymous>)
    at E._generateUncached (https://esm.sh/v135/@langchain/[email protected]/denonext/language_models/chat_models.js:31:15951)
    at eventLoopTick (ext:core/01_core.js:177:7)
    at async E.invoke (https://esm.sh/v135/@langchain/[email protected]/denonext/language_models/chat_models.js:31:13787)
    at async U.agent [as func] (file:///root/netlify/edge-functions/lib/checklistGraph.ts:265:22)
    at async U.invoke (https://esm.sh/v135/@langchain/[email protected]/denonext/langgraph.mjs:5:14004) {
  pregelTaskId: "f880f64e-bd26-5a31-9318-d79206eaba3c"
}

Description

I'm using Deno in an Edge Function.

Downgrading to @langchain/[email protected] fixes the error

System Info

Deno on Edge function

krankos avatar Mar 26 '25 07:03 krankos

Hey @krankos 👋, I'm here to help you with your LangChain.js issue. I can assist with bug fixes, answer questions, and guide you on becoming a contributor. Let's tackle this together!

The error you're encountering, TypeError: t.Completions is not a constructor, suggests that there might be an issue with the way the Completions class or function is being imported or used in the @langchain/openai package version 0.5.0. Since downgrading to version 0.4.5 resolves the issue, it indicates a potential change or regression in the newer version.

Here are a few steps you can take to address this issue:

  1. Check for Breaking Changes: Review the changelog or release notes for version 0.5.0 to see if there are any documented breaking changes or updates related to the Completions class or its usage. Unfortunately, I couldn't find specific migration notes or breaking changes documented for this version in the available data.

  2. Verify Import Paths: Ensure that the import paths and module resolutions are correct, especially when using Deno. Sometimes, module resolution issues can cause such errors.

  3. Compatibility with Deno: Since you're using Deno in an Edge Function, ensure that the package is fully compatible with Deno. There might be specific compatibility issues with version 0.5.0 that are not present in 0.4.5.

  4. Error Handling: Check if there are any error handling mechanisms in place that might be affecting the instantiation of the Completions class. The @langchain/openai package uses specific error handling for constructors, which might be relevant [1].

If these steps do not resolve the issue, you might consider continuing to use version 0.4.5 until a fix or update is available in the newer version.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

dosubot[bot] avatar Mar 26 '25 07:03 dosubot[bot]

@dosubot can you find the changelog for @langchain/openai ?

krankos avatar Mar 26 '25 08:03 krankos

Could you provide the specific version of @langchain/openai you are interested in, or are you looking for the changelog for version 0.5.0 specifically? Additionally, do you have access to the repository or any specific links where the changelog might be hosted? This information would help in locating the changelog more effectively.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

dosubot[bot] avatar Mar 26 '25 08:03 dosubot[bot]

Bumping this as I am running into the same issue on 0.5.4 @dosubot

sbilling avatar Apr 08 '25 17:04 sbilling

@dosu please assist

sbilling avatar Apr 10 '25 18:04 sbilling

Hey @sbilling, OpenAI has had some issues with esm.sh in the past - can you try importing it like this:

import { ChatOpenAI } from 'npm:@langchain/openai';

jacoblee93 avatar Apr 10 '25 21:04 jacoblee93

The error TypeError: t.Completions is not a constructor suggests a potential issue with the Completions class in the @langchain/openai package for versions 0.5.0 and above. Unfortunately, I couldn't find specific changelogs or release notes for version 0.5.4 that might detail changes affecting the Completions class.

Here are some steps you can take to address this issue:

  1. Verify Import Paths: Ensure that the import paths are correct, especially when using Deno. Incorrect paths can lead to such errors.

  2. Check for Breaking Changes: Although specific release notes weren't found, reviewing any available documentation or updates on the repository might provide insights into changes in version 0.5.4.

  3. Compatibility with Deno: Ensure that the package version is fully compatible with Deno. There might be specific compatibility issues with version 0.5.4.

  4. Consider Downgrading: If the issue persists, consider downgrading to a version that is known to work, such as 0.4.5, until a fix is available.

If these steps do not resolve the issue, you might need to wait for further updates or fixes in future releases.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

dosubot[bot] avatar Apr 10 '25 21:04 dosubot[bot]

@krankos @sbilling are you guys still encountering this? I think this is probably an issue with the esm.sh distribution of the openai package that @langchain/openai depends upon, but I'd like to confirm if possible. Did Jacob's suggestion to use the npm: prefix help?

If it is indeed a packaging issue with openai on esm.sh, I think you'll likely need to take this upstream to them.

benjamincburns avatar May 15 '25 22:05 benjamincburns

Closing due to lack of activity. If you are still encountering this problem, please try Jacob's suggestion and if the problem persists, you'll most likely want to open a new issue over at openai/openai-node.

If you believe this is an issue with @langchain/openai or some other langchain package, please open a new issue here and be sure to include a minimum reproducible example so that we can understand and diagnose the problem more easily.

benjamincburns avatar May 21 '25 04:05 benjamincburns