run-llama / llama_index

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

[Bug]: Import error on latest PyPI Release #7951

Closed connor-mccorm closed 1 year ago

connor-mccorm commented 1 year ago

Bug Description

Running the following command in a jupyter notebook:

from llama_index import ServiceContext, StorageContext, SimpleDirectoryReader, VectorStoreIndex, set_global_service_context

Getting the following error:

TypeError: Argument 'description' has incorrect type (expected str, got tuple)

I will start looking into this, but I imagine you all have more expertise so would appreciate some guidance/a quick fix if possible.

Version

latest - 0.8.38

Steps to Reproduce

Run the following command in a python shell with 0.8.38 version of llama_index

from llama_index import ServiceContext, StorageContext, SimpleDirectoryReader, VectorStoreIndex, set_global_service_context

Relevant Logs/Tracbacks

/Users/connor/mambaforge/envs/predibase38/lib/python3.8/site-packages/pinecone/index.py:4: TqdmExperimentalWarning: Using `tqdm.autonotebook.tqdm` in notebook mode. Use `tqdm.tqdm` instead to force console mode (e.g. in jupyter console)
  from tqdm.autonotebook import tqdm
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [1], in <cell line: 6>()
      3 import openai
      4 import pinecone
----> 6 from llama_index import ServiceContext, StorageContext, SimpleDirectoryReader, VectorStoreIndex, set_global_service_context
      7 from llama_index.llms import PredibaseLLM
      8 from llama_index.vector_stores import PineconeVectorStore

File ~/mambaforge/envs/predibase38/lib/python3.8/site-packages/llama_index/__init__.py:20, in <module>
     16 from llama_index.embeddings.openai import OpenAIEmbedding
     19 # indices
---> 20 from llama_index.indices.keyword_table import (
     21     KeywordTableIndex,
     22     RAKEKeywordTableIndex,
     23     SimpleKeywordTableIndex,
     24     GPTKeywordTableIndex,
     25     GPTRAKEKeywordTableIndex,
     26     GPTSimpleKeywordTableIndex,
     27 )
     28 from llama_index.indices.knowledge_graph import (
     29     KnowledgeGraphIndex,
     30     GPTKnowledgeGraphIndex,
     31 )
     32 from llama_index.indices.list import ListIndex, GPTListIndex, SummaryIndex

File ~/mambaforge/envs/predibase38/lib/python3.8/site-packages/llama_index/indices/__init__.py:4, in <module>
      1 """LlamaIndex data structures."""
      3 # indices
----> 4 from llama_index.indices.keyword_table.base import (
      5     KeywordTableIndex,
      6     GPTKeywordTableIndex,
      7 )
      8 from llama_index.indices.keyword_table.rake_base import (
      9     RAKEKeywordTableIndex,
     10     GPTRAKEKeywordTableIndex,
     11 )
     12 from llama_index.indices.keyword_table.simple_base import (
     13     SimpleKeywordTableIndex,
     14     GPTSimpleKeywordTableIndex,
     15 )

File ~/mambaforge/envs/predibase38/lib/python3.8/site-packages/llama_index/indices/keyword_table/__init__.py:4, in <module>
      1 """Keyword Table Index Data Structures."""
      3 # indices
----> 4 from llama_index.indices.keyword_table.base import (
      5     KeywordTableIndex,
      6     GPTKeywordTableIndex,
      7 )
      8 from llama_index.indices.keyword_table.retrievers import (
      9     KeywordTableGPTRetriever,
     10     KeywordTableRAKERetriever,
     11     KeywordTableSimpleRetriever,
     12 )
     13 from llama_index.indices.keyword_table.rake_base import (
     14     RAKEKeywordTableIndex,
     15     GPTRAKEKeywordTableIndex,
     16 )

File ~/mambaforge/envs/predibase38/lib/python3.8/site-packages/llama_index/indices/keyword_table/base.py:17, in <module>
     15 from llama_index.async_utils import run_async_tasks
     16 from llama_index.data_structs.data_structs import KeywordTable
