Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support serverless environments #633

Closed
homanp opened this issue Apr 5, 2023 · 15 comments · Fixed by #632
Closed

Support serverless environments #633

homanp opened this issue Apr 5, 2023 · 15 comments · Fixed by #632
Labels
env/packaging Issues related to packaging/bundling

Comments

@homanp
Copy link

homanp commented Apr 5, 2023

Summary

Would be great if this package could support serverless environments such as NextJS route handlers. Specifically the streaming part.

Being able to have langchain and the UI of an application on the same infra saves a lot of time and complexity.

References

vercel/next.js#9965 (comment)

#378

#62

@nfcampos nfcampos added the env/packaging Issues related to packaging/bundling label Apr 6, 2023
@leerobert
Copy link
Contributor

leerobert commented Apr 7, 2023

In the same vein, Deno functions that were once working for me (v0.0.36) are now erroring out with:

When attempting to import:

import { VectorStore } from 'https://esm.sh/langchain@0.0.36/vectorstores';
import { Document } from 'https://esm.sh/langchain@0.0.36/document';

import type { SupabaseClient } from 'https://esm.sh/@supabase/supabase-js@2.12.0';
import type { Embeddings } from 'https://esm.sh/langchain@0.0.36/embeddings';
Download https://esm.sh/error.js?type=unsupported-nodejs-builtin-module&name=fs/promises&importer=langchain
serving function find_documents

Seems like the next step here is building an edge specific build.

@jameswong3388
Copy link

Any update on this now ?

@homanp
Copy link
Author

homanp commented Apr 8, 2023

Any update on this now ?

I'm trying this on Vercel:

#378 (comment)

@leerobert
Copy link
Contributor

I believe @nfcampos is working on creating a separate env build for edge. Would need to disable all nodejs stubs such as fs, etc. Probably the easiest solution to this.

@nfcampos
Copy link
Collaborator

nfcampos commented Apr 8, 2023

Could you try with the latest version? It worked for me when used inside Supabase edge functions, which is deno

In the same vein, Deno functions that were once working for me (v0.0.36) are now erroring out with:

When attempting to import:

import { VectorStore } from 'https://esm.sh/langchain@0.0.36/vectorstores';

import { Document } from 'https://esm.sh/langchain@0.0.36/document';



import type { SupabaseClient } from 'https://esm.sh/@supabase/supabase-js@2.12.0';

import type { Embeddings } from 'https://esm.sh/langchain@0.0.36/embeddings';

Download https://esm.sh/error.js?type=unsupported-nodejs-builtin-module&name=fs/promises&importer=langchain

serving function find_documents

Seems like the next step here is building an edge specific build.

@leerobert
Copy link
Contributor

Could you try with the latest version? It worked for me when used inside Supabase edge functions, which is deno

In the same vein, Deno functions that were once working for me (v0.0.36) are now erroring out with:
When attempting to import:

import { VectorStore } from 'https://esm.sh/langchain@0.0.36/vectorstores';

import { Document } from 'https://esm.sh/langchain@0.0.36/document';



import type { SupabaseClient } from 'https://esm.sh/@supabase/supabase-js@2.12.0';

import type { Embeddings } from 'https://esm.sh/langchain@0.0.36/embeddings';

Download https://esm.sh/error.js?type=unsupported-nodejs-builtin-module&name=fs/promises&importer=langchain

serving function find_documents

Seems like the next step here is building an edge specific build.

@nfcampos I can confirm v0.0.50 solves my supabase edge functions issues (deno importing of langchain).

@nfcampos
Copy link
Collaborator

Hi, edge/browser support has been published as a prerelease, you can install the prerelease with npm i langchain@next to try it out before we release to everyone.

See upgrade instructions here https://langchainjs-docs-git-nc-test-exports-cf-langchain.vercel.app/docs/getting-started/install you'll need to update import paths, see the link for more details

If you test it let me know any issues!

@leerobert
Copy link
Contributor

@nfcampos I'm getting:

worker thread panicked ReferenceError: window is not defined
    at https://esm.sh/v114/form-data@4.0.0/esnext/form-data.mjs:24:59
    at https://esm.sh/v114/form-data@4.0.0/esnext/form-data.mjs:6:27
    at https://esm.sh/v114/form-data@4.0.0/esnext/form-data.mjs:32:11

when importing
import { OpenAIEmbeddings } from 'https://esm.sh/langchain@next/embeddings/openai';

in a supabase function

@nfcampos
Copy link
Collaborator

@nfcampos I'm getting:

worker thread panicked ReferenceError: window is not defined
    at https://esm.sh/v114/form-data@4.0.0/esnext/form-data.mjs:24:59
    at https://esm.sh/v114/form-data@4.0.0/esnext/form-data.mjs:6:27
    at https://esm.sh/v114/form-data@4.0.0/esnext/form-data.mjs:32:11

when importing import { OpenAIEmbeddings } from 'https://esm.sh/langchain@next/embeddings/openai';

in a supabase function

Intersting I don't get that, can you confirm this is when running supabase functions serve? Which version of supabase CLI?

@leerobert
Copy link
Contributor

leerobert commented Apr 10, 2023

@nfcampos I'm getting:

worker thread panicked ReferenceError: window is not defined
    at https://esm.sh/v114/form-data@4.0.0/esnext/form-data.mjs:24:59
    at https://esm.sh/v114/form-data@4.0.0/esnext/form-data.mjs:6:27
    at https://esm.sh/v114/form-data@4.0.0/esnext/form-data.mjs:32:11

