langchain-ai / langchainjs

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

Opensearch integration compilation error #4850

Closed HowardIntentional closed 4 months ago

HowardIntentional commented 5 months ago

Checked other resources

Example Code

I am following these instructions in an empty typescript project:

https://js.langchain.com/docs/integrations/vectorstores/opensearch

It cannot compile

here is my package.json

{
  "name": "utils",
  "version": "1.0.0",
  "description": "",
  "main": "utils.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "node_modules/typescript/bin/tsc"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@aws-sdk/client-apigatewaymanagementapi": "^3.525.0",
    "@aws-sdk/client-dynamodb": "^3.525.0",
    "@aws-sdk/lib-dynamodb": "^3.525.0",
    "@langchain/openai": "^0.0.22",
    "@opensearch-project/opensearch": "^2.6.0",
    "@types/aws-lambda": "^8.10.130",
    "@types/node": "^20.10.5",
    "langchain": "^0.1.28",
    "openai": "^4.24.2",
    "uuid": "^9.0.1"
  },
  "devDependencies": {
    "@types/uuid": "^9.0.8",
    "jest": "^29.7.0"
  },
  "overrides": {
    "@langchain/core": "0.1.5"
  }
}

Error Message and Stack Trace (if applicable)

$ tsc node_modules/@langchain/openai/dist/chat_models.d.ts:7:64 - error TS2305: Module '"@langchain/core/language_models/base"' has no exported member 'StructuredOutputMethodOptions'.

7 import type { BaseFunctionCallOptions, BaseLanguageModelInput, StructuredOutputMethodOptions, StructuredOutputMethodParams } from "@langchain/core/language_models/base";


node_modules/@langchain/openai/dist/chat_models.d.ts:7:95 - error TS2305: Module '"@langchain/core/language_models/base"' has no exported member 'StructuredOutputMethodParams'.

7 import type { BaseFunctionCallOptions, BaseLanguageModelInput, StructuredOutputMethodOptions, StructuredOutputMethodParams } from "@langchain/core/language_models/base";

node_modules/@langchain/openai/dist/utils/openai.d.ts:3:62 - error TS2307: Cannot find module '@langchain/core/utils/function_calling' or its corresponding type declarations.

3 import { convertToOpenAIFunction, convertToOpenAITool } from "@langchain/core/utils/function_calling";


node_modules/@langchain/openai/dist/utils/openai.d.ts:6:103 - error TS2724: '"/Users/howardkitto/Projects/Intentional/intentional-api/layers/utils/node_modules/openai/resources/beta/beta".Beta' has no exported member named 'AssistantCreateParams'. Did you mean 'AssistantUpdateParams'?

6 export declare function formatToOpenAIAssistantTool(tool: StructuredToolInterface): OpenAIClient.Beta.AssistantCreateParams.AssistantToolsFunction;

node_modules/@langchain/openai/node_modules/@langchain/core/dist/language_models/chat_models.d.ts:64:129 - error TS2304: Cannot find name 'this'.

64 _generateCached({ messages, cache, llmStringKey, parsedOptions, handledOptions, }: ChatModelGenerateCachedParameters): Promise<LLMResult & {


node_modules/@langchain/openai/node_modules/@langchain/core/dist/language_models/llms.d.ts:66:122 - error TS2304: Cannot find name 'this'.

66     _generateCached({ prompts, cache, llmStringKey, parsedOptions, handledOptions, }: LLMGenerateCachedParameters<typeof this>): Promise<LLMResult & {

Found 6 errors in 4 files.

Errors Files 2 node_modules/@langchain/openai/dist/chat_models.d.ts:7 2 node_modules/@langchain/openai/dist/utils/openai.d.ts:3 1 node_modules/@langchain/openai/node_modules/@langchain/core/dist/language_models/chat_models.d.ts:64 1 node_modules/@langchain/openai/node_modules/@langchain/core/dist/language_models/llms.d.ts:66

Description

The documentation is wrong The dependencies are not up to date

System Info

mac aws lambda (SAM)

dosubot[bot] commented 5 months ago

Hey there @HowardIntentional! Good to see you back with us 🚀

Thank you for providing detailed information about the issue you're encountering. It seems like there might be a few different factors contributing to the compilation error.

Firstly, the error messages suggest that there are some unresolved imports in your opensearch.ts file. Specifically, the StructuredOutputMethodOptions and StructuredOutputMethodParams modules from the @langchain/core/language_models/base package seem to be causing issues. Unfortunately, I wasn't able to find the correct import paths for these modules within the repository. It's possible that these modules have been moved, renamed, or removed in a recent update to the @langchain/core package.

Secondly, the error messages also indicate that there might be some version compatibility issues between the @langchain/core and @langchain/openai packages. The @langchain/core package version compatible with LangChain JS version 0.1.28 is ~0.1.45, and the @langchain/openai package version is 0.0.22. Please ensure that you're using these versions in your project.

Lastly, the error messages suggest that there might be some issues with your TypeScript configuration. Specifically, the Cannot find name 'this' errors in chat_models.d.ts and llms.d.ts might be due to some TypeScript compiler options that are causing the resolution to fail. Please check your tsconfig.json for any configurations that might affect module resolution.

Unfortunately, I wasn't able to find any known issues or bugs with the Opensearch integration in the LangChain JS version 0.1.28, or any discrepancies between the LangChain JS documentation and the actual implementation that could be causing your issue. However, it's possible that I might have missed something, or that the answer may be available elsewhere.

If you're still encountering the issue after checking these potential causes, could you please provide more information about your TypeScript configuration and the exact steps you're following to integrate Opensearch with LangChain.js? This will help us to better understand the issue and provide a more accurate solution.

Sources

#### About Dosu This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot.
KeisukeNagakawa commented 5 months ago

same error: node_modules/openai/resources/beta/beta".Beta' has no exported member named 'AssistantCreateParams'. Did you mean 'AssistantUpdateParams'?

HowardIntentional commented 5 months ago

I updated my packages to match the versions in the automated response from dosubot - but still ge the same error:

{
  "name": "utils",
  "version": "1.0.0",
  "description": "",
  "main": "utils.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "node_modules/typescript/bin/tsc"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@aws-sdk/client-apigatewaymanagementapi": "^3.525.0",
    "@aws-sdk/client-dynamodb": "^3.525.0",
    "@aws-sdk/lib-dynamodb": "^3.525.0",
    "@langchain/openai": "^0.0.22",
    "@opensearch-project/opensearch": "^2.6.0",
    "@types/aws-lambda": "^8.10.130",
    "@types/node": "^20.10.5",
    "aws-sdk": "^2.1582.0",
    "aws4": "^1.12.0",
    "langchain": "^0.1.28",
    "openai": "^4.24.2",
    "typescript": "^5.4.3",
    "uuid": "^9.0.1"
  },
  "devDependencies": {
    "@types/uuid": "^9.0.8",
    "jest": "^29.7.0"
  },
  "overrides": {
    "@langchain/core": "0.1.45"
  }
}
tsc
node_modules/@langchain/openai/dist/utils/openai.d.ts:6:103 - error TS2724: '"...node_modules/openai/resources/beta/beta".Beta' has no exported member named 'AssistantCreateParams'. Did you mean 'AssistantUpdateParams'?

6 export declare function formatToOpenAIAssistantTool(tool: StructuredToolInterface): OpenAIClient.Beta.AssistantCreateParams.AssistantToolsFunction;
                                                                                                        ~~~~~~~~~~~~~~~~~~~~~

node_modules/@langchain/openai/node_modules/@langchain/core/dist/language_models/chat_models.d.ts:64:129 - error TS2304: Cannot find name 'this'.

64     _generateCached({ messages, cache, llmStringKey, parsedOptions, handledOptions, }: ChatModelGenerateCachedParameters<typeof this>): Promise<LLMResult & {
                                                                                                                                   ~~~~

node_modules/@langchain/openai/node_modules/@langchain/core/dist/language_models/llms.d.ts:66:122 - error TS2304: Cannot find name 'this'.

66     _generateCached({ prompts, cache, llmStringKey, parsedOptions, handledOptions, }: LLMGenerateCachedParameters<typeof this>): Promise<LLMResult & {
                                                                                                                            ~~~~

Found 3 errors in 3 files.

Errors  Files
     1  node_modules/@langchain/openai/dist/utils/openai.d.ts:6
     1  node_modules/@langchain/openai/node_modules/@langchain/core/dist/language_models/chat_models.d.ts:64
     1  node_modules/@langchain/openai/node_modules/@langchain/core/dist/language_models/llms.d.ts:66
dosubot[bot] commented 5 months ago

From the error messages you've shared, it seems like there are a few issues related to the @langchain/openai and @langchain/core packages. Let's address them one by one:

  1. Error in openai.d.ts: The error message suggests that the AssistantCreateParams member is not exported from the Beta module. This could be due to a version mismatch between @langchain/openai and openai. You're using @langchain/openai version ^0.0.22 and openai version ^4.24.2. Please ensure that these versions are compatible. If the error persists, you might need to use a different member that exists in the Beta module, as suggested by the error message (AssistantUpdateParams).

  2. Errors in chat_models.d.ts and llms.d.ts: These errors are related to the usage of this in a type parameter context. This is a TypeScript feature that allows a class method to refer to the class instance type with this. However, it seems like the TypeScript compiler is unable to resolve this in the context where it's used. This could be due to a TypeScript version mismatch or a bug in the @langchain/core package. You're using TypeScript version ^5.4.3, please ensure that this version is compatible with @langchain/core.

To resolve these issues, you could try the following steps:

If none of the above steps resolve the issue, please provide more information about your TypeScript configuration and the exact steps to reproduce the issue. This would help in identifying the root cause of the issue and finding a suitable solution.

Sources

#### About Dosu This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot.
kasindi commented 5 months ago

I have the same error Error: node_modules/@langchain/openai/dist/utils/openai.d.ts:6:103 - error TS2724: '"C:/IADEMO/project1/node_modules/openai/resources/beta/beta".Beta' has no exported member named 'AssistantCreateParams'. Did you mean 'AssistantUpdateParams'?

6 export declare function formatToOpenAIAssistantTool(tool: StructuredToolInterface): OpenAIClient.Beta.AssistantCreateParams.AssistantToolsFunction;

alexchavezlop commented 5 months ago

Same error here :(

node_modules/openai/resources/beta/beta".Beta' has no exported member named 'AssistantCreateParams'. Did you mean 'AssistantUpdateParams'?

6 export declare function formatToOpenAIAssistantTool(tool: StructuredToolInterface): OpenAIClient.Beta.AssistantCreateParams.AssistantToolsFunction;

Any update?

kasindi commented 5 months ago

I decide to restard my project. I do a new project.

I uninstall @angular/cli (npm uninstall -g @angular/cli) I install @angular/cli (npm install -g @angular/cli@latest) with the latest version Now it is ok.

package.json

{ "name": "chatbot", "version": "0.0.0", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "watch": "ng build --watch --configuration development", "test": "ng test" }, "private": true, "dependencies": { "@angular/animations": "^17.3.0", "@angular/common": "^17.3.0", "@angular/compiler": "^17.3.0", "@angular/core": "^17.3.0", "@angular/forms": "^17.3.0", "@angular/platform-browser": "^17.3.0", "@angular/platform-browser-dynamic": "^17.3.0", "@angular/router": "^17.3.0", "@langchain/community": "^0.0.43", "@langchain/core": "^0.1.52", "@langchain/openai": "^0.0.24", "cheerio": "^1.0.0-rc.12", "langchain": "^0.1.30", "rxjs": "~7.8.0", "tslib": "^2.3.0", "zone.js": "~0.14.3" }, "devDependencies": { "@angular-devkit/build-angular": "^17.3.2", "@angular/cli": "^17.3.2", "@angular/compiler-cli": "^17.3.0", "@types/jasmine": "~5.1.0", "jasmine-core": "~5.1.0", "karma": "~6.4.0", "karma-chrome-launcher": "~3.2.0", "karma-coverage": "~2.2.0", "karma-jasmine": "~5.1.0", "karma-jasmine-html-reporter": "~2.1.0", "typescript": "~5.4.2" } }

alexchavezlop commented 5 months ago

@kasindi I did the same thing and it still has an error :(

"dependencies": { "@angular/animations": "^17.3.2", "@angular/common": "^17.3.2", "@angular/compiler": "^17.3.2", "@angular/core": "^17.3.2", "@angular/forms": "^17.3.2", "@angular/platform-browser": "^17.3.2", "@angular/platform-browser-dynamic": "^17.3.2", "@angular/router": "^17.3.2", "@ant-design/icons-angular": "^17.0.0", "@arcgis/core": "^4.28.10", "@langchain/community": "^0.0.43", "@langchain/core": "^0.1.52", "@langchain/openai": "^0.0.25", "keycloak-angular": "^14.1.0", "keycloak-js": "^22.0.4", "langchain": "^0.1.30", "ng-zorro-antd": "16.1.0", "ngx-cookie-service": "^16.1.0", "rxjs": "~7.8.0", "tslib": "^2.3.0", "zone.js": "~0.14.4" }, "devDependencies": { "@angular-devkit/build-angular": "^17.3.2", "@angular/cli": "^17.3.2", "@angular/compiler-cli": "^17.3.2", "@types/jasmine": "~4.3.0", "jasmine-core": "~4.6.0", "karma": "~6.4.0", "karma-chrome-launcher": "~3.2.0", "karma-coverage": "~2.2.0", "karma-jasmine": "~5.1.0", "karma-jasmine-html-reporter": "~2.1.0", "typescript": "~5.4.3" }

Error:

...openai/resources/beta/beta".Beta' has no exported member named 'AssistantCreateParams'. Did you mean 'AssistantUpdateParams'?

6 export declare function formatToOpenAIAssistantTool(tool: StructuredToolInterface): OpenAIClient.Beta.AssistantCreateParams.AssistantToolsFunction

roshie548 commented 5 months ago

npm i -S openai@4.26.0 fixed the AssistantCreateParams error for me.

alexchavezlop commented 5 months ago

@roshie548 npm i -S openai@4.26.0 work here. Thanks !!!

bradleat commented 4 months ago

It looks like

export declare function formatToOpenAIAssistantTool(tool: StructuredToolInterface): OpenAIClient.Beta.AssistantCreateParams.AssistantToolsFunction;

should be replaced with

export declare function formatToOpenAIAssistantTool(
  tool: StructuredToolInterface,
): OpenAIClient.Beta.AssistantTool;
bradleat commented 4 months ago

For a temporary workout around put the following in your package.json

"overrides": {
    "@langchain/openai": {
      "openai": "4.26.0"
    }
  }

You have to delete the existing openai from your package-lock.json and node_modules for this to actually work on the next npm install

jacoblee93 commented 4 months ago

Sorry about the delay - this should be fixed by #4974

jacoblee93 commented 4 months ago

Bumping to latest langchain@0.1.31 and @langchain/openai@0.0.26 should fix the most recent iteration of this - apologies for the delay!

sudheer0071 commented 4 months ago

Bumping to latest langchain@0.1.31 and @langchain/openai@0.0.26 should fix the most recent iteration of this - apologies for the delay!

thank you sir , this is really fixed my issue!