supabase edge functions rag
1.0.0
在Supabase Edge功能中安装NPM软件包,如果您熟悉Supabase Edge功能,则可能知道安装NPM软件包不像典型的Node.js或Express应用程序那样简单。但是,有几种方法可以在supabase边缘函数中包含NPM软件包。在本指南中,我将演示如何使用import_map.json文件实现此目的。
确保将Docker安装在计算机上。
选择您的目录并运行以下命令:
npx supabase init这将在您的目录中创建一个supabase文件夹。
运行以下命令开始项目:
npx supabase start此过程可能需要几分钟,因为它可以拉出Docker图像并启动容器。
打开您喜欢的代码编辑器中的目录,然后运行以下命令以创建一个新的supabase边缘函数:
npx supabase functions new < your-function-name >这将创建一个文件夹,其中包含您在functions目录中的函数名称。
您可以安装任何NPM软件包。对于此示例,我们将安装Langchain软件包以创建基本的RAG管道。
import_map.json在您的functions文件夹中创建一个名为import_map.json的文件,并添加以下JSON块:
{
"imports" : {
"@supabase/supabase-js" : " npm:@supabase/[email protected] " ,
"langchain/" : " https://esm.sh/[email protected]/ " ,
"@langchain/openai/" : " https://esm.sh/@langchain/[email protected]/ " ,
"@langchain/core/" : " https://esm.sh/@langchain/[email protected]/ " ,
"@langchain/community/" : " https://esm.sh/@langchain/[email protected]/ "
}
}如果要使用NPM软件包的子模型,请确保在软件包名称的末尾添加A
/。有关参考,请参见@supabase/supabase-js的导入以及其余的langchain软件包。
确保您的项目与您的Supabase Cloud项目链接。
要将边缘函数部署到supabase,请运行以下命令:
npx supabase functions deploy此命令将部署所有功能。
要部署特定功能,请使用:
npx supabase functions deploy < function-name >