Langchain local setup?

Has anyone else gotten langchain setup locally? I did both “npm install -S langchain” and “npm install langchain”. Didn’t make a difference. I tried the import: Uncaught TypeError: Failed to resolve module specifier “langchain”. Relative references must start with either “/”, “./”, or “…/”. After I added the slash at the beginning of the path, the code threw this error: GET http://127.0.0.1:5500/langchain net::ERR_ABORTED 404 (Not Found)

Also, I tried to import “langchain” and “langchain/text_splitter”. Again, didn’t make a difference.

Hey @Brock, sorry for the delay. Could you check if langchain is installed correctly by going langchain -v. Just check if it’s install as it should display the version of langchain you’re running.

Could you paste your code where you’re calling the langchain (just make sure to omit any API keys)?

I got it working by downgrading to the version in the tutorial. I’ll have to find a more recent tutorial to get the latest working. But here’s what I posted in the discord:

Working from this obsolete YouTube vid, https://youtu.be/W3AoeMrg27o?t=90, I got the latest (0.1.17) imported. I got some errors about things are depreciated and to use these other things and ended up with this snippet:

import { OpenAI } from "@langchain/openai"
import * as dotenv from "dotenv"
dotenv.config()

const model = new OpenAI({
    temperature:0.9
})

const res = await model.invoke("What would be a good company name for a company that makes cosmetics from human waste?")
console.log(res)

For the text splitter, I used the “npm init -y” from the vid and installed the older version of langchain (0.0.152) from the scrimba tutorial. This code worked:

import { readFileSync } from 'fs'
import { RecursiveCharacterTextSplitter } from "langchain/text_splitter"

try {
  // Read the contents of the file
  const text = readFileSync('scrimba-info.txt', 'utf8');

  const splitter = new RecursiveCharacterTextSplitter();

  const output = await splitter.createDocuments([text]);
  console.log(output);
} catch (err) {
  console.log(err);
}

BTW I ran “langchain -v” in the terminal of my current project. LangChain is definitely working but it threw this error:
langchain : The term ‘langchain’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included,
verify that the path is correct and try again.
At line:1 char:1

  • langchain -v
  •   + CategoryInfo          : ObjectNotFound: (langchain:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException

Great to hear it’s working.

The -v command potentially could be that it’s not detecting langchain in your local directory though it seems like you’ve checked that’s the case so not too sure there…

Also I think is -s flag is not required anymore since npm has updated so it now adds the dependencies into your package. json file with the -s flag.