Skip to content

[🐛 Fix]: Upgrade deprecated OpenAI API client and replace davinci model with gpt-3.5-turbo #21

@lucumango

Description

@lucumango

Description 📝

The Synthesize.ipynb research notebook uses the deprecated openai==0.28 Python client and the davinci completion model, which are no longer supported by OpenAI and throw InvalidRequestError / deprecation warnings when researchers attempt to run the data synthesis pipeline.

Problem 🚨

  • openai==0.28 is deprecated and incompatible with the current OpenAI API.
  • openai.Completion.create with the davinci engine is no longer available.
  • The hardcoded openai.api_key assignment is a security anti-pattern.
  • No error handling around API calls causes the entire batch loop to crash on quota/rate-limit errors.

Proposed Solution 💡

  1. Upgrade the pip dependency to openai>=1.0.0.
  2. Initialize the client securely using os.environ.get('OPENAI_API_KEY') instead of hardcoding the key.
  3. Replace the deprecated openai.Completion.create / davinci call with the modern client.chat.completions.create syntax using gpt-3.5-turbo.
  4. Wrap API calls in a try/except block to gracefully handle rate-limit or quota errors without crashing the batch loop.

References 🔗

Acceptance Criteria ✅

  • Synthesize.ipynb runs without deprecation warnings or InvalidRequestError.
  • API key is read from environment variables, not hardcoded.
  • Text generation uses gpt-3.5-turbo via client.chat.completions.create.
  • Batch loop handles rate-limit errors gracefully.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions