vercel / ai

Build AI-powered applications with React, Svelte, Vue, and Solid
https://sdk.vercel.ai/docs
Other
8.58k stars 1.21k forks source link

Module not found: Can't resolve 'http' (Google PaLM model integration through Langchain JS and Vercel AI SDK #590

Closed luisrivash closed 7 months ago

luisrivash commented 9 months ago

Hi, I'm trying to use Langchain JS with the Google PaLM integration, trying to use the Vercel AI SDK, but I'm getting these errors:

error ./node_modules/agent-base/dist/helpers.js:27:26 Module not found: Can't resolve 'http' Then: Module not found: Can't resolve 'stream' Module not found: Can't resolve 'crypto' This is the traceback: Import trace for requested module: ./node_modules/agent-base/dist/index.js ./node_modules/https-proxy-agent/dist/index.js ./node_modules/gaxios/build/src/gaxios.js ./node_modules/gaxios/build/src/index.js ./node_modules/google-auth-library/build/src/transporters.js ./node_modules/google-auth-library/build/src/index.js ./node_modules/langchain/dist/llms/googlepalm.js ./node_modules/langchain/llms/googlepalm.js ./src/app/api/langchain/route.js

I've followed the instruction in this page for using Google PaLM model: https://js.langchain.com/docs/modules/model_io/models/llms/integrations/google_palm

Also, I copied this sample code from Vercel page: vhttps://sdk.vercel.ai/docs/guides/providers/langchain

Substituting OpenAI model with the Google PaLM model from above, and I get those errors:

Also, when installing both libraries, I got this dependency error:

While resolving: langchain@0.0.153 npm ERR! Found: @google-ai/generativelanguage@1.1.0 npm ERR! node_modules/@google-ai/generativelanguage npm ERR! @google-ai/generativelanguage@"^1.1.0" from the root project

How can I solve it

kevsjh commented 8 months ago

If you are cloning from vercel ai template, remove the edge runtime for the backend API, this will default the runtime to nodejs.

// export const runtime = "edge"; It seems that langchain support for Google Palm is limited to node runtime as for now

luokerenx4 commented 4 months ago

If you are cloning from vercel ai template, remove the edge runtime for the backend API, this will default the runtime to nodejs.

// export const runtime = "edge"; It seems that langchain support for Google Palm is limited to node runtime as for now

It also works to me. I set a proxy to port 7890 of OpenAI then the API route reports bugs. I think http package is not supported by Edge Runtime. So when you want to use proxy, remove the edge runtime will save lots of time for you.