run-llama / llama_index

LlamaIndex is a data framework for your LLM applications
https://docs.llamaindex.ai
MIT License
36.75k stars 5.27k forks source link

[Bug]: ModuleNotFoundError: No module named 'openai.openai_object' #11281

Closed alokkrsahu closed 8 months ago

alokkrsahu commented 8 months ago

Bug Description

----> 4 from ragatouille import RAGPretrainedModel 6 READER_MODEL_NAME = "llama-2-7b-chat-hf" 8 bnb_config = BitsAndBytesConfig( 9 load_in_4bit=True, 10 bnb_4bit_use_double_quant=True, 11 bnb_4bit_quant_type="nf4", 12 bnb_4bit_compute_dtype=torch.bfloat16, 13 )

File ~/.local/lib/python3.9/site-packages/ragatouille/init.py:2, in 1 version = "0.0.7post3" ----> 2 from .RAGPretrainedModel import RAGPretrainedModel 3 from .RAGTrainer import RAGTrainer 5 all = ["RAGPretrainedModel", "RAGTrainer"]

File ~/.local/lib/python3.9/site-packages/ragatouille/RAGPretrainedModel.py:8, in 5 from langchain.retrievers.document_compressors.base import BaseDocumentCompressor 6 from langchain_core.retrievers import BaseRetriever ----> 8 from ragatouille.data.corpus_processor import CorpusProcessor 9 from ragatouille.data.preprocessors import llama_index_sentence_splitter 10 from ragatouille.integrations import ( 11 RAGatouilleLangChainCompressor, 12 RAGatouilleLangChainRetriever, 13 )

File ~/.local/lib/python3.9/site-packages/ragatouille/data/init.py:1, in ----> 1 from .corpus_processor import CorpusProcessor 2 from .preprocessors import llama_index_sentence_splitter 3 from .training_data_processor import TrainingDataProcessor

File ~/.local/lib/python3.9/site-packages/ragatouille/data/corpus_processor.py:4, in 1 from typing import Callable, List, Optional, Union 2 from uuid import uuid4 ----> 4 from ragatouille.data.preprocessors import llama_index_sentence_splitter 7 class CorpusProcessor: 8 def init( 9 self, 10 document_splitter_fn: Optional[Callable] = llama_index_sentence_splitter, 11 preprocessing_fn: Optional[Union[Callable, list[Callable]]] = None, 12 ):

File ~/.local/lib/python3.9/site-packages/ragatouille/data/preprocessors.py:1, in ----> 1 from llama_index import Document 2 from llama_index.text_splitter import SentenceSplitter 5 def llama_index_sentence_splitter( 6 documents: list[str], document_ids: list[str], chunk_size=256 7 ):

File /opt/conda/lib/python3.9/site-packages/llama_index/init.py:17, in 14 from llama_index.data_structs.struct_type import IndexStructType 16 # embeddings ---> 17 from llama_index.embeddings.langchain import LangchainEmbedding 18 from llama_index.embeddings.openai import OpenAIEmbedding 20 # structured

File /opt/conda/lib/python3.9/site-packages/llama_index/embeddings/init.py:16, in 14 from llama_index.embeddings.instructor import InstructorEmbedding 15 from llama_index.embeddings.langchain import LangchainEmbedding ---> 16 from llama_index.embeddings.openai import OpenAIEmbedding 17 from llama_index.embeddings.utils import resolve_embed_model 19 all = [ 20 "GoogleUnivSentEncoderEmbedding", 21 "LangchainEmbedding", (...) 32 "ClarifaiEmbedding", 33 ]

File /opt/conda/lib/python3.9/site-packages/llama_index/embeddings/openai.py:18, in 16 from llama_index.callbacks.base import CallbackManager 17 from llama_index.embeddings.base import DEFAULT_EMBED_BATCH_SIZE, BaseEmbedding ---> 18 from llama_index.llms.openai_utils import ( 19 resolve_from_aliases, 20 resolve_openai_credentials, 21 ) 24 class OpenAIEmbeddingMode(str, Enum): 25 """OpenAI embedding mode."""

File /opt/conda/lib/python3.9/site-packages/llama_index/llms/init.py:23, in 21 from llama_index.llms.konko import Konko 22 from llama_index.llms.langchain import LangChainLLM ---> 23 from llama_index.llms.litellm import LiteLLM 24 from llama_index.llms.llama_cpp import LlamaCPP 25 from llama_index.llms.localai import LocalAI

File /opt/conda/lib/python3.9/site-packages/llama_index/llms/litellm.py:28, in 5 from llama_index.llms.base import ( 6 LLM, 7 ChatMessage, (...) 16 llm_completion_callback, 17 ) 18 from llama_index.llms.generic_utils import ( 19 achat_to_completion_decorator, 20 acompletion_to_chat_decorator, (...) 26 stream_completion_to_chat_decorator, 27 ) ---> 28 from llama_index.llms.litellm_utils import ( 29 acompletion_with_retry, 30 completion_with_retry, 31 from_openai_message_dict, 32 is_chat_model, 33 is_function_calling_model, 34 openai_modelname_to_contextsize, 35 to_openai_message_dicts, 36 validate_litellm_api_key, 37 ) 40 class LiteLLM(LLM): 41 model: str = Field( 42 description="The LiteLLM model to use." 43 ) # For complete list of providers https://docs.litellm.ai/docs/providers

File /opt/conda/lib/python3.9/site-packages/llama_index/llms/litellm_utils.py:4, in 1 import logging 2 from typing import Any, Callable, Dict, List, Optional, Sequence, Type ----> 4 from openai.openai_object import OpenAIObject 5 from tenacity import ( 6 before_sleep_log, 7 retry, (...) 10 wait_exponential, 11 ) 13 from llama_index.bridge.pydantic import BaseModel

ModuleNotFoundError: No module named 'openai.openai_object'

Version

llama-index==0.10.11 llama-index-agent-openai==0.1.5 llama-index-cli==0.1.3 llama-index-core==0.10.11.post1 llama-index-embeddings-huggingface==0.1.3 llama-index-embeddings-openai==0.1.6 llama-index-indices-managed-llama-cloud==0.1.3 llama-index-legacy==0.9.48 llama-index-llms-ollama==0.1.2 llama-index-llms-openai==0.1.6 llama-index-multi-modal-llms-openai==0.1.4 llama-index-packs-ragatouille-retriever==0.1.2 llama-index-program-openai==0.1.4 llama-index-question-gen-openai==0.1.3 llama-index-readers-file==0.1.5 llama-index-readers-llama-parse==0.1.3 llama-index-vector-stores-chroma==0.1.2

Steps to Reproduce

from ragatouille import RAGPretrainedModel

Relevant Logs/Tracbacks

----> 4 from ragatouille import RAGPretrainedModel
      6 READER_MODEL_NAME = "llama-2-7b-chat-hf"
      8 bnb_config = BitsAndBytesConfig(
      9     load_in_4bit=True,
     10     bnb_4bit_use_double_quant=True,
     11     bnb_4bit_quant_type="nf4",
     12     bnb_4bit_compute_dtype=torch.bfloat16,
     13 )

File ~/.local/lib/python3.9/site-packages/ragatouille/__init__.py:2, in <module>
      1 __version__ = "0.0.7post3"
----> 2 from .RAGPretrainedModel import RAGPretrainedModel
      3 from .RAGTrainer import RAGTrainer
      5 __all__ = ["RAGPretrainedModel", "RAGTrainer"]

File ~/.local/lib/python3.9/site-packages/ragatouille/RAGPretrainedModel.py:8, in <module>
      5 from langchain.retrievers.document_compressors.base import BaseDocumentCompressor
      6 from langchain_core.retrievers import BaseRetriever
----> 8 from ragatouille.data.corpus_processor import CorpusProcessor
      9 from ragatouille.data.preprocessors import llama_index_sentence_splitter
     10 from ragatouille.integrations import (
     11     RAGatouilleLangChainCompressor,
     12     RAGatouilleLangChainRetriever,
     13 )

File ~/.local/lib/python3.9/site-packages/ragatouille/data/__init__.py:1, in <module>
----> 1 from .corpus_processor import CorpusProcessor
      2 from .preprocessors import llama_index_sentence_splitter
      3 from .training_data_processor import TrainingDataProcessor

File ~/.local/lib/python3.9/site-packages/ragatouille/data/corpus_processor.py:4, in <module>
      1 from typing import Callable, List, Optional, Union
      2 from uuid import uuid4
----> 4 from ragatouille.data.preprocessors import llama_index_sentence_splitter
      7 class CorpusProcessor:
      8     def __init__(
      9         self,
     10         document_splitter_fn: Optional[Callable] = llama_index_sentence_splitter,
     11         preprocessing_fn: Optional[Union[Callable, list[Callable]]] = None,
     12     ):

File ~/.local/lib/python3.9/site-packages/ragatouille/data/preprocessors.py:1, in <module>
----> 1 from llama_index import Document
      2 from llama_index.text_splitter import SentenceSplitter
      5 def llama_index_sentence_splitter(
      6     documents: list[str], document_ids: list[str], chunk_size=256
      7 ):

File /opt/conda/lib/python3.9/site-packages/llama_index/__init__.py:17, in <module>
     14 from llama_index.data_structs.struct_type import IndexStructType
     16 # embeddings
---> 17 from llama_index.embeddings.langchain import LangchainEmbedding
     18 from llama_index.embeddings.openai import OpenAIEmbedding
     20 # structured

File /opt/conda/lib/python3.9/site-packages/llama_index/embeddings/__init__.py:16, in <module>
     14 from llama_index.embeddings.instructor import InstructorEmbedding
     15 from llama_index.embeddings.langchain import LangchainEmbedding
