BaşlayınÜcretsiz Başlayın

Query bakery sales data using SQL agent

The "bakehouse" schema in the samples catalog in Databricks contains fabricated data about bakery sales. We can create a LangChain Databricks SQL agent to connect to this dataset and then ask the agent queries about the data. The agent can use SQL to get the answers and can show it's work, describing the SQL queries and logic used to get to the solution.

Bu egzersiz

Databricks with the Python SDK

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Create a LangChain SQL database from the bakehouse dataset in the samples catalog.
  • Create a SQLDatabaseToolkit object that connects to the LangChain SQL database and llm.
  • Create a LangChain SQL Agent that connects to the llm and toolkit.
  • Ask the Databricks SQL agent which product generates the most revenue.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Create a LangChain SQL database from the `bakehouse` dataset in the `samples` catalog
bakehouse_db = SQLDatabase.from_databricks(
    ____="samples", 
    schema="bakehouse",  
  	warehouse_id=warehouse_id)

# Create a SQLDatabaseToolkit object that connects to the LangChain SQL database and llm
toolkit = SQLDatabaseToolkit(____=bakehouse_db, llm=llm)
# Create a LangChain SQL Agent that connects to the llm and toolkit
agent = ____(llm=llm, toolkit=toolkit, verbose=True, handle_parsing_errors=True)

# Ask the Databricks SQL agent which product generates the most revenue
prompt = "Which product generates the most revenue?"
result = agent.run(____)
print(result)
Kodu Düzenle ve Çalıştır