Giter Club home page Giter Club logo

db-openai-assistant's Introduction

Overview

This application demonstrates the of Open AI (ChatGPT/GPT-4) to help answer questions about data by performing advanced data analytic tasks on Snowflake Database. Examples of questions are:

  • Simple: Show me daily revenue trends in 2016 per region
  • More difficult: Is that true that top 20% customers generate 80% revenue in 2016?
  • Advanced: Forecast monthly revenue for next 12 months starting from June-2018

This app requires access to Azure Open AI. Azure Open AI preview access can be requested here. GPT-4 access can be requested here

The app is deployed to Streamlit Cloud and can be accessed from https://sf-openai-assistant.streamlit.app/

Architecture

architecture

Configuration of the Application

  1. Enter Open AI and database settings if these were not done during installation (see installation below if you want to install yourself).

    settings

    Click on settings. Provide Open AI keys, deployment name and URL for ChatGPT. Optionally, you can provide deployment name for GPT-4 for advanced questions. Enter the Snowflake details for connecting to Snowflake. Click on submit to save settings.

  2. There are two applications

    • SQL Query Writing Assistant: a simple application that translate business question into SQL query language then execute and display result.
    • Data Analysis Assistant: a more sophisticated application to perform advanced data analytics such as statistical analysis and forecasting. Here we demonstrate the use of Chain of Thought and React techniques to perform multi-step processing where the next step in the chain also depends on the observation/result from the previous step.
  3. Use SQL Query Writing Assistant

    sql-assistant
    • Use a question from the FAQ or enter your own question.
    • You can select show code and/or show prompt to show SQL query and the prompt behind the scene.
    • Click on submit to execute and see result.
  4. Use Data Analysis Assistant

    data-assistant
    • Use a question from the FAQ or enter your own question.

    • You can select show code and/or show prompt to show SQL & Python code and the prompt behind the scene.

    • Click on submit to execute and see result.

    • For advanced questions such as forecasting, you can use GPT-4 as the engine

      advanced

Installation

Open AI setup

  1. Create an Azure OpenAI deployment in an Azure subscription with a GPT-35-Turbo deployment and preferably a GPT-4 deployment. Here we provide options to use both but GPT-4 should be used to address difficult & vague questions. We assume that your GPT-4 and CHATGPT deployments are in the same Azure Open AI resource.

Install the application locally

  1. Clone this repository.

  2. (Optional) Provide settings for Open AI and Database.You can either create a secrets.env file in the root of this folder as below or do it using the app's UI later on.

     AZURE_OPENAI_API_KEY="9999999999999999999999999"
     AZURE_OPENAI_ENDPOINT="https://openairesourcename.openai.azure.com/"
     AZURE_OPENAI_GPT4_DEPLOYMENT="NAME_OF_GPT_4_DEPLOYMENT"
     AZURE_OPENAI_CHATGPT_DEPLOYMENT="NAME_OF_CHATGPT_4_DEPLOYMENT"
     SNOW_ACCOUNT="lbvdurp-microsoft_csa"
     SNOW_USER="OPENAITEST"
     SNOW_PASSWORD="OpenAI@123"
     SNOW_ROLE="SYSADMIN"
     SNOW_DATABASE="NORTHWIND"
     SNOW_SCHEMA="PUBLIC"
     SNOW_WAREHOUSE="COMPUTE_WH"
    
  3. Navigate to the root of the folder

  4. Create a python environment with version from 3.7 and 3.10

    • Python 3+
      • Important: Python and the pip package manager must be in the path in Windows for the setup scripts to work.
      • Important: Ensure you can run python --version from console. On Ubuntu, you might need to run sudo apt install python-is-python3 to link python to python3.
  5. Import the requirements.txt pip install -r requirements.txt

  6. To run the application from the command line: streamlit run app.py

  7. The UI prompts for settings. If you want to save these so the next time you run the project you don't have to type them in, you can create a secrets.env file in the root of streamlit folder.

Legal

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this tool except in compliance with the License. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

This is an Open Source repository and not an official Microsoft or Snowflake offering. This tool is not endorsed by Microsoft or Snowflake.

Source

This App is ported to Snowflake thanks to the Sources provided in humans.txt

Trademarks

This project may contain trademarks or logos for projects, products, or services. SNOWFLAKE is a trademark of Snowflake Computing, Inc in the United States and/or other countries. MICROSOFT is a registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

db-openai-assistant's People

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.