Giter Club home page Giter Club logo

llama-index-fastapi's Introduction

A Local Knowledge Base Augmented LLM able to serve millions of users, on top of llama index, fastapi and MongoDB

pic

  • if user asks a question, the bot will try to match the question and find the answer from local database first
  • local knowledge base is a csv file of question/answer pairs, which is embedded(vectorized) by llama index when first run
  • if no good matches found, the bot then call openAI's chatgpt api to get the answer, and insert the question/answer pair into the index. so next time the bot will be able to answer a similar question from local database
  • if the question is not relevant to the topic(in our case the topic is Golf), the bot will call openAI's chatgpt api to get the answer

When asking a question in the knowledge base

pic

When asking a question which is not relevant to the topic

pic

More details

  • the bot uses fastapi as the web framework, llama index as the search engine, MongoDB as the metadata storage
  • during the first run, csv file is ingested and embedded by llama index as vector store, and the metadata is stored in MongoDB
  • the bot uses https://api.openai.com/v1/embeddings for embedding. it is very cheap and with high performance
  • the bot uses https://api.openai.com/v1/chat/completions to ask chatgpt for answers. by default gpt-3.5-turbo is used as the model
  • concurrency is naturally supported

Next steps

  • currently the bot only supports question answering. plan to support chat as well.
  • use openAI's Assistant API as the search engine(I've already tried, but it is not as good as llama index at the moment)
  • more test cases

Development

  • Setup Environment
export OPENAI_API_KEY=your_openai_api_key
virtualenv -p python3.9 env
source env/bin/activate
pip install -r requirements.txt
  • Run the application locally
PYTHONPATH=. python app/main.py
PYTHONPATH=. python app/utils/api-docs/extract_openapi.py app.main:app --out openapi.yaml
python app/utils/api-docs/swagger_html.py < openapi.yaml > swagger.html
python app/utils/api-docs/redoc_html.py < openapi.yaml > redoc.html
  • Test cases(for local tests)
    • write test cases in /app/tests/test_*.py
    • need to pass local test cases before commit

Reference

llama-index-fastapi's People

Contributors

pengxiaoo avatar deepersea avatar chunyang-wen 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.