Code Monkey home page Code Monkey logo

redis-openai-qna's Introduction

Drawing

Question & Answering using LangChain, Redis & OpenAI

LangChain simplifies the development of LLM applications through modular components and "chains". It acts as a wrapper around several complex tools and makes us more efficient in our development workflow.

Redis plays a crucial role with large language models (LLMs) for a few reasons. It can store and retrieve data in near realtime (for prompt caching) and can also index vector embeddings for semantic search. Semantic search enables the LLM to attach to "external memory" or "knowledge" to augment the LLM prompts and ensure greater quality in results. Redis has both the developer community and battle-tested, enterprise-readiness required to deploy quality AI-enabled applications in this demanding marketplace.

OpenAI and Azure's OpenAI Service are shaping the future of next-gen apps through it's release of powerful natural language and computer vision models that are used in a variety of downstream tasks.

This example Streamlit app gives you the tools to get up and running with Redis as a vector database, OpenAI as a LLM provider for embedding creation and text generation, and LangChain for application dev. The combination of these is what makes things happen.

ref arch


Run the App

The example QnA application uses a dataset from wikipedia of articles about the 2020 summer olympics. The first time you run the app -- all docs will be downloaded, processed, and stored in Redis. This will take a few minutes to spin up initially. From that point forward, the app should be quicker to load.

Docker Compose

  1. Create your env file:

    $ cp .env.template .env

    fill out values, most importantly, your OPENAI_API_KEY.

  2. Run with docker compose:

    $ docker compose up

    add -d option to daemonize the processes to the background if you wish.

    Issues with dependencies? Try force-building with no-cache:

    $ docker compose build --no-cache
    
  3. Navigate to:

    http://localhost:8080/
    

NOW: Ask the app anything about the 2020 Summer Olympics!

Using Azure OpenAI

If using Azure OpenAI - use .env.azure.template instead. Some clarifications below:

  • Besides OPENAI_API_KEY, make sure to fill in your own value for OPENAI_API_BASE and create Model Deployment for the engines such as text-davinci-003.
  • Also be sure to update the REDIS environment vars as needed.
  • Currently (May 2023) Embedding Generation on Azure OpenAI is limited in batch size and request frequency, that makes it unusable for the purposes of this demo.
  • In the meantime if OPENAI_API_TYPE=azure - this demo will load and use HuggingFace all-MiniLM-L6-v2 embeddings. You might be able to request a service limit increase for your Azure subscription to address it.
  • Check out this end to end example created by practitioners at MSFT.

Optional dev env

Use the provided conda env for development:

conda env create -f environment.yml

This is useful for local development outside of docker. But this is not strictly necessary.

redis-openai-qna's People

Contributors

tylerhutcherson avatar antonum 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.