---> 16 from llama_index.embeddings.openai import OpenAIEmbedding
     17 from llama_index.embeddings.utils import resolve_embed_model
     19 __all__ = [
     20     "GoogleUnivSentEncoderEmbedding",
     21     "LangchainEmbedding",
   (...)
     32     "ClarifaiEmbedding",
     33 ]

File /opt/conda/lib/python3.9/site-packages/llama_index/embeddings/openai.py:18, in <module>
     16 from llama_index.callbacks.base import CallbackManager
     17 from llama_index.embeddings.base import DEFAULT_EMBED_BATCH_SIZE, BaseEmbedding
---> 18 from llama_index.llms.openai_utils import (
     19     resolve_from_aliases,
     20     resolve_openai_credentials,
     21 )
     24 class OpenAIEmbeddingMode(str, Enum):
     25     """OpenAI embedding mode."""

File /opt/conda/lib/python3.9/site-packages/llama_index/llms/__init__.py:23, in <module>
     21 from llama_index.llms.konko import Konko
     22 from llama_index.llms.langchain import LangChainLLM
---> 23 from llama_index.llms.litellm import LiteLLM
     24 from llama_index.llms.llama_cpp import LlamaCPP
     25 from llama_index.llms.localai import LocalAI

File /opt/conda/lib/python3.9/site-packages/llama_index/llms/litellm.py:28, in <module>
      5 from llama_index.llms.base import (
      6     LLM,
      7     ChatMessage,
   (...)
     16     llm_completion_callback,
     17 )
     18 from llama_index.llms.generic_utils import (
     19     achat_to_completion_decorator,
     20     acompletion_to_chat_decorator,
   (...)
     26     stream_completion_to_chat_decorator,
     27 )
---> 28 from llama_index.llms.litellm_utils import (
     29     acompletion_with_retry,
     30     completion_with_retry,
     31     from_openai_message_dict,
     32     is_chat_model,
     33     is_function_calling_model,
     34     openai_modelname_to_contextsize,
     35     to_openai_message_dicts,
     36     validate_litellm_api_key,
     37 )
     40 class LiteLLM(LLM):
     41     model: str = Field(
     42         description="The LiteLLM model to use."
     43     )  # For complete list of providers https://docs.litellm.ai/docs/providers

File /opt/conda/lib/python3.9/site-packages/llama_index/llms/litellm_utils.py:4, in <module>
      1 import logging
      2 from typing import Any, Callable, Dict, List, Optional, Sequence, Type
----> 4 from openai.openai_object import OpenAIObject
      5 from tenacity import (
      6     before_sleep_log,
      7     retry,
   (...)
     10     wait_exponential,
     11 )
     13 from llama_index.bridge.pydantic import BaseModel

ModuleNotFoundError: No module named 'openai.openai_object'
dosubot[bot] commented 8 months ago

🤖

Hey @alokkrsahu, great to see you back here! Hope you're doing well.

Based on the information you've provided, it seems like the issue might be related to the version of the llama-index-llms-openai package you're using. The openai.openai_object module is part of the llama-index-llms-openai package and is used to interact with the OpenAI API.

The error message you're seeing suggests that Python cannot find this module, which could be due to a number of reasons. Here are a few things you could try:

  1. Check the installation of the llama-index-llms-openai package: Make sure that the llama-index-llms-openai package is correctly installed in your Python environment. You can do this by running pip show llama-index-llms-openai in your terminal. If the package is not installed, you can install it using pip install llama-index-llms-openai==0.1.6.

  2. Upgrade the llama-index package: There was a similar issue reported in the LlamaIndex repository (At MacOS, not working well[Bug]: ) where the user was able to resolve the issue by upgrading the llama-index package. You can do this by running pip install --upgrade llama-index. If you're using a notebook, it's also recommended to completely restart it after upgrading the package.

  3. Check your Python version: The LlamaIndex packages are tested with Python 3.7, 3.8, and 3.9. If you're using a different version of Python, you might encounter compatibility issues. You can check your Python version by running python --version in your terminal.

If none of these suggestions resolve the issue, it would be helpful if you could provide more information about your Python environment and the exact steps you're taking when you encounter the error. This could help identify if there's a specific condition or sequence of actions that triggers the error.

For example, are you importing RAGPretrainedModel directly in your script, or is it being imported by another module? Are you able to import other modules from the ragatouille package without encountering an error? Any additional information you can provide would be helpful in diagnosing the issue.

You can refer to the LlamaIndex documentation for more information about the openai.openai_object module and the RAGPretrainedModel class.

Sources

#### About Dosu This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot.
logan-markewich commented 8 months ago

@alokkrsahu this seems like an issue with ragatouille not supporting llama-index v0.10.x. I see you've already opened an issue there -- lets track progress in one location.

https://github.com/bclavie/RAGatouille/issues/152