Skip to content

yksnilowyrahcaz/llm-fastapi-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

llm-fastapi-example

Create API endpoints for question answering and sentiment analysis.

Photo: Shutterstock

Table of Contents

  1. File Descriptions
  2. Supporting Packages
  3. How To Use This Repository
  4. Project Motivation
  5. About The Dataset
  6. Acknowledgements
  7. Licence & copyright

File Descriptions

File Description
data/coltrane.txt text from the John Coltrane Wikipedia page
data/index.json sentence embeddings of text from coltrane.txt
main.py FastAPI app
models.py Hugging Face models and supporting functions
requirements.in pip-tools spec file for requirements.txt
requirements.txt list of python dependencies

Supporting Packages

In addition to the standard python library, this analysis utilizes the following packages:

Please see requirements.txt for a complete list of packages and dependencies used in the making of this project.

How To Use This Repository

  1. Clone the repo locally or download and unzip this repository to a local machine.

  2. Navigate to this directory and open the command line. For the purposes of running the scripts, this will be the root directory.

  3. Create a virtual environment to store the supporting packages.

     python -m venv venv --upgrade-deps
    
  4. Activate the virtual environment.

     venv\scripts\activate
    
  5. Install the supporting packages from the requirements.txt file.

     pip install -r requirements.txt
    
  6. Run "uvicorn main:app --reload"

  7. Open up a browser and go to 127.0.0.1:8000/docs and try out the two endpoints.

Note: if you do not have the hugging face models already, they will be downloaded and cached on your machine in the C:\Users\USEDID\.cache folder

Project Motivation

It is interesting to consider indexing a corpus with sentence embeddings and using them to query an LLM in a closed loop way, without calls to an external web API. This repo contributes an example in how to do this for the tasks of question answering from a knowledge base, as well as sentiment analysis.

About The Dataset

See John Coltrane Wikipedia page.

Acknowledgements

Thanks to the developers who created the foundations for this example.

License & copyright

© Zachary Wolinsky 2023

Licensed under the MIT License

About

FastAPI + Hugging Face Transformers + LlamaIndex

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages