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

[bug] ModuleNotFoundError: No module named 'openai.error' #434

Closed
kdcokenny opened this issue Nov 6, 2023 · 2 comments
Closed

[bug] ModuleNotFoundError: No module named 'openai.error' #434

kdcokenny opened this issue Nov 6, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@kdcokenny
Copy link

Describe the bug
I'm getting this error, not exactly sure why:

ModuleNotFoundError                       Traceback (most recent call last)
/home/kenny/workspace/elapse/packages/research/notebooks/wized-guardrail.ipynb Cell 4 line 1
----> [1](vscode-notebook-cell://wsl%2Bubuntu/home/kenny/workspace/elapse/packages/research/notebooks/wized-guardrail.ipynb#W6sdnNjb2RlLXJlbW90ZQ%3D%3D?line=0) from guardrails import Guard
      [3](vscode-notebook-cell://wsl%2Bubuntu/home/kenny/workspace/elapse/packages/research/notebooks/wized-guardrail.ipynb#W6sdnNjb2RlLXJlbW90ZQ%3D%3D?line=2) guard = Guard.from_pydantic(output_class=GuardRails, prompt=prompt)

File [~/.local/lib/python3.10/site-packages/guardrails/__init__.py:3](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/kenny/workspace/elapse/packages/research/notebooks/~/.local/lib/python3.10/site-packages/guardrails/__init__.py:3)
      [1](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/kenny/workspace/elapse/packages/research/notebooks/~/.local/lib/python3.10/site-packages/guardrails/__init__.py:1) # Set up __init__.py so that users can do from guardrails import Response, Schema, etc.
----> [3](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/kenny/workspace/elapse/packages/research/notebooks/~/.local/lib/python3.10/site-packages/guardrails/__init__.py:3) from guardrails.guard import Guard
      [4](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/kenny/workspace/elapse/packages/research/notebooks/~/.local/lib/python3.10/site-packages/guardrails/__init__.py:4) from guardrails.llm_providers import PromptCallableBase
      [5](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/kenny/workspace/elapse/packages/research/notebooks/~/.local/lib/python3.10/site-packages/guardrails/__init__.py:5) from guardrails.logging_utils import configure_logging

File [~/.local/lib/python3.10/site-packages/guardrails/guard.py:20](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/kenny/workspace/elapse/packages/research/notebooks/~/.local/lib/python3.10/site-packages/guardrails/guard.py:20)
     [17](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/kenny/workspace/elapse/packages/research/notebooks/~/.local/lib/python3.10/site-packages/guardrails/guard.py:17) from eliot import add_destinations, start_action
     [18](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/kenny/workspace/elapse/packages/research/notebooks/~/.local/lib/python3.10/site-packages/guardrails/guard.py:18) from pydantic import BaseModel
---> [20](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/kenny/workspace/elapse/packages/research/notebooks/~/.local/lib/python3.10/site-packages/guardrails/guard.py:20) from guardrails.llm_providers import get_async_llm_ask, get_llm_ask
     [21](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/kenny/workspace/elapse/packages/research/notebooks/~/.local/lib/python3.10/site-packages/guardrails/guard.py:21) from guardrails.prompt import Instructions, Prompt
     [22](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/kenny/workspace/elapse/packages/research/notebooks/~/.local/lib/python3.10/site-packages/guardrails/guard.py:22) from guardrails.rail import Rail

File [~/.local/lib/python3.10/site-packages/guardrails/llm_providers.py:5](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/kenny/workspace/elapse/packages/research/notebooks/~/.local/lib/python3.10/site-packages/guardrails/llm_providers.py:5)
      [2](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/kenny/workspace/elapse/packages/research/notebooks/~/.local/lib/python3.10/site-packages/guardrails/llm_providers.py:2) from typing import Any, Awaitable, Callable, Dict, List, Optional, cast
      [4](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/kenny/workspace/elapse/packages/research/notebooks/~/.local/lib/python3.10/site-packages/guardrails/llm_providers.py:4) import openai
----> [5](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/kenny/workspace/elapse/packages/research/notebooks/~/.local/lib/python3.10/site-packages/guardrails/llm_providers.py:5) import openai.error
      [6](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/kenny/workspace/elapse/packages/research/notebooks/~/.local/lib/python3.10/site-packages/guardrails/llm_providers.py:6) from pydantic import BaseModel
      [7](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/kenny/workspace/elapse/packages/research/notebooks/~/.local/lib/python3.10/site-packages/guardrails/llm_providers.py:7) from tenacity import retry, retry_if_exception_type, wait_exponential_jitter

ModuleNotFoundError: No module named 'openai.error'

To Reproduce

# %%
%pip -q install guardrails-ai openai

# %%
from enum import Enum
from pydantic import BaseModel, Field

class RelatedEnum(int, Enum):
    one = 1
    two = 2
    three = 3
    four = 4
    five = 5

class PriorityEnum(int, Enum):
    one = 1
    two = 2
    three = 3

class GuardRails(BaseModel):
    related_ranking: RelatedEnum = Field(RelatedEnum.three, description="Related ranking")
    priority_ranking: PriorityEnum = Field(PriorityEnum.two, description="Priority ranking")

# %%
prompt = """Determine the following base on the user's query:

Query: `${query}`

- Is the user's query related to the platform Wized?
- What is the likely priority of the user's query?

Ranking:
1. Not related
2. Somewhat related
3. Related
4. Very related
5. Extremely related

Priority:
1. Low
2. Medium
3. High


${gr.complete_json_suffix_v2}
"""

# %%
from guardrails import Guard

guard = Guard.from_pydantic(output_class=GuardRails, prompt=prompt)

# %%
query = "What is the best way to get started with Wized?"

# %%
import openai

raw_llm_output, validated_output = guard(
    openai.Completion.create,
    prompt_params={"query": query},
    engine="text-davinci-003",
    max_tokens=1024,
    temperature=0.3,
)

# %%
raw_llm_output

# %%
validated_output

Expected behavior
The error to not show up

Library version:
Version (e.g. 0.2.6)

@kdcokenny kdcokenny added the bug Something isn't working label Nov 6, 2023
@kdcokenny kdcokenny changed the title [bug] [bug] ModuleNotFoundError: No module named 'openai.error' Nov 6, 2023
@thekaranacharya
Copy link
Contributor

thekaranacharya commented Nov 7, 2023

Hello @kdcokenny, openai just released a new package (> v1.x) with new features like JSON mode yesterday - and it's somewhat backwards incompatible. We've started working on updating our code to make it compatible with openai's latest package - and we will update here once it's complete. As of now, please try re-installing an earlier version:

pip install openai==0.28.1

Apologies for this inconvenience!

@CalebCourier
Copy link
Collaborator

Hey @kdcokenny, we just publish guardails-ai v0.2.7, this patch temporarily locks the version of openai to 0.28.1 or under. Once we have support for openai 1.x we'll remove this lock, but for now you should be able to use this latest version without having to specify the openai version yourself. Thanks again for filing this issue!

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

3 participants