openai / openai-python

The official Python library for the OpenAI API
https://pypi.org/project/openai/
Apache License 2.0
21.08k stars 2.86k forks source link

Missing module openai.error #840

Closed MarkJYC001 closed 7 months ago

MarkJYC001 commented 7 months ago

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

Describe the bug

I am using library prompt2model, and its demo shows that import openai.error

While then there is a Error ModuleNotFoundError: No module named 'openai.error'

My question is whether openai python have deleted the library openai.error? Is there any alternative code here?

To Reproduce

I think there is a general problem of Module missing. Maybe try as following

1.In terminal, pip install openai

  1. In any file, try import openai.error

Alternatively, when I did this in terminal

  1. pip install prompt2model
  2. python prompt2model_demo.py

Code snippets

"""Tools for accessing API-based models."""

from __future__ import annotations  # noqa FI58

import asyncio
import json
import logging
import time

import aiolimiter
import litellm.utils
import openai
import openai.error
import tiktoken
from aiohttp import ClientSession
from litellm import acompletion, completion
from tqdm.asyncio import tqdm_asyncio

# Note that litellm converts all API errors into openai errors,
# so openai errors are valid even when using other services.
API_ERRORS = (
    openai.error.APIError,
    openai.error.Timeout,
    openai.error.RateLimitError,
    openai.error.ServiceUnavailableError,
    openai.error.InvalidRequestError,
    json.decoder.JSONDecodeError,
    AssertionError,
)

ERROR_ERRORS_TO_MESSAGES = {
    openai.error.InvalidRequestError: "API Invalid Request: Prompt was filtered",
    openai.error.RateLimitError: "API rate limit exceeded. Sleeping for 10 seconds.",
    openai.error.APIConnectionError: "Error Communicating with API",
    openai.error.Timeout: "API Timeout Error: API Timeout",
    openai.error.ServiceUnavailableError: "API service unavailable error: {e}",
    openai.error.APIError: "API error: {e}",
}

OS

Mac OS

Python version

Python v3.9

Library version

openai v1.3.0

RobertCraigie commented 7 months ago

All exception classes are available from the top-level package, e.g. openai.BadRequestError.

mengyuxin commented 3 weeks ago

your openai api version is too high, please use this code to install lower bersion api. pip3 install openai==0.28