Error in OpenAI dependencies for Python Lambda Function

1

Hello, I'm creating a lambda function using the OpenAI API, and when testing it I get this error: { "errorMessage": "Unable to import module 'lambda_function': No module named 'pydantic_core._pydantic_core'", "errorType": "Runtime.ImportModuleError", "requestId": "6bddf918-25a1-4a6a-b523-d97db6ea94ed", "stackTrace": [] }

  • I've triple checked, Lambda Python environment is 3.11 and so is my local version (3.11.6)
  • I've moved all the dependency (site-packages) files into the root of the ZIP file
  • pydantic_core folder and in it _pydantic_core file exists in my ZIP.
  • This module is a sub dependency of OpenAI package
  • I tried packing the modules under 'python' sub directory in the ZIP file, and then it didn't even recognized 'openai' which makes me think it's something specific with 'pydantic_core'.

Any help will be very much appreciated. Thanks!

demandé il y a 6 mois2362 vues
2 réponses
0

The following documentation demonstrate how it should packages should be included in the Lambda zip for Python: https://docs.aws.amazon.com/lambda/latest/dg/python-package.html#python-package-dependencies-layers:~:text=zip%20lambda_function.py-,Creating%20a%20Python%20layer%20for%20your%20dependencies,-The%20instructions%20in

I recommend using Lambda Layers for storing dependencies and then assign it to the Lambda function: https://docs.aws.amazon.com/lambda/latest/dg/packaging-layers.html#packaging-layers-paths

AWS
vtjean
répondu il y a 6 mois
0

using openai==0.28.0 and install async-timeout==4.0.3 in the same folder. Be sure by creating the venv the version of your local-machine is same as the version of your Lambda python.

répondu il y a 2 mois

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions