langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
93.05k stars 14.96k forks source link

[Feature Request] BunJs Support #2888

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... 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
homanp commented 1 year ago

This should be posted in the langchainjs repo: https://github.com/hwchase17/langchainjs

Also check out this discussion: https://github.com/hwchase17/langchainjs/discussions/152

LuisMalhadas commented 1 year ago

You are right, sorry. I also took a look at the discussion, voted, and upvoted the bun request comment. :) Saw that someone already claimed support for bun, but not all parts of langchain, I guess. Anyway, I'll close this and repost on the proper rep.