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

ChatOpenAI breaks edge streaming on Vercel Edge functions. #3092

Closed
oalexdoda opened this issue Oct 29, 2023 · 7 comments · Fixed by #3149
Closed

ChatOpenAI breaks edge streaming on Vercel Edge functions. #3092

oalexdoda opened this issue Oct 29, 2023 · 7 comments · Fixed by #3149
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature auto:improvement Medium size change to existing code to handle new use-cases

Comments

@oalexdoda
Copy link

ChatOpenAI breaks edge streaming on Vercel Edge functions.

Error:

../../node_modules/.pnpm/openai@4.4.0/node_modules/openai/core.mjs
A Node.js API is used (process.arch at line: 531) which is not supported in the Edge Runtime.

Import trace for requested module:

../../node_modules/.pnpm/openai@4.4.0/node_modules/openai/core.mjs
../../node_modules/.pnpm/openai@4.4.0/node_modules/openai/index.mjs
../../node_modules/.pnpm/langchain@0.0.175_axios@1.6.0_mammoth@1.6.0/node_modules/langchain/dist/chat_models/openai.js
../../node_modules/.pnpm/langchain@0.0.175_axios@1.6.0_mammoth@1.6.0/node_modules/langchain/chat_models/openai.js

...

The import causing the error:
import { ChatOpenAI } from 'langchain/chat_models/openai';

Potential Solution:
If the native OpenAI library doesn't support edge streaming / functions, then LangChain should implement that chat module via a native fetch.

@dosubot dosubot bot added auto:bug Related to a bug, vulnerability, unexpected error with an existing feature auto:improvement Medium size change to existing code to handle new use-cases labels Oct 29, 2023
@jacoblee93
Copy link
Collaborator

What bundler are you using?

Have noticed this warning in our tests but we use this live in production with Webpack + Next pretty frequently, so I assumed the bundler was smart enough to filter it out:

https://github.com/langchain-ai/langchain-nextjs-template

@oalexdoda
Copy link
Author

What bundler are you using?

Have noticed this warning in our tests but we use this live in production with Webpack + Next pretty frequently, so I assumed the bundler was smart enough to filter it out:

https://github.com/langchain-ai/langchain-nextjs-template

Next.js with Webpack, but I have this custom config - not sure if it matters:

const { withDev } = require('@destacked/dev');
const { withSentryConfig } = require('@sentry/nextjs');

const withBundleAnalyzer = require('@next/bundle-analyzer')({
	enabled: process.env.ANALYZE === 'true',
	openAnalyzer: false
});

const config = {
	webpack: (config) => {
		if (process.env.NODE_ENV === 'development') {
			config.watchOptions = {
				poll: 10000
			};
		}

		config.module.rules.push({
			test: /\.XXXXXXXXXX.txt$/,
			type: 'asset/source'
		});

		return config;
	},
	experimental: {
		useDeploymentId: true,
		webpackBuildWorker: true
	},
	transpilePackages: [
		'@destacked/js',
		'@destacked/server',
		'@destacked/interface',
		'@destacked/layouts',
		'@destacked/apps-gleap',
		'@destacked/apps-mirror',
		'@tabler/icons-react'
	],
	poweredByHeader: false,
	sentry: {
		hideSourceMaps: true,
		widenClientFileUpload: true
	},
	images: {
		dangerouslyAllowSVG: true,
		remotePatterns: [
			{ hostname: 'XXXXXXXXXX' }
		]
	},
	async rewrites() {
		return [
			{
				source: '/XXXXXXXXXX',
				destination: 'XXXXXXXXXX'
			}
		];
	},
	async redirects() {
		return [
			{
				source: '/XXXXXXXXXX',
				destination: 'XXXXXXXXXX',
				permanent: false
			},
		];
	}
};

module.exports = withSentryConfig(withBundleAnalyzer(withDev(config)), {
	org: 'XXXXXXXXXX',
	project: 'XXXXXXXXXX',
	silent: true
});

@jacoblee93
Copy link
Collaborator

CC @rattrayalex is it possible to remove references like this?

@rattrayalex
Copy link

rattrayalex commented Nov 3, 2023

Hey @jacoblee93 , thanks for the ping. We don't actually call that at runtime on that platform, so I'd consider it a bug/problem with the import tracer… but I can see if I can move that code into another file to make this easier.

@rattrayalex
Copy link

Ah, I see the user is on openai@4.4.0, can you try with a later version? We've made improvements to related areas and I wonder if it'd be fixed.

Also, I'm a bit surprised to see .cjs used in a Next build instead of .mjs, know what might be up with that?

@jacoblee93
Copy link
Collaborator

Yes, definitely a bundler/chunking issue.

Ok will try bumping the version! Thanks for the look.

@jacoblee93
Copy link
Collaborator

jacoblee93 commented Nov 3, 2023

Please reopen if this persists past the next release (0.0.180)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature auto:improvement Medium size change to existing code to handle new use-cases
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants