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

Receiving 404 when calling edge function with langchain libraries in import_map.json #401

Open
2 tasks done
iliskhan opened this issue Aug 22, 2024 · 5 comments
Open
2 tasks done
Labels
bug Something isn't working category: hosted

Comments

@iliskhan
Copy link

iliskhan commented Aug 22, 2024

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

When running the edge function locally, everything works as expected. However, after deploying it to production, I receive a 404 error in the invocations section of the monitoring dashboard. The logs section does not display any information, making it difficult to diagnose the issue.

I suspect that the problem is related to the Langchain libraries included in the import_map.json file. I identified this by commenting out all imports and then uncommenting them one by one until the error reappeared. Previously, I encountered a similar issue and resolved it by adjusting the import sources (some libraries were imported from npm, others from esm). However, this time, I have tried multiple sources, but the problem persists.

To Reproduce

Steps to reproduce the behavior:

  1. Deploy the edge function with Langchain libraries included in the import_map.json file.
  2. Attempt to invoke the function in the production environment.
  3. Check the invocations section in the monitoring dashboard and observe the 404 error.
  4. Notice that no logs are generated in the logs section.

Expected behavior

The edge function should execute successfully without a 404 error, and logs should be generated to assist in troubleshooting.

Screenshots

image

System information

  • OS: [e.g. macOS, Windows]
  • Browser (if applies) [e.g. chrome, safari]
  • Version of supabase-js: [e.g. 6.0.2]
  • Version of Node.js: [e.g. 10.10.0]

Additional context

To rule out potential network issues related to accessing npm and esm in different regions, I created a separate project and deployed it in another country, but the issue persisted.

import_map.json

{
  "imports": {
    "axios": "npm:[email protected]",

    "zod": "https://deno.land/x/[email protected]/index.ts",
    "djwt": "https://deno.land/x/[email protected]/mod.ts",
    "zod/types": "https://deno.land/x/[email protected]/types.ts",

    "cron-parser": "https://esm.sh/[email protected]",

    "@langchain/openai": "https://esm.sh/@langchain/[email protected]",

    "@langchain/langgraph": "npm:@langchain/[email protected]",
    "@langchain/langgraph/prebuilt": "npm:@langchain/[email protected]/prebuilt",

    "@langchain/core": "npm:@langchain/[email protected]",
    "@langchain/core/tools": "npm:@langchain/[email protected]/tools",
    "@langchain/core/agents": "npm:@langchain/[email protected]/agents",
    "@langchain/core/prompts": "npm:@langchain/[email protected]/prompts",
    "@langchain/core/messages": "npm:@langchain/[email protected]/messages",
    "@langchain/core/runnables": "npm:@langchain/[email protected]/runnables",
    "@langchain/core/callbacks/manager": "npm:@langchain/[email protected]/callbacks/manager",
    "@langchain/core/utils/function_calling": "npm:@langchain/[email protected]/utils/function_calling"
  }
}
@iliskhan iliskhan added the bug Something isn't working label Aug 22, 2024
@danielpgauer
Copy link

danielpgauer commented Aug 22, 2024

I have run into the same problem.
After redeploying, everything works fine again, but the issue reappears after a few days

@encima
Copy link
Member

encima commented Aug 23, 2024

Thanks for reporting! Which module in particular is causing the 404?

Transferring to edge functions repo for visibility

@encima encima transferred this issue from supabase/supabase Aug 23, 2024
@iliskhan
Copy link
Author

Which module in particular is causing the 404?

I noticed that the error mainly occurs because of @langchain/openai which under the hood simply uses openai

@iliskhan
Copy link
Author

I also built all the libraries manually and linked to my builds on GitHub and now everything works fine in production

my current import_map.json

{
  "imports": {
    "zod": "https://deno.land/x/[email protected]/index.ts",
    "djwt": "https://deno.land/x/[email protected]/mod.ts",
    "semver": "https://deno.land/[email protected]/semver/mod.ts",
    "p-queue": "https://deno.land/x/[email protected]/mod.ts",
    "zod/types": "https://deno.land/x/[email protected]/types.ts",

    "openai": "https://raw.githubusercontent.com/openai/openai-deno-build/main/mod.ts",
    "openai/helpers/zod": "https://raw.githubusercontent.com/openai/openai-deno-build/main/helpers/zod.ts",

    "axios": "npm:[email protected]",

    "uuid": "https://esm.sh/[email protected]",
    "p-retry": "https://esm.sh/[email protected]",
    "mustache": "https://esm.sh/[email protected]",
    "camelcase": "https://esm.sh/[email protected]",
    "decamelize": "https://esm.sh/[email protected]",
    "ansi-styles": "https://esm.sh/[email protected]",
    "js-tiktoken/lite": "https://esm.sh/[email protected]/lite",
    "zod-to-json-schema": "https://esm.sh/[email protected]",

    "cron-parser": "https://esm.sh/[email protected]",

    "langsmith": "https://raw.githubusercontent.com/iliskhan/langsmith-sdk/main/js/index.js",
    "langsmith/run_trees": "https://raw.githubusercontent.com/iliskhan/langsmith-sdk/main/js/run_trees.js",
    "langsmith/singletons/traceable": "https://raw.githubusercontent.com/iliskhan/langsmith-sdk/main/js/traceable.js",

    "@langchain/openai": "https://raw.githubusercontent.com/iliskhan/langchainjs/main/libs/langchain-openai/index.js",

    "@langchain/langgraph": "https://raw.githubusercontent.com/iliskhan/langgraphjs/main/langgraph/index.js",
    "@langchain/langgraph/prebuilt": "https://raw.githubusercontent.com/iliskhan/langgraphjs/main/langgraph/prebuilt.js",

    "@langchain/core/load": "https://raw.githubusercontent.com/iliskhan/langchainjs/main/langchain-core/load.js",
    "@langchain/core/tools": "https://raw.githubusercontent.com/iliskhan/langchainjs/main/langchain-core/tools.js",
    "@langchain/core/agents": "https://raw.githubusercontent.com/iliskhan/langchainjs/main/langchain-core/agents.js",
    "@langchain/core/prompts": "https://raw.githubusercontent.com/iliskhan/langchainjs/main/langchain-core/prompts.js",
    "@langchain/core/outputs": "https://raw.githubusercontent.com/iliskhan/langchainjs/main/langchain-core/outputs.js",
    "@langchain/core/messages": "https://raw.githubusercontent.com/iliskhan/langchainjs/main/langchain-core/messages.js",
    "@langchain/core/singletons": "https://raw.githubusercontent.com/iliskhan/langchainjs/main/langchain-core/singletons.js",
    "@langchain/core/runnables": "https://raw.githubusercontent.com/iliskhan/langchainjs/main/langchain-core/runnables.js",
    "@langchain/core/embeddings": "https://raw.githubusercontent.com/iliskhan/langchainjs/main/langchain-core/embeddings.js",
    "@langchain/core/output_parsers": "https://raw.githubusercontent.com/iliskhan/langchainjs/main/langchain-core/output_parsers.js",
    "@langchain/core/runnables/graph": "https://raw.githubusercontent.com/iliskhan/langchainjs/main/langchain-core/runnables/graph.js",
    "@langchain/core/output_parsers/openai_tools": "https://raw.githubusercontent.com/iliskhan/langchainjs/main/langchain-core/output_parsers/openai_tools.js",

    "@langchain/core/callbacks/manager": "https://raw.githubusercontent.com/iliskhan/langchainjs/main/langchain-core/dist/callbacks/manager.js",

    "@langchain/core/utils/env": "https://raw.githubusercontent.com/iliskhan/langchainjs/main/langchain-core/utils/env.js",
    "@langchain/core/utils/stream": "https://raw.githubusercontent.com/iliskhan/langchainjs/main/langchain-core/utils/stream.js",
    "@langchain/core/utils/chunk_array": "https://raw.githubusercontent.com/iliskhan/langchainjs/main/langchain-core/utils/chunk_array.js",
    "@langchain/core/utils/function_calling": "https://raw.githubusercontent.com/iliskhan/langchainjs/main/langchain-core/dist/utils/function_calling.js",

    "@langchain/core/language_models/base": "https://raw.githubusercontent.com/iliskhan/langchainjs/main/langchain-core/language_models/base.js",
    "@langchain/core/language_models/llms": "https://raw.githubusercontent.com/iliskhan/langchainjs/main/langchain-core/language_models/llms.js",
    "@langchain/core/language_models/chat_models": "https://raw.githubusercontent.com/iliskhan/langchainjs/main/langchain-core/language_models/chat_models.js"
  }
}

@iliskhan
Copy link
Author

"openai": "https://raw.githubusercontent.com/openai/openai-deno-build/main/mod.ts",
"openai/helpers/zod": "https://raw.githubusercontent.com/openai/openai-deno-build/main/helpers/zod.ts",

and everything breaks if I don't specify these two libraries from the openai repository, although logically there should be the same code on npm, esm, and github. Perhaps the problem is with how edge runtime works with these cdn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working category: hosted
Projects
None yet
Development

No branches or pull requests

4 participants