langchain-ai / langchainjs

🦜🔗 Build context-aware reasoning applications 🦜🔗
https://js.langchain.com/docs/
MIT License
12.31k stars 2.08k forks source link

ParsedChatCompletion not found in 'openai/resources/beta/chat/completions.mjs' #6670

Closed gognjanovski closed 1 week ago

gognjanovski commented 2 weeks ago

Example Code

I get the following error node_modules/@langchain/openai/dist/chat_models.d.ts:9:38 - error TS7016: Could not find a declaration file for module 'openai/resources/beta/chat/completions.mjs'. for import { ParsedChatCompletion } from "openai/resources/beta/chat/completions.mjs";

Error Message and Stack Trace (if applicable)

No response

Description

I'm trying to build my nodejs project that includes the langchain package

System Info

Using: node v20.13.1 npm 10.5.2 "langchain": "^0.2.17" "openai": "4.57.0"

dosubot[bot] commented 2 weeks ago

Hello @gognjanovski! I'm here to help you with your LangChain.js issue. I'm a bot designed to assist with bug fixes, questions, and contributions. Let's work together to resolve the issue you're experiencing.

I found some relevant information that might help with the issue you're facing.

  1. Similar Issues and Discussions:

  2. Possible Cause and Solution:

    • The error "ParsedChatCompletion not found in 'openai/resources/beta/chat/completions.mjs'" occurs because the ParsedChatCompletion is being imported from a module that does not exist or is not correctly referenced in your project. Verify the correct path and export for ParsedChatCompletion in the openai package or remove the import if it is not needed [4].
    • Ensure that ParsedChatCompletion is a valid export in the openai/resources/beta/chat/completions.mjs file. According to the LangChain.js repository, it is a valid export [4].
  3. Dependencies:

    • Check the dependencies and peer dependencies in your package.json file. The relevant dependencies are:
      "openai": "^4.41.1"

      and peer dependencies:

      "@langchain/openai": ">=0.1.0 <0.3.0"

      Ensure these are correctly installed and compatible with your project [5].

  4. Alternative Methods:

    • The LangChain.js documentation provides alternative modules or methods for achieving similar functionality as ParsedChatCompletion. You can use Runnable, RunnablePassthrough, and RunnableSequence for structured output methods. Here is an example:
      withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(
      outputSchema: StructuredOutputMethodParams<RunOutput, boolean> | z.ZodType<RunOutput> | Record<string, any>,
      config?: StructuredOutputMethodOptions<boolean>
      ): Runnable<BaseLanguageModelInput, RunOutput> | Runnable<BaseLanguageModelInput, { raw: BaseMessage; parsed: RunOutput }> {
      // Implementation details...
      }

      This code snippet demonstrates how to use structured output methods with Runnable, RunnablePassthrough, and RunnableSequence to achieve similar functionality [6][4].

By following these steps, you should be able to resolve the import error and continue building your Node.js project with the LangChain package.

To continue talking to Dosu, mention @dosu.

jacoblee93 commented 1 week ago

Hey, sorry for the delay here!

Will fix.

jacoblee93 commented 1 week ago

Live in @langchain/openai@0.2.10!