when importing import { OpenAIEmbeddings } from 'https://esm.sh/langchain@next/embeddings/openai';
in a supabase function

Intersting I don't get that, can you confirm this is when running supabase functions serve? Which version of supabase CLI?

v1.40.1 and v1.50.1 and on supabase functions serve locally. I did upgrade to the latest CLI via homebrew tho and I think it messed up my local environment. I'm trying to wipe and start from scratch & confirm this isn't a badly formed dev environment first.

@nfcampos
Copy link
Collaborator

@leerobert cool let me know how you get on. we also have this template, which might help https://github.com/langchain-ai/langchain-template-supabase

@leerobert
Copy link
Contributor

@leerobert cool let me know how you get on. we also have this template, which might help https://github.com/langchain-ai/langchain-template-supabase

I set up this project locally starting completely fresh and installed according to your README and got:

yarn supabase:dev
yarn run v1.22.19
$ supabase functions serve --env-file supabase/.env
Setting up Edge Functions runtime...
Serving functions on http://localhost:50321/functions/v1/<function-name>
serving the request with /home/deno/functions/chat
Download https://deno.land/std@0.177.0/http/server.ts
Download https://esm.sh/langchain@0.0.51/chat_models
Download https://esm.sh/langchain@0.0.51/chains
Download https://esm.sh/langchain@0.0.51/callbacks
Download https://esm.sh/langchain@0.0.51/prompts
Download https://deno.land/std@0.177.0/async/mod.ts
Download https://deno.land/std@0.177.0/async/abortable.ts
Download https://deno.land/std@0.177.0/async/deadline.ts
Download https://deno.land/std@0.177.0/async/debounce.ts
Download https://deno.land/std@0.177.0/async/deferred.ts
Download https://deno.land/std@0.177.0/async/delay.ts
Download https://deno.land/std@0.177.0/async/mux_async_iterator.ts
Download https://deno.land/std@0.177.0/async/pool.ts
Download https://deno.land/std@0.177.0/async/tee.ts
Download https://deno.land/std@0.177.0/async/retry.ts
Download https://esm.sh/v114/langchain@0.0.51/esnext/prompts.js
Download https://esm.sh/v114/langchain@0.0.51/esnext/chains.js
Download https://esm.sh/v114/langchain@0.0.51/esnext/callbacks.js
Download https://esm.sh/v114/langchain@0.0.51/esnext/chat_models.js
Download https://esm.sh/v114/node_process.js
Download https://esm.sh/v114/yaml@2.2.1/esnext/yaml.mjs
Download https://esm.sh/v114/exponential-backoff@3.1.1/esnext/exponential-backoff.mjs
Download https://esm.sh/v114/p-queue@6.6.2/esnext/p-queue.mjs
Download https://esm.sh/v114/axios@1.3.5/esnext/axios.mjs
Download https://esm.sh/v114/@fortaine/fetch-event-source@3.0.6/esnext/fetch-event-source.mjs
Download https://esm.sh/v114/@fortaine/fetch-event-source@3.0.6/esnext/parse.js
Download https://esm.sh/v114/openai@3.2.1/esnext/openai.mjs
Download https://esm.sh/v114/node_events.js
Download https://esm.sh/v114/@anthropic-ai/sdk@0.4.3/esnext/sdk.mjs
Download https://esm.sh/v114/p-timeout@3.2.0/esnext/p-timeout.mjs
Download https://esm.sh/v114/eventemitter3@4.0.7/esnext/eventemitter3.mjs
Download https://esm.sh/v114/axios@0.26.1/esnext/axios.mjs
Download https://esm.sh/v114/form-data@4.0.0/esnext/form-data.mjs
Download https://esm.sh/v114/node_buffer.js
Download https://esm.sh/v114/p-finally@1.0.0/esnext/p-finally.mjs
Download https://esm.sh/v114/cross-fetch@3.1.5/esnext/cross-fetch.mjs
worker thread panicked TypeError: U.accessor is not a function
    at https://esm.sh/v114/axios@1.3.5/esnext/axios.mjs:702:3
serving the request with /home/deno/functions/chat
serving the request with /home/deno/functions/chat
worker thread panicked TypeError: U.accessor is not a function
    at https://esm.sh/v114/axios@1.3.5/esnext/axios.mjs:702:3
worker thread panicked TypeError: U.accessor is not a function
    at https://esm.sh/v114/axios@1.3.5/esnext/axios.mjs:702:3
serving the request with /home/deno/functions/chat
serving the request with /home/deno/functions/chat

Similar error that I'm seeing on my side of the house as well.

@nfcampos
Copy link
Collaborator

This works for me with

supabase --version
1.49.4

Can you confirm yours?

@leerobert
Copy link
Contributor

This works for me with

supabase --version
1.49.4

Can you confirm yours?

Can confirm when I update the package.json

"devDependencies": {
    "supabase": "1.49.4"
  }

Then it works. Supbase' latest CLI must corrupt things. Might want to lock in teh supabase CLI for the time being

@nfcampos
Copy link
Collaborator

This works for me with

supabase --version
1.49.4

Can you confirm yours?

Can confirm when I update the package.json

"devDependencies": {
    "supabase": "1.49.4"
  }

Then it works. Supbase' latest CLI must corrupt things. Might want to lock in teh supabase CLI for the time being

Ah I see, I'll pin it and pick it up with supabase, hopefully they can get it fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
env/packaging Issues related to packaging/bundling
Projects
None yet
4 participants