---> 17 from llama_index.indices.base import BaseIndex
     18 from llama_index.indices.base_retriever import BaseRetriever
     19 from llama_index.indices.keyword_table.utils import extract_keywords_given_response

File ~/mambaforge/envs/predibase38/lib/python3.8/site-packages/llama_index/indices/base.py:6, in <module>
      3 from abc import ABC, abstractmethod
      4 from typing import Any, Dict, Generic, List, Optional, Sequence, Type, TypeVar, cast
----> 6 from llama_index.chat_engine.types import BaseChatEngine, ChatMode
      7 from llama_index.data_structs.data_structs import IndexStruct
      8 from llama_index.indices.base_retriever import BaseRetriever

File ~/mambaforge/envs/predibase38/lib/python3.8/site-packages/llama_index/chat_engine/__init__.py:1, in <module>
----> 1 from llama_index.chat_engine.condense_question import CondenseQuestionChatEngine
      2 from llama_index.chat_engine.context import ContextChatEngine
      3 from llama_index.chat_engine.simple import SimpleChatEngine

File ~/mambaforge/envs/predibase38/lib/python3.8/site-packages/llama_index/chat_engine/condense_question.py:6, in <module>
      3 from typing import Any, List, Optional, Type
      5 from llama_index.callbacks import CallbackManager, trace_method
----> 6 from llama_index.chat_engine.types import (
      7     AgentChatResponse,
      8     BaseChatEngine,
      9     StreamingAgentChatResponse,
     10 )
     11 from llama_index.chat_engine.utils import response_gen_from_query_engine
     12 from llama_index.indices.query.base import BaseQueryEngine

File ~/mambaforge/envs/predibase38/lib/python3.8/site-packages/llama_index/chat_engine/types.py:14, in <module>
     12 from llama_index.response.schema import Response, StreamingResponse
     13 from llama_index.schema import NodeWithScore
---> 14 from llama_index.tools import ToolOutput
     16 logger = logging.getLogger(__name__)
     17 logger.setLevel(logging.WARNING)

File ~/mambaforge/envs/predibase38/lib/python3.8/site-packages/llama_index/tools/__init__.py:4, in <module>
      1 """Tools."""
      3 from llama_index.tools.query_engine import QueryEngineTool
----> 4 from llama_index.tools.retriever_tool import RetrieverTool
      5 from llama_index.tools.types import (
      6     BaseTool,
      7     ToolMetadata,
   (...)
     10     AsyncBaseTool,
     11 )
     12 from llama_index.tools.function_tool import FunctionTool

File ~/mambaforge/envs/predibase38/lib/python3.8/site-packages/llama_index/tools/retriever_tool.py:5, in <module>
      1 """Retriever tool."""
      3 from typing import Any, Optional, cast
----> 5 from llama_index.indices.base_retriever import BaseRetriever
      6 from llama_index.tools.types import AsyncBaseTool, ToolMetadata, ToolOutput
      7 from llama_index.langchain_helpers.agents.tools import LlamaIndexTool

File ~/mambaforge/envs/predibase38/lib/python3.8/site-packages/llama_index/indices/base_retriever.py:5, in <module>
      2 from typing import List, Optional
      4 from llama_index.indices.query.schema import QueryBundle, QueryType
----> 5 from llama_index.indices.service_context import ServiceContext
      6 from llama_index.schema import NodeWithScore
      9 class BaseRetriever(ABC):

File ~/mambaforge/envs/predibase38/lib/python3.8/site-packages/llama_index/indices/service_context.py:17, in <module>
     15 from llama_index.llms.utils import LLMType, resolve_llm
     16 from llama_index.logger import LlamaLogger
---> 17 from llama_index.node_parser.interface import NodeParser
     18 from llama_index.node_parser.sentence_window import SentenceWindowNodeParser
     19 from llama_index.node_parser.simple import SimpleNodeParser

File ~/mambaforge/envs/predibase38/lib/python3.8/site-packages/llama_index/node_parser/__init__.py:4, in <module>
      1 """Node parsers."""
      3 from llama_index.node_parser.interface import NodeParser
