langchain-ai / langchainjs

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

Need more types exported from langchain/memory #2975

Closed curthipster closed 10 months ago

curthipster commented 11 months ago

The BaseMemory class references several types that are not exported from the package: InputValues, OutputValues, and MemoryVariables.

Can you export them so that we can reference them in our memory implementations?

dosubot[bot] commented 11 months ago

🤖

Hello,

Thank you for reaching out. The InputValues, OutputValues, and MemoryVariables types are indeed being exported from the langchain/src/memory/base.ts file. You can import them in your memory implementations like this:

import { InputValues, OutputValues, MemoryVariables } from 'langchain/src/memory/base';

Here are the lines where these types are being exported:

export type InputValues = Record<string, any>;
export type OutputValues = Record<string, any>;
export type MemoryVariables = Record<string, any>;

These types are aliases for a record where the keys are strings and the values can be any type. They are used to represent the input values for a Chain, the output values from a Chain, and the memory variables in a Chain, respectively.

You can find these exports in the langchain/src/memory/base.ts file.

Please let me know if you have any other questions or need further clarification.

Best regards.

Sources


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.

curthipster commented 11 months ago

@dosu-bot That didn't exactly make it work, but I was able to get it to compile using import { InputValues, OutputValues, MemoryVariables } from 'langchain/dist/memory/base'.

dosubot[bot] commented 11 months ago

🤖

Hello,

The issue you're experiencing is likely due to the fact that the 'langchain/src/memory/base' file is written in TypeScript, while your project is likely using JavaScript.

When you import from 'langchain/src/memory/base', you're trying to import from the TypeScript source file directly. However, JavaScript doesn't understand TypeScript syntax, so it can't import the types or classes from the TypeScript file.

On the other hand, 'langchain/dist/memory/base' is the compiled version of the TypeScript file. When TypeScript code is compiled, it's transformed into JavaScript code that can be understood by the JavaScript runtime. That's why you're able to import the InputValues, OutputValues, and MemoryVariables types from 'langchain/dist/memory/base' - because it's JavaScript, not TypeScript.

In general, when using a library or framework that's written in TypeScript in a JavaScript project, you should always import from the compiled JavaScript files (usually found in a 'dist' directory), not the TypeScript source files.

You can find more details about the structure of the 'langchain/src/memory/base' file in the langchainjs codebase.

I hope this helps! If you have any other questions, feel free to ask.

Best, Dosu

Sources


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.

curthipster commented 11 months ago

My project is TypeScript. Perhaps the issue is my typescript config.

This technique is working for me, but I don't like that I have to import from deep within the package. It would be great if the types were actually exported from the module so that we don't have to deeply import from subfolders.

jacoblee93 commented 10 months ago

We can do this, yes.

jacoblee93 commented 10 months ago

Merged in #2993, will available under langchain/memory in the next release