Skip to content
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

with multiprocessing, pickle issue with client.beta.chat.completions.parse output #1776

Open
1 task done
yufang67 opened this issue Oct 5, 2024 · 0 comments
Open
1 task done
Labels
bug Something isn't working

Comments

@yufang67
Copy link

yufang67 commented Oct 5, 2024

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

We use multiprocessing to handle the calls. It was working with client.chat.completions.create. Currently, we are trying client.beta.chat.completions.parse with response_format, i got error:

Traceback (most recent call last):
File "/anaconda/lib/python3.10/multiprocessing/queues.py", line 244, in _feed
obj = _ForkingPickler.dumps(obj)
File "/anaconda/lib/python3.10/multiprocessing/reduction.py", line 51, in dumps
cls(buf, protocol).dump(obj)
_pickle.PicklingError: Can't pickle <class 'openai.types.chat.parsed_chat_completion.ParsedChatCompletion[CalendarEvent]'>: attribute lookup ParsedChatCompletion[CalendarEvent] on openai.types.chat.parsed_chat_completion failed

anyone can help ?

Thanks

To Reproduce

from pydantic import BaseModel
from . import get_token_provider
import openai
import asyncio
import pickle

class CalendarEvent(BaseModel):
    name: str
    date: str
    participants: list[str]

def original_test():

    MODEL = "gpt-4o-2024-08-06"
    ENDPOINT = "gpt-4o-2024-08-06-endpoint"
    token_provider = get_token_provider()

    client = openai.AsyncAzureOpenAI(
    azure_ad_token_provider=token_provider,
    azure_endpoint=ENDPOINT,
    api_version="2024-08-01-preview",
    )

    func = client.beta.chat.completions.parse(
        model=MODEL,
        messages=[
            {"role": "system", "content": "Extract the event information."},
            {"role": "user", "content": "Alice and Bob are going to a science fair on Friday."},
        ],
        response_format=CalendarEvent,
        )

    completion = asyncio.run(func)
    pickle.dumps(completion)
    

if __name__ == "__main__":
    original_test()

Code snippets

No response

OS

linux

Python version

py3.10

Library version

openai 1.51.0

@yufang67 yufang67 added the bug Something isn't working label Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant