Skip to content

Bugs When using OpenAI api with Celery/redit #1118

@jfrancoisponcet16

Description

@jfrancoisponcet16

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • This is an issue with the Python library

Describe the bug

Hello,
There seem to be a bug when using the Openai API with Celery/redit shared task. When running the function bellow.
I’m not sure exactly why. When In use langchain with Mistral api, Ollama or with any my own custom models it works really well, but it crashes when I use anything touching the openai api. I tried bypassing langchain to work directly with the openai api and I still do get this error Does someone have any idea why ?

To Reproduce

  1. pip install Django
  2. pip install celery
  3. brew install redit // for macs
  4. create a random view function that will call the task at task.py

Code snippets

in views.py

def some_view_fucntion(request):
    for x in range(2):
         some_ai_function.delay()

in task.py

@shared_task
def some_ai_function():
    message = "Hello, write a message about testing "
    print(message)
    completion = openai.chat.completions.create(
        model=gpt-3.5-turbo”,
        messages=[
            {
                 “role”: “user”,
                 “content”: message,
            },
        ],
    )
    print(completion.choices[0].message.content)

RETURNS :

ERROR/MainProcess] Process ‘ForkPoolWorker-2’ pid:86900 exited with ‘signal 5 (SIGTRAP)’
ERROR/MainProcess] Task handler raised error: WorkerLostError(‘Worker exited prematurely: signal 5 (SIGTRAP) Job: 0.’)

Traceback (most recent call last):
File" …
/python3.11/site-packages/billiard/pool.py", line 1264, in mark_as_worker_lost
raise WorkerLostError(
billiard.exceptions.WorkerLostError: Worker exited prematurely: signal 5 (SIGTRAP) Job: 0.

OS

macOS (m2)

Python version

Python 3.11.5

Library version

openai 1.8.0

### Tasks
- [ ] Create a work around get_architecture()  for celery tasks on MacOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions