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

Using google-cloud/vertexai in edge environments #82

Closed
lgrammel opened this issue Dec 15, 2023 · 4 comments
Closed

Using google-cloud/vertexai in edge environments #82

lgrammel opened this issue Dec 15, 2023 · 4 comments
Labels
api: aiplatform Issues related to the googleapis/nodejs-vertexai API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@lgrammel
Copy link

Environment details

  • Programming language: JavaScript / TypeScript
  • OS: Targeting edge environments (cloudflare, vercel)
  • Package version: 0.1.3

Background

I'm implementing Gemini support for the Vercel AI SDK ( https://github.com/vercel/ai/pull/863/files ). However, when I set the runtime to 'edge', I run into the error below. My investigation showed that the auth library has several dependencies that are not supported in edge environments. Are there any guides on how to use the Vertex library in an edge environment, e.g. for streaming AI responses?

Steps to reproduce

  1. Try to use the library in a edge environment (cloudflare, vercel)
  2. Observe the following error:

image

@lgrammel lgrammel added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Dec 15, 2023
@product-auto-label product-auto-label bot added the api: aiplatform Issues related to the googleapis/nodejs-vertexai API. label Dec 15, 2023
@sararob
Copy link
Contributor

sararob commented Dec 15, 2023

You can use a bundler to remove https-proxy-agent, but depending on the environment where you're running this you may need to reimplement the crypto interface. If you do need to reimplement that piece, feel free to open a PR on google-auth-library.

@lgrammel
Copy link
Author

@sararob thanks for the quick answer. I've tried removing https-proxy-agent and configured various other related settings in the next config, but it seems that the proxy agent is a hard requirement. I'll continue to try to get it to work, was just curious if there are some working examples or guides for this setup.

next.config.js (for reference)

/** @type {import('next').NextConfig} */
const nextConfig = {
  webpack: (config, { isServer, webpack }) => {
    config.plugins.push(
      new webpack.IgnorePlugin({ resourceRegExp: /https-proxy-agent/ }),
    );

    config.resolve.fallback = {
      buffer: false,
      crypto: false,
      events: false,
      fs: false,
      http: false,
      https: false,
      net: false,
      os: false,
      path: false,
      querystring: false,
      stream: false,
      tty: false,
      util: false,
      zlib: false,
      child_process: false,
      tls: false,
    };

    return config;
  },
};

module.exports = nextConfig;

error (for reference)

 ⨯ ../node_modules/.pnpm/[email protected]/node_modules/gaxios/build/src/gaxios.js (27:0) @ <unknown>
 ⨯ Cannot find module 'https-proxy-agent'
null

@alexander-fenster
Copy link

Try using null-loader as we do in https://github.com/googleapis/google-auth-library-nodejs/blob/7ae4aaea0311de1a3e10f4e86a1ef93ff00656b5/webpack.config.js#L43-L46. It will replace the module with an empty thing, and will not fail unless it's called (and it won't be called). We don't have a good test coverage for browsers (it's not an officially supported use case), but we run some tests in browser with webpack and karma in some other repos (e.g. in google-gax) and they work with this config.

@lgrammel
Copy link
Author

@alexander-fenster thanks - I've given it a try, but ran into other issues as well and ended up needing to disable more items, which eventually led to the route not being available. We have implemented a solution with the generative ai sdk in the meantime, which works on the edge.

Abandoned PR for reference: https://github.com/vercel/ai/pull/863/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: aiplatform Issues related to the googleapis/nodejs-vertexai API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

3 participants