- Newest
- Most votes
- Most comments
I'd suggest you to follow this process and comment here, how it goes for you:
-
Create openai layer by following this re:Post Knowledge Center Article How can I create a layer for my Lambda Python function?. Payload for the lambda function to create openai layer would be as below:
{ "dependencies": { "openai": "== 0.27.0" }, "layer": { "name": "openai-lambda-layer", "description": "this layer contains requests, operations libraries", "compatible-runtimes": [ "python3.11" ], "license-info": "MIT" } }
-
With the above payload, run the lambda function, which would create layer.
- Now layer is created and you can use it in your own lambda function, where you wanted to use openai module. Just go to your lambda function -> code -> Scroll down -> Add a layer -> Add newly created openai layer
- Once you add the layer, you can use this module in your lambda function code as I did below(no error reporting that openai module not found):
Comment here if you have additional questions, happy to help.
Abhishek
Terrific! I was able to get rid of the import error. You rock, Abhishek !
I still couldn't execute the function, though. I got another error message: can't imprt name 'OpenAI' from 'openai' (/opt/python/openai/init.py)". Any advice on how I could fix this issue would be great, Abhishek!
Lin
I did some exploration, and found that if I didn't import OpenAI from openai, the function was fine. Guess it might be an issue between openai and python. I will keep investigating. However, if you have any suggestions, I am all ears.
It worked, Abhishek! Appreciate your prompt advice!
Lin
Glad it worked. For community's better experience, it'd be great if you could mark the first answer as accepted one like you did at first place. Thanks.
Relevant content
- asked 10 months ago
- Accepted Answerasked 3 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 4 months ago
- AWS OFFICIALUpdated 5 months ago
- AWS OFFICIALUpdated 4 months ago
Hi Lin, I'm not sure, how did I miss the link in my original answer, hence edited it and provided you the link for the process to create layer. To your second question about the error: "can't imprt name 'OpenAI' from 'openai' (/opt/python/openai/init.py)". I'd suggest you to create a new layer with latest version of openai, payload to create the layer with latest version of openai, would look like as below:
Then add this layer to your function and see how it goes.