Find answers from the community

Updated 3 months ago

Hi guys, I started my first RAG project

Hi guys, I started my first RAG project using LlamaIndex and am having trouble importing the openai module in the package.

Im doing
from llama_index.llms import OpenAI
L
P
9 comments
incorrect import

from llama_index.llms.openai import OpenAI
Do check out our docs for any latest usage πŸ™
Thanks so much
any idea why I am having an issue with this?
Code:

python3 -m venv env

source env/bin/activate

from note_engine import note_engine
import os
from prompts import new_prompt, instruction_str, context
import pandas as pd
from dotenv import load_dotenv
from llama_index.core.tools import QueryEngineTool, ToolMetadata
from llama_index.experimental.query_engine import PandasQueryEngine
from llama_index.core.agent import ReActAgent
from llama_index.llms.openai import OpenAI

pipeline of diff tools it has access to

load_dotenv()
population_path = os.path.join("data", "data.csv")
population_df = pd.read_csv(population_path)

population_query_engine = PandasQueryEngine(df=population_df,verbose=True, instruction_str=instruction_str)
population_query_engine.update_prompts(new_prompt)


tools = [
note_engine,
QueryEngineTool(query_engine=population_query_engine, metadata=ToolMetadata(
name="earthquake_data",
description="Query earthquake data",
)
)
]

llm = OpenAI(model="gpt-3.5-turbo-0125")
agent = ReActAgent.from_tools(tools,llm=llm,verbose=True, context = context)

while(prompt := input("Enter a prompt q to quit")) != "q":
result = agent.query(prompt)
print(result)
Error:

Traceback (most recent call last):
File "/Users/patrickmoorhead/Code/AIagenttutorial/agent.py", line 34, in <module>
result = agent.query(prompt)
^^^^^^^^^^^^^^^^^^^
File "/Users/patrickmoorhead/Code/AIagenttutorial/agent/lib/python3.12/site-packages/llama_index/core/instrumentation/dispatcher.py", line 230, in wrapper
result = func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/patrickmoorhead/Code/AIagenttutorial/agent/lib/python3.12/site-packages/llama_index/core/base/base_query_engine.py", line 52, in query
query_result = self._query(str_or_query_bundle)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I can send the prompt files but I first wanted to check if it might be a syntax issue
Do you have the full traceback? Seems like its missing some detail on what the error actually was

But besides that, you code seems fine at first glance
sorry for the late response, i figured it out, it has issues if it doesnt have any tool that it can use, "hi" = error, "find earthquakes using tool" = perfect, Thank you for your help
Add a reply
Sign up and join the conversation on Discord