----> 4 from llama_index.node_parser.simple import SimpleNodeParser
      5 from llama_index.node_parser.sentence_window import SentenceWindowNodeParser
      6 from llama_index.node_parser.hierarchical import (
      7     HierarchicalNodeParser,
      8     get_leaf_nodes,
      9     get_root_nodes,
     10 )

File ~/mambaforge/envs/predibase38/lib/python3.8/site-packages/llama_index/node_parser/simple.py:7, in <module>
      5 from llama_index.callbacks.base import CallbackManager
      6 from llama_index.callbacks.schema import CBEventType, EventPayload
----> 7 from llama_index.node_parser.extractors.metadata_extractors import MetadataExtractor
      8 from llama_index.node_parser.interface import NodeParser
      9 from llama_index.node_parser.node_utils import get_nodes_from_document

File ~/mambaforge/envs/predibase38/lib/python3.8/site-packages/llama_index/node_parser/extractors/__init__.py:1, in <module>
----> 1 from llama_index.node_parser.extractors.metadata_extractors import (
      2     MetadataExtractor,
      3     SummaryExtractor,
      4     QuestionsAnsweredExtractor,
      5     TitleExtractor,
      6     KeywordExtractor,
      7     EntityExtractor,
      8     MetadataFeatureExtractor,
      9 )
     10 from llama_index.node_parser.extractors.marvin_metadata_extractor import (
     11     MarvinMetadataExtractor,
     12 )
     14 __all__ = [
     15     "MetadataExtractor",
     16     "MetadataExtractorBase",
   (...)
     23     "MarvinMetadataExtractor",
     24 ]

File ~/mambaforge/envs/predibase38/lib/python3.8/site-packages/llama_index/node_parser/extractors/metadata_extractors.py:644, in <module>
    632         return metadata_list
    635 DEFAULT_EXTRACT_TEMPLATE_STR = """\
    636 Here is the content of the section:
    637 ----------------
   (...)
    640 Given the contextual information, extract out a {class_name} object.\
    641 """
--> 644 class PydanticProgramExtractor(MetadataFeatureExtractor):
    645     """Pydantic program extractor.
    646 
    647     Uses an LLM to extract out a Pydantic object. Return attributes of that object
    648     in a dictionary.
    649 
    650     """
    652     program: BasePydanticProgram = Field(
    653         ..., description="Pydantic program to extract."
    654     )

File ~/mambaforge/envs/predibase38/lib/python3.8/site-packages/llama_index/node_parser/extractors/metadata_extractors.py:655, in PydanticProgramExtractor()
    645 """Pydantic program extractor.
    646 
    647 Uses an LLM to extract out a Pydantic object. Return attributes of that object
    648 in a dictionary.
    649 
    650 """
    652 program: BasePydanticProgram = Field(
    653     ..., description="Pydantic program to extract."
    654 )
--> 655 input_key: str = Field(
    656     default="input",
    657     description=(
    658         "Key to use as input to the program (the program "
    659         "template string must expose this key).",
    660     ),
    661 )
    662 extract_template_str: str = Field(
    663     default=DEFAULT_EXTRACT_TEMPLATE_STR,
    664     description="Template to use for extraction.",
    665 )
    667 @classmethod
    668 def class_name(cls) -> str:

TypeError: Argument 'description' has incorrect type (expected str, got tuple)
dosubot[bot] commented 1 year ago

🤖

Hello,

Thank you for reporting this issue. The error you're encountering, TypeError: Argument 'description' has incorrect type (expected str, got tuple), seems to be related to the Pydantic library, which is used in LlamaIndex.

Based on a similar issue that was resolved in the past (#7817), the problem might be due to the version of Pydantic you're using. The solution in that case was to install a specific version of Pydantic, version 1.10.12, by running pip install pydantic==1.10.12.

Please try this solution and let us know if it resolves your issue. If not, we may need more information to further investigate the problem.

Best, Dosu

Sources


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.

connor-mccorm commented 1 year ago

Brillian! Will try now, thank you!

connor-mccorm commented 1 year ago

Nice it worked. Thank you for the super fast reply!