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

AttributeError: module 'openai' has no attribute 'error' #30

Closed
jpzambranoleon opened this issue May 7, 2024 · 1 comment
Closed

AttributeError: module 'openai' has no attribute 'error' #30

jpzambranoleon opened this issue May 7, 2024 · 1 comment

Comments

@jpzambranoleon
Copy link

Hi,

I'm experimenting with the GoT framework, but I keep encountering an AttributeError.

There's an error when running the example files i.e. doc_merg.py, keyword_counting.py, set_intersection.py files, and sorting.py files. Error is traced back to chatgpt.py. It's strange that this error is present ONLY when running the example files, but it doesn't show up when running the quick start prompt.

Code:

from openai import OpenAI, OpenAIError

    @backoff.on_exception(backoff.expo, OpenAIError, max_time=10, max_tries=6)
    def chat(self, messages: List[Dict], num_responses: int = 1) -> ChatCompletion:
        """
        Send chat messages to the OpenAI model and retrieves the model's response.
        Implements backoff on OpenAI error.

        :param messages: A list of message dictionaries for the chat.
        :type messages: List[Dict]
        :param num_responses: Number of desired responses, default is 1.
        :type num_responses: int
        :return: The OpenAI model's response.
        :rtype: ChatCompletion
        """
        response = self.client.chat.completions.create(
            model=self.model_id,
            messages=messages,
            temperature=self.temperature,
            max_tokens=self.max_tokens,
            n=num_responses,
            stop=self.stop,
        )

        self.prompt_tokens += response.usage.prompt_tokens
        self.completion_tokens += response.usage.completion_tokens
        prompt_tokens_k = float(self.prompt_tokens) / 1000.0
        completion_tokens_k = float(self.completion_tokens) / 1000.0
        self.cost = (
            self.prompt_token_cost * prompt_tokens_k
            + self.response_token_cost * completion_tokens_k
        )
        self.logger.info(
            f"This is the response from chatgpt: {response}"
            f"\nThis is the cost of the response: {self.cost}"
        )
        return response

The error message:

line 104, in ChatGPT
    backoff.expo, openai.error.OpenAIError, max_time=10, max_tries=6
                  ^^^^^^^^^^^^
AttributeError: module 'openai' has no attribute 'error'

This is preventing me from running any example file including my own. Any suggestions?

@jpzambranoleon
Copy link
Author

Okay, so I've managed to solve this issue. All I had to do was move the graph_of_thoughts directory inside my project directory for my custom project to work. Additionally, relocating the 'graph_of_thoughts' directory into the respective example directories within the repository resolves the issue, enabling smooth execution of the example files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant