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

ImportError: cannot import name 'ChatMessage' from 'llama_index.core.llms' (unknown location) #2

Open
C0deXG opened this issue Feb 20, 2024 · 2 comments

Comments

@C0deXG
Copy link

C0deXG commented Feb 20, 2024

error:
Traceback (most recent call last): File "/Users/ahmednadiir/Desktop/agency/main.py", line 4, in <module> from llama_index.core.query_engine import PandasQueryEngine File "/Users/ahmednadiir/Desktop/agency/ai/lib/python3.11/site-packages/llama_index/__init__.py", line 13, in <module> from llama_index.callbacks.global_handlers import set_global_handler File "/Users/ahmednadiir/Desktop/agency/ai/lib/python3.11/site-packages/llama_index/callbacks/__init__.py", line 7, in <module> from .token_counting import TokenCountingHandler File "/Users/ahmednadiir/Desktop/agency/ai/lib/python3.11/site-packages/llama_index/callbacks/token_counting.py", line 6, in <module> from llama_index.utilities.token_counting import TokenCounter File "/Users/ahmednadiir/Desktop/agency/ai/lib/python3.11/site-packages/llama_index/utilities/token_counting.py", line 6, in <module> from llama_index.llms import ChatMessage, MessageRole File "/Users/ahmednadiir/Desktop/agency/ai/lib/python3.11/site-packages/llama_index/llms/__init__.py", line 14, in <module> from llama_index.llms.anyscale import Anyscale File "/Users/ahmednadiir/Desktop/agency/ai/lib/python3.11/site-packages/llama_index/llms/anyscale.py", line 10, in <module> from llama_index.llms.openai import OpenAI File "/Users/ahmednadiir/Desktop/agency/ai/lib/python3.11/site-packages/llama_index/llms/openai/__init__.py", line 1, in <module> from llama_index.llms.openai.base import AsyncOpenAI, OpenAI, SyncOpenAI, Tokenizer File "/Users/ahmednadiir/Desktop/agency/ai/lib/python3.11/site-packages/llama_index/llms/openai/base.py", line 28, in <module> from llama_index.core.callbacks import CallbackManager File "/Users/ahmednadiir/Desktop/agency/ai/lib/python3.11/site-packages/llama_index/core/callbacks/__init__.py", line 4, in <module> from .token_counting import TokenCountingHandler File "/Users/ahmednadiir/Desktop/agency/ai/lib/python3.11/site-packages/llama_index/core/callbacks/token_counting.py", line 6, in <module> from llama_index.core.utilities.token_counting import TokenCounter File "/Users/ahmednadiir/Desktop/agency/ai/lib/python3.11/site-packages/llama_index/core/utilities/token_counting.py", line 6, in <module> from llama_index.core.llms import ChatMessage, MessageRole ImportError: cannot import name 'ChatMessage' from 'llama_index.core.llms' (/Users/ahmednadiir/Desktop/agency/ai/lib/python3.11/site-packages/llama_index/core/llms/__init__.py)

code:
`from dotenv import load_dotenv
import os
import pandas as pd
from llama_index.core.query_engine import PandasQueryEngine
from prompts import new_prompt, instruction_str

load_dotenv()

#my quran.json file
quran_path = os.path.join('data', 'data.json');
#load
quran_df = pd.read_json(quran_path);

quran_query_engine = PandasQueryEngine(df=quran_df, verbose=True, instruction_str=instruction_str);
quran_query_engine.update_prompts({"pandas_prompt": new_prompt})
quran_query_engine.query("how many total hasanat in the the whole quran")`

help me plz

@AnkitaKrishnan
Copy link

error: Traceback (most recent call last): File "/Users/ahmednadiir/Desktop/agency/main.py", line 4, in <module> from llama_index.core.query_engine import PandasQueryEngine File "/Users/ahmednadiir/Desktop/agency/ai/lib/python3.11/site-packages/llama_index/__init__.py", line 13, in <module> from llama_index.callbacks.global_handlers import set_global_handler File "/Users/ahmednadiir/Desktop/agency/ai/lib/python3.11/site-packages/llama_index/callbacks/__init__.py", line 7, in <module> from .token_counting import TokenCountingHandler File "/Users/ahmednadiir/Desktop/agency/ai/lib/python3.11/site-packages/llama_index/callbacks/token_counting.py", line 6, in <module> from llama_index.utilities.token_counting import TokenCounter File "/Users/ahmednadiir/Desktop/agency/ai/lib/python3.11/site-packages/llama_index/utilities/token_counting.py", line 6, in <module> from llama_index.llms import ChatMessage, MessageRole File "/Users/ahmednadiir/Desktop/agency/ai/lib/python3.11/site-packages/llama_index/llms/__init__.py", line 14, in <module> from llama_index.llms.anyscale import Anyscale File "/Users/ahmednadiir/Desktop/agency/ai/lib/python3.11/site-packages/llama_index/llms/anyscale.py", line 10, in <module> from llama_index.llms.openai import OpenAI File "/Users/ahmednadiir/Desktop/agency/ai/lib/python3.11/site-packages/llama_index/llms/openai/__init__.py", line 1, in <module> from llama_index.llms.openai.base import AsyncOpenAI, OpenAI, SyncOpenAI, Tokenizer File "/Users/ahmednadiir/Desktop/agency/ai/lib/python3.11/site-packages/llama_index/llms/openai/base.py", line 28, in <module> from llama_index.core.callbacks import CallbackManager File "/Users/ahmednadiir/Desktop/agency/ai/lib/python3.11/site-packages/llama_index/core/callbacks/__init__.py", line 4, in <module> from .token_counting import TokenCountingHandler File "/Users/ahmednadiir/Desktop/agency/ai/lib/python3.11/site-packages/llama_index/core/callbacks/token_counting.py", line 6, in <module> from llama_index.core.utilities.token_counting import TokenCounter File "/Users/ahmednadiir/Desktop/agency/ai/lib/python3.11/site-packages/llama_index/core/utilities/token_counting.py", line 6, in <module> from llama_index.core.llms import ChatMessage, MessageRole ImportError: cannot import name 'ChatMessage' from 'llama_index.core.llms' (/Users/ahmednadiir/Desktop/agency/ai/lib/python3.11/site-packages/llama_index/core/llms/__init__.py)

code: `from dotenv import load_dotenv import os import pandas as pd from llama_index.core.query_engine import PandasQueryEngine from prompts import new_prompt, instruction_str

load_dotenv()

#my quran.json file quran_path = os.path.join('data', 'data.json'); #load quran_df = pd.read_json(quran_path);

quran_query_engine = PandasQueryEngine(df=quran_df, verbose=True, instruction_str=instruction_str); quran_query_engine.update_prompts({"pandas_prompt": new_prompt}) quran_query_engine.query("how many total hasanat in the the whole quran")`

help me plz

In main.py:
change "from llama_index.query_engine import PandasQueryEngine" to "from llama_index.core.query_engine import PandasQueryEngine"

in prompts.py:
change "from llama_index import PromptTemplate" to "from llama_index.core import PromptTemplate"

@yettey74
Copy link

yettey74 commented Jul 28, 2024

change:
from llama_index.query_engine import PandasQueryEngine
to
from llama_index.experimental.query_engine import PandasQueryEngine
and
change this 👍
from llama_index.core.llms import OpenAI
to this
from llama_index.llms.openai import OpenAI

updated from [https://docs.llamaindex.ai/en/stable/examples/llm/openai/]

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

3 participants