hwchase17 / langchain-hub

3.25k stars 266 forks source link

Langchain on AWS Lambda #20

Open ali-chaudhry8 opened 1 year ago

ali-chaudhry8 commented 1 year ago

Has anyone deployed langchain scripts on AWS - Lambda in particular. There is some issue with the way langchain imports numpy that is causing issues. I have tried it with different version and with a docker image as well but get numpy import issues. Locally it works fine.

ellisonbg commented 1 year ago

@3coins is working this and can help out.

KBB99 commented 1 year ago

I can help. You need to make sure that you are installing the langchain library in the same runtime as the lambda. If you want you can use this public Langchain layer I've made that includes Langchain and OpenAI libraries: arn:aws:lambda:us-east-1:609061237212:layer:langchain:6 . For a full implementation guide of a Langchain agent on Lambda you can check this article

animateM commented 1 year ago

Could you tell us what libraries you put in that layer? So we can update / patch / etc with the latest langchain? Would be awesome to know! I am having a heck of a time getting past this numpy error on lambda.

KBB99 commented 1 year ago

That one is using ARM64 architecture. It includes the langchain and openai packages.

animateM commented 1 year ago

Hmmm. I imported both those. All that is in a layer. Still get the numpy errors... Oh well, switch to container image and X86, cause that is pretty sure to work.

KBB99 commented 1 year ago

If someone is still looking for a Lambda layer including Langchain I just built this one and made it public: arn:aws:lambda:us-east-1:609061237212:layer:langchain:9 . It is running Langchain version 0.0.191 on ARM64 architecture and I have confirmed it's compatibility with Python3.10. To fix conflicts with boto3 I had to pin urllib<2.

animateM commented 1 year ago

Thank you. Yes, knowing exactly how you did it, so we can continue to update ourselves as langchain updates is important. I am finding that using a container image may be required just because of how large langchain libraries are.

KBB99 commented 1 year ago

Sure, I create a Codebuild job with ARM64 architecture using the latest Amazon Linux AMI and run the command mkidr package/python && pip install <package_names> --target package/python && zip -r package.zip package. I then set the artifact source to package.zip and specify an S3 bucket as the destination. Lastly, I create a Lambda layer, pointing to that zipped file in the S3 bucket. I'll try and create a blog post sometime where I go through the process in more details, but that is the high-level overview.

animateM commented 1 year ago

Awesome!


From: Kenton @.> Sent: Wednesday, June 7, 2023 12:28 PM To: hwchase17/langchain-hub @.> Cc: animateM @.>; Comment @.> Subject: Re: [hwchase17/langchain-hub] Langchain on AWS Lambda (Issue #20)

Sure, I create a Codebuild job with ARM64 architecture using the latest Amazon Linux AMI and run the command mkidr package/python && pip install --target package/python && zip -r package.zip package. I then set the artifact source to package.zip and specify an S3 bucket as the destination. Lastly, I create a Lambda layer, pointing to that zipped file in the S3 bucket. I'll try and create a blog post sometime where I go through the process in more details, but that is the high-level overview.

— Reply to this email directly, view it on GitHubhttps://github.com/hwchase17/langchain-hub/issues/20#issuecomment-1581164495, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACDNKRBIK24SH4YIWSYIKPTXKCT4PANCNFSM6AAAAAAVL6V2ZE. You are receiving this because you commented.Message ID: @.***>