GithubHelp home page GithubHelp logo

augiot / langchain_database_search Goto Github PK

View Code? Open in Web Editor NEW

This project forked from clairelovesgravy/langchain_database_search

0.0 0.0 0.0 77.13 MB

database search powered by llm

Python 100.00%

langchain_database_search's Introduction

README.md

Query database using natural language powered by Langchain

(An Interface to OpenAI GPT-3.5-turbo & SQL Databases)

Introduction

This project provides a way to use OpenAI's GPT-3.5-turbo language model in combination with SQL databases, enabling the powerful and intuitive language processing of OpenAI to interact with databases directly. This is achieved using the langchain module which includes classes like OpenAI, SQLDatabase, and SQLDatabaseChain.

Prerequisites

Before starting with this project, ensure you have the following:

  1. Python 3.6 or newer
  2. OpenAI's Python package
  3. MySQL Connector Python (Optional if using a MySQL database)
  4. SQLite database or MySQL database

Install necessary packages using pip:

pip install openai
pip install langchain
pip install mysql-connector-python

Setting Up

  1. Initialize OpenAI model: Initialize the OpenAI model using the OpenAI class from langchain module. It requires an API key that can be retrieved from your OpenAI account.initialize your openai-api-key in terminal.
export OPENAI_API_KEY='your own api key'
  1. Connect to Database: Create an instance of the SQLDatabase object that connects to the SQLite database or MySQL database using the from_uri method.

  2. Create SQLDatabaseChain object: Create an instance of the SQLDatabaseChain object that connects the OpenAI model to the SQLDatabase.

Usage

After setup, run a while loop to take in user input. If the user types "quit", the loop will break. Otherwise, it will run the input question through the SQLDatabaseChain object which will interact with the database using the OpenAI model. Here's the code:

while True:
    question=input("Ask a question: ")
    if question=="quit":
        break
    db_chain.run(question)

The OpenAI model will interpret the question and return a relevant SQL query, which will then be executed on the connected SQL database. This functionality is encapsulated in the SQLDatabaseChain.run() method.

Conclusion

This project is a powerful tool that leverages the abilities of OpenAI's language models to interact with databases in an intuitive, conversational manner. It can be very useful for performing complex database operations without needing to write complicated SQL queries.

Note

This project is in a development phase. We encourage users to report any issues and contribute to the development by submitting pull requests.

For more information, please visit the project homepage.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Acknowledgments

  • Thanks to OpenAI for providing the GPT-3.5-turbo model.
  • Thanks to users who contribute to the project's improvement.

langchain_database_search's People

Contributors

clairelovesgravy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.