import OpenAIEmbeddingsfrom langchain.vectorstores import FAISStexts = (artists + albums)embeddings = OpenAIEmbeddings()vector_db = FAISS.from_texts(texts, embeddings)retriever = vector_db.as_retriever()retriever_tool = create_retriever_tool(        retriever,        name='name_search',        description='use to learn how a piece of data is actually written, can be from names, surnames addresses etc'    )custom_tool_list = [retriever_tool]from langchain.agents import create_sql_agent, AgentTypefrom langchain.agents.agent_toolkits import SQLDatabaseToolkitfrom langchain.utilities import SQLDatabasefrom langchain.chat_models import ChatOpenAI# db = SQLDatabase.from_uri("sqlite:///Chinook.db")llm = ChatOpenAI(model_name='gpt-4', temperature=0)toolkit = SQLDatabaseToolkit(db=db, llm=llm)custom_suffix = """If a user asks for me to filter based on proper nouns, I should first check the spelling using the name_search tool.Otherwise, I can then look at the tables in the database to see what I can query.Then I should query the schema of the most relevant tables"""agent = create_sql_agent(llm=llm,                         toolkit=toolkit,                         verbose=True,                         agent_type=AgentType.OPENAI_FUNCTIONS,                         extra_tools=custom_tool_list,                         suffix=custom_suffix                        )Let's try it out:agent.run("How many albums does alis in pains have?")            > Entering new AgentExecutor chain...        Invoking: `name_search` with `alis in pains`            [Document(page_content='House of Pain', metadata={}), Document(page_content='Alice In Chains', metadata={}), Document(page_content='Aisha Duo', metadata={}), Document(page_content='House Of Pain', metadata={})]    Invoking: `sql_db_list_tables` with ``    responded: {content}        Album, Artist, Customer, Employee, Genre, Invoice, InvoiceLine, MediaType, Playlist, PlaylistTrack, Track    Invoking: `sql_db_schema` with `Album, Artist`
Open In Colab
Open In Colab ->: import OpenAIEmbeddingsfrom langchain.vectorstores import FAISStexts = (artists + albums)embeddings = OpenAIEmbeddings()vector_db = FAISS.from_texts(texts, embeddings)retriever = vector_db.as_retriever()retriever_tool = create_retriever_tool(        retriever,        name='name_search',        description='use to learn how a piece of data is actually written, can be from names, surnames addresses etc'    )custom_tool_list = [retriever_tool]from langchain.agents import create_sql_agent, AgentTypefrom langchain.agents.agent_toolkits import SQLDatabaseToolkitfrom langchain.utilities import SQLDatabasefrom langchain.chat_models import ChatOpenAI# db = SQLDatabase.from_uri("sqlite:///Chinook.db")llm = ChatOpenAI(model_name='gpt-4', temperature=0)toolkit = SQLDatabaseToolkit(db=db, llm=llm)custom_suffix = """If a user asks for me to filter based on proper nouns, I should first check the spelling using the name_search tool.Otherwise, I can then look at the tables in the database to see what I can query.Then I should query the schema of the most relevant tables"""agent = create_sql_agent(llm=llm,                         toolkit=toolkit,                         verbose=True,                         agent_type=AgentType.OPENAI_FUNCTIONS,                         extra_tools=custom_tool_list,                         suffix=custom_suffix                        )Let's try it out:agent.run("How many albums does alis in pains have?")            > Entering new AgentExecutor chain...        Invoking: `name_search` with `alis in pains`            [Document(page_content='House of Pain', metadata={}), Document(page_content='Alice In Chains', metadata={}), Document(page_content='Aisha Duo', metadata={}), Document(page_content='House Of Pain', metadata={})]    Invoking: `sql_db_list_tables` with ``    responded: {content}        Album, Artist, Customer, Employee, Genre, Invoice, InvoiceLine, MediaType, Playlist, PlaylistTrack, Track    Invoking: `sql_db_schema` with `Album, Artist`