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

Query NYC Taxi Dataset using SQL Agent

Databricks exposes an open source samples catalog that contains several schemas. In this exercise, we will create a LangChain Databricks SQL agent to connect to the nyctaxi schema and then ask it a question that requires SQL to answer. Creating one of these agents empowers the user to perform data analysis and ask questions on data that require SQL, with no prior knowledge of SQL.

Bu egzersiz, kursun bir parçasıdır

Databricks with the Python SDK

Kursa Göz Atın

Egzersiz talimatları

  • Create LangChain SQLDatabase object from nyctaxi schema in Databricks samples catalog.
  • Create a custom LangChain LLM using the Databricks Meta Llama 3 model.
  • Create a LangChain Databricks SQL Agent using the custom LLM.
  • Query the Databricks SQL Agent.

Uygulamalı etkileşimli egzersiz

Bu egzersizi bu örnek kodu tamamlayarak deneyin.

# Create LangChain SQLDatabase object from `nyctaxi` schema in Databricks `samples` catalog
db = SQLDatabase.from_databricks(
    ____="samples", 
    ____="nyctaxi",  
  	warehouse_id=warehouse_id)

# Create a custom LangChain LLM using the Databricks Meta Llama 3 model
meta_llm = ChatDatabricks(
    ____="databricks-meta-llama-3-3-70b-instruct",
    max_tokens=100)
toolkit = SQLDatabaseToolkit(db=db, llm=meta_llm)

# Create a LangChain Databricks SQL Agent using the custom LLM created above
agent = create_sql_agent(llm=____, toolkit=toolkit, verbose=True, handle_parsing_errors=True)

# Query the Databricks SQL Agent
result = agent.____("what's the duration and distance of the longest trip?")
print(result)
Kodu Düzenle ve Çalıştır