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!

preguntada hace 6 meses2366 visualizaciones
2 Respuestas
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
respondido hace 6 meses
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.

respondido hace 2 meses

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas