cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

Resource Not Found

Rajaniesh
New Contributor III

Hi,

I am trying to write a simple code in databricks using langchain. But it is throwing this error: Resource not 

%pip install --upgrade openai

%pip install langchain --upgrade

%pip install pymssql --upgrade

%pip install SQLAlchemy

%pip install pyodbc

import os

from langchain.llms import AzureOpenAI

import openai

from langchain.agents import create_sql_agent

from langchain.agents.agent_toolkits import SQLDatabaseToolkit

from langchain.sql_database import SQLDatabase

from langchain.llms.openai import OpenAI

from langchain.agents import AgentExecutor

import pymssql

from sqlalchemy.engine import URL

# Configure OpenAI API

os.environ["OPENAI_API_TYPE"] = "azure"

os.environ["OPENAI_API_KEY"] = "xxxxxxxx"

os.environ["OPENAI_API_BASE"] = "https://zxadw.openai.azure.com/"

os.environ["OPENAI_API_VERSION"] = "2022-12-01"

llm = AzureOpenAI(deployment_name="text-davinci-003", model_name="text-davinci-003")

db = SQLDatabase.from_uri("mssql+pymssql://sqladmin:Passw0rd@hostnameofazuresqldb:1433/AdventureWorks2017")

toolkit = SQLDatabaseToolkit(db=db, llm=llm ,use_query_checker=True, verbose=True, return_intermediate_steps=True )

agent_executor = create_sql_agent(

    llm=llm,

    toolkit=toolkit,

    verbose=True,

    db=db

)

agent_executor.run("List the tables in the database")

But it throws this error:

> Entering new AgentExecutor chain...

InvalidRequestError: Resource not found

Any clue!!

Regards

Rajaniesh

1 REPLY 1

Kaniz
Community Manager
Community Manager

Hi @Rajaniesh

It seems you’re encountering an error related to the Langchain library while working with Databricks.

Let’s troubleshoot this issue step by step:

  1. AzureOpenAI Configuration:

    • Ensure that your Azure OpenAI configuration is correctly set up. Double-check the following environment variables:
    • Also, ensure that the model name (text-davinci-003) and deployment name match the resources you’ve set up in Azure.
  2. Remove Redundant Imports:

    • In your code, you’re importing both AzureOpenAI from langchain.llms and openai. Since AzureOpenAI already encapsulates the OpenAI functionality, you can remove the line import openai.
  3. Check Database Connection:

    • Verify that the connection string for your SQL database is correct. Ensure the hostname, credentials, and database name match your Azure SQL Database configuration.
  4. Resource Not Found Error:

    • The error message you’re encountering (InvalidRequestError: Resource not found) suggests that a resource (possibly a table or database) is not accessible or doesn’t exist.
    • Confirm that the database specified in your connection string (AdventureWorks2017) lives in your Azure SQL instance.
    • Also, ensure that the user (sqladmin) has the necessary permissions to access the database and its tables.
  5. Model Name and Deployment Name:

    • Make sure the model name (text-davinci-003) and the deployment name is accurate. You'll encounter resource-related errors if they don’t match the actual resources.
  6. Environment Variables:

    • Check if any other environment variables are affecting your code execution. Ensure there are no conflicting variables or incorrect values.
  7. Retry the Query:

    • After addressing the above points, try rerunning the query: agent_executor.run("List the tables in the database").

Remember to validate each step, and if you encounter any specific issues during the process, feel free to ask for further assistance! 😊

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.