-
Notifications
You must be signed in to change notification settings - Fork 16.2k
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
Langchain with AWS Lambda #1364
Comments
We are working to get it moved over to the GitHub org of @hwchase17 but here is the repo with a working AWS deployment template for Lambda: |
I deployed https://github.com/3coins/langchain-aws-template in my aws account. However, API is throwing 'internal server error '. Will debug more today. |
@gitmj |
Here is the body used : {"prompt": "explain code: print("Hello world")", "session_id": ""} and attached logs when I tested on API gateway console |
I debugged it further and it was related to openai key. After setting up the aws secrets again, I got the following response so all is good. Thanks for the template, Now I will try to use it for my specific use case. {"response": "Sure! This code is a simple example of printing a text message to the console. In this case, "Hello world" is the message that will be printed. The "print" function is a built-in function in Python that allows you to print messages to the console.", "session_id": "7eec9625-b034-46a6-a454-d2b87302bbf0"} |
Great, let us know if we can improve the documentation.
…On Wed, Mar 29, 2023 at 11:52 AM gitmj ***@***.***> wrote:
I debugged it further and it was related to openai key. After setting up
the aws secrets again, I got the following response so all it good. Thanks
for the template, Now I will try to use it for my specific use case.
{"response": "Sure! This code is a simple example of printing a text
message to the console. In this case, "Hello world" is the message that
will be printed. The "print" function is a built-in function in Python that
allows you to print messages to the console.", "session_id":
"7eec9625-b034-46a6-a454-d2b87302bbf0"}
—
Reply to this email directly, view it on GitHub
<#1364 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAGXUD5SSW3AFPHAOT5KTDW6SAFPANCNFSM6AAAAAAVMFLOME>
.
You are receiving this because you commented.Message ID:
***@***.***>
--
Brian E. Granger
Senior Principal Technologist, AWS AI/ML ***@***.***)
On Leave - Professor of Physics and Data Science, Cal Poly
@ellisonbg on GitHub
|
@3coins Thank you for creating this template! I was hoping you could help me figure out an error I'm running into. I followed all the steps to deploy the "service" example, but when I get to the cdk bootstrap command, I get the following error:
Shouldn't this module be installed when I spin up the environment using the environment.yaml file? |
@AreJay-Smith |
@gitmj Hi, could you please elaborate a bit more on how you set up the aws secrets and solved this issue? I'm facing the same problem here, and I tried reset my aws secrets a few times, but it didn't work... |
I had the same problem while using langchain in AWS Lambda, the way I resolved this by downloading the numpy files from here from the PyPi numpy files download page. Once downloaded, unzip the whl into your virtual environment's site-packages directory. Now package the dependencies for the Lambda into a zip file as usual (I was using the Python 3.9 runtime). |
Hi, I'm fairly new to both AWS and LangChain, and I'd like to deploy my code (similar to this found in LangChain's documentation) onto AWS Lambda. Would this be possible using JavaScript? If so, are there are examples/resources that I can refer to? |
@francisurias |
Thanks for the reply, I'll try using the CDK today. Also, I tried simply putting ConversationalRetrievalQAChain ) into an AWS Lambda function, but I get this error: Update: I changed the vectorstore I'm using from HNSWLib to MemoryVectorStore and it seems to be working; still not really sure why HNSWLib wasn't working though. |
can't install langchain on aws lambda env. python3.9. if i use aws pandas layer, the image is too large, pls help
|
@reachlin please see https://github.com/aws-samples/llm-apps-workshop/blob/main/blogs/rag/api/deploy.sh for a recipe to package dependencies including numpy and langchain into AWS Lambda. |
Try using Docker to create your Lambda Layer for LangChain: AWS Lambda Layer for Python 3.10:
AWS Lambda Layer For Python 3.9:
|
I have followed the instruction and this is what I got: Have you seen this? tks |
@Duonghailee so you need to create a Python 3.9 conda environment first and then run this script from within that environment. Yes I have seen this error and it will go away once you build from within a Python3.9 environment.
|
up to this point, i feel it's not wise to put langchain into a lambda. even the docker image works, it will be huge. i've already put it in another micro service anyway. |
@reachlin Hi mate. I am trying to build a new AI application using langchain from scratch. Based on the discussions above, it looks using aws lambda is not ideal. But I want to confirm that because I have zero experience on python so want to be on the right track. I still would like to put everything on AWS, any suggestions of waht's the best approach from a high level, eg: using ECS microservices, fargate or something? I know the question is vague. I just want to have some high level ideas how to use langchain with python on production. Another question is how big is langchain, will it impact the cold start time like lambda largely? Tks |
@Deanfei fyi, i put langchain part on pythonanywhere as a flask app. you can use ECS to run it. langchain start is pretty fast, but query any LLM is very slow. if you use lambda, it won't be cheap. |
That's good to know. Thanks so much. 👍 |
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. |
I used the comments from @IvanCampos and @KBB99 to create a lambda layer that worked in my 3.10 environment:
Then copied the zip from the docker shell instance to my local machine and uploaded the zip to lambda as a layer. |
I have migrated to aws ecs as I don't think lambda is that efficient and could be buggy for the long term. |
I have a same issue. i have trouble when using LLMChain.run().
And then my error message is under
I tried upgrade memory of lambda, but i was not working... I think memory size is appropriate
plz help me.... |
When I have Langchain installed and try to use UnstructuredURLLoader in asks me to also install "unstructured" package which is making packages size 250MB+ this way this can not run in Lambda because of 250MB hard limit to unzipped package size |
@MarkiyanPyts if you want to use Lambda you should look into Lambda container images |
I still got the error below, any tips would be appreciated: "Unable to import module 'lambda_function': \n\nIMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!\n\nImporting the numpy C-extensions failed. This error can happen for\nmany reasons, often due to issues with your setup or how NumPy was\ninstalled.\n\nWe have compiled some common reasons and troubleshooting tips at:\n\n https://numpy.org/devdocs/user/troubleshooting-importerror.html\n\nPlease note and check the following:\n\n * The Python version is: Python3.10 from "/var/lang/bin/python3.10"\n * The NumPy version is: "1.25.2"\n\nand make sure that they are the versions you expect.\nPlease carefully study the documentation linked above for further help.\n\nOriginal error was: No module named 'numpy.core._multiarray_umath'\n", |
Hey I keep getting the following error: [ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'pydantic_core._pydantic_core' Any help would be great, I'm kind of new to this to I'm totally lost on fixing it I've tried debugging it the best I can and I'm not getting anywhere with it. |
@Ethanmbinns try building the layer with the environment image set to amazonlinux2-x86-64-standard:5.0. Also, make sure you are using Python 3.11 runtime for your Lambda. |
To create a lambda layer compatible with the latest version of Langchain and Python you can follow these steps:
Under artifacts: file: add the following path
Note: To add openai or Bedrock add them to the pip install command, i.e. - pip install langchain openai... |
Hi @KBB99 . Thanks for your guidance. I did exactly what you showed here to create a lambda layer. Now the issue is, I've tried to create a layer for both openai and langchain, but every time I try to use it in the lambda function and test, I get:
So, I always get that error no matter what I do. I am using serverless on this project. Can you share a simple project where this works with me, please? I appreciate any help you can provide. |
There is a public layer I use in the repo here. If you follow the README.md in the project it will guide you through the commands to deploy the agent to AWS using CDK.
|
Thank you so much. Will give it a try. Does it have to be ARM_64? |
If you use my public layer, then yes. If you build your own, then it depends on what architecture you pick for the build runtime. |
Still having this kind of error till now |
Gives numpy error though |
Posted a new guide for deploying a Langchain and Lambda agent here: https://github.com/aws-samples/langchain-agents . It deploys everything using CDK so it should work out of the box. Let me know if you have any questions. |
Hi, @ali-chaudhry8, I'm helping the LangChain team manage their backlog and am marking this issue as stale. It looks like you're experiencing issues deploying Langchain scripts on AWS Lambda due to problems with importing numpy. There have been various attempts to resolve the issue, including the development of a deployment template for Langchain on Lambda and API Gateway by 3coins from AWS. Additionally, users have shared their experiences and solutions, such as using Docker to create Lambda layers for Langchain and resolving conflicts with boto3. KBB99 has also provided a public Lambda layer for Langchain and shared a guide for deploying a Langchain and Lambda agent using CDK. Could you please confirm if this issue is still relevant to the latest version of the LangChain repository? If it is, please let the LangChain team know by commenting on the issue. Otherwise, feel free to close the issue yourself, or the issue will be automatically closed in 7 days. Thank you for your understanding and contribution to LangChain! |
I've followed these steps to create a Lambda layer for Python 3.12, including the langchain libraries, and it worked perfectly. Hope it helps!
For quick access, you can also use this pre-built Lambda layer with the langchain libraries: |
hi @brunocam11 . I'm faacing this issue while trying to use your layer > |
arn:aws:lambda:us-east-1:017000801446:layer:AWSLambdaPowertoolsPythonV2:51 |
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. Thanks, Ali
The text was updated successfully, but these errors were encountered: