0

I would like to use langchain with SQLDatabaseToolkit, create_pandas_dataframe_agent and PythonREPL for data analysis.

Do you have a working approach for me? My approach isn't working

# Ensure the SQLite database file exists and is accessible
database_path = 'sensor.db'
if not os.path.isfile(database_path):
    raise Exception(f"Database file not found: {database_path}")

# Erstellen Sie eine Verbindung zur SQLite-Datenbank
conn = sqlite3.connect(database_path)

# Führen Sie die SQL-Abfrage aus und lesen Sie das Ergebnis in ein DataFrame
df = pd.read_sql_query('SELECT * FROM mytable', conn)
pandas_tool = create_pandas_dataframe_agent(OpenAI(temperature=0), df, verbose=True)

#db = SQLDatabase.from_uri(f'sqlite:///{database_path}')
#toolkit = SQLDatabaseToolkit(db=db, llm=OpenAI(temperature=0))
python_repl = PythonREPL()

tools = [Tool(name="python repl", func=python_repl.run, description="useful for when you need to use python to write code to create charts from data")]
tools.append(pandas_tool)
agent_kwargs = {
    "extra_prompt_messages": [MessagesPlaceholder(variable_name="memory")],
}
memory = ConversationBufferMemory(memory_key="memory", return_messages=True)

# Create the SQL agent
llm = ChatOpenAI(temperature=0, model="gpt-3.5-turbo-0613")
zero_shot_agent = initialize_agent(
    agent="zero-shot-react-description",
    tools=tools,
    llm=llm,
    verbose=True,
    agent_kwargs=agent_kwargs,
    memory=memory
    )

I want that langchain with a LLM extracts data from a database, putting it in a data frame for data analysis and that the LLM also creates charts from this data with PythonREPL

Karsten
  • 1
  • 1

0 Answers0