langchain-ai / langchainjs

πŸ¦œπŸ”— Build context-aware reasoning applications πŸ¦œπŸ”—
https://js.langchain.com/docs/
MIT License
12.8k stars 2.21k forks source link

[Feature Request] BunJs Support #798

Closed LuisMalhadas closed 1 year ago

LuisMalhadas commented 1 year ago

I have been working with BunJS runtime and decided to try langchain with it. I also noted in documentation that there are some supported runtimes... Also this discussion (pointed to me by @homanp) has someone stating it supports it, but not every part. So it seems that it is not fully compatible with Bun... It imports, instantiates the model, but doesn't execute it. Am I doing something wrong?

import { OpenAI } from "langchain/llms/openai";
console.log("imported");
const model = new OpenAI({ openAIApiKey: "sk-...", temperature: 0.7 });
console.log("model created")
const res = await model.call(
    "What would be a good company name a company that makes colorful socks?"
);
console.log(res);

Running the example:

% bun index.ts
imported
model created
38 |         const PQueue = "default" in PQueueMod ? PQueueMod.default : PQueueMod;
39 |         this.queue = new PQueue({ concurrency: this.maxConcurrency });
40 |     }
41 |     // eslint-disable-next-line @typescript-eslint/no-explicit-any
42 |     call(callable, ...args) {
43 |         return this.queue.add(() => pRetry(() => callable(...args).catch((error) => {
                   ^
TypeError: undefined is not a function (near '...this.queue.add...')
      at call (/Users/luismal/Projects/bunjs+langchainjs/node_modules/langchain/dist/util/async_caller.js:43:15)
      at /Users/luismal/Projects/bunjs+langchainjs/node_modules/langchain/dist/llms/openai.js:312:15
      at completionWithRetry (/Users/luismal/Projects/bunjs+langchainjs/node_modules/langchain/dist/llms/openai.js:300:30)
      at /Users/luismal/Projects/bunjs+langchainjs/node_modules/langchain/dist/llms/openai.js:270:24
      at _generate (/Users/luismal/Projects/bunjs+langchainjs/node_modules/langchain/dist/llms/openai.js:204:20)
      at /Users/luismal/Projects/bunjs+langchainjs/node_modules/langchain/dist/llms/base.js:43:27
shanginn commented 1 year ago

same here.

although I had it working here, but now I'm trying to do summarization example and it does not work with Bun

dosubot[bot] commented 1 year ago

Hi, @LuisMalhadas! I'm here to help the LangChain team manage their backlog, and I wanted to let you know that we are marking this issue as stale.

From what I understand, you requested support for BunJs in the LangChain library, but encountered an issue where the model doesn't fully execute. Another user, @shanginn, also experienced the same problem and shared a link to their code where it was previously working.

It seems that the issue has been resolved, as @shanginn found a workaround. However, before we close this issue, we wanted to check with you if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days.

Thank you for your understanding and contribution to the LangChain project!

AlexZoningOut commented 1 year ago

Is it working now?

JamesClarke7283 commented 7 months ago

Is it working now?

It works for me.

➜  LangChainUtils bun src/test-bun.js        
imported
model created

"RainbowTread Socks" or "VibrantSoles Co."