Skip to content

Building an API using FastAPI, which allows users to have text-based conversations with a Language Model. It is built on GPT4All and Langchain. Useres can interact with Language Models, like LLama2, GPT-3, and can generate human-like text based on the input provided, making it an interesting tool for various applications.

Notifications You must be signed in to change notification settings

foscraft/fastLLMs-api

Repository files navigation

This project is under active development and more details are being updated. Let's work together and explore only the imaginable throuGh AI

fastLLMsAPI

Introduction

This project is about building an API using FastAPI, which allows users to have text-based conversations with a Language Model. It is built on GPT4All and Langchain. Useres can interact with Language Models, like LLama2, GPT-3, and can generate human-like text based on the input provided, making it an interesting tool for various applications, including chatbots.

Query own data

It also allows users to query their own data by first creating embeddings by running the..

python3 create_embeddings.py

To generate embeddings.

Technologies Used

  • FastAPI: A modern, fast (high-performance) web framework for building APIs with Python.
  • Language Model (e.g., GPT-3): Used to generate responses to user queries.
  • Python: The programming language used for the development.

How to Run

  1. Clone the repository:

    git clone <repository-url>
    cd fastLLMs-api

For poetry

poetry run uvicorn main:app --reload

For non poetry

uvicorn main:app --reload

Visit

http://localhost:8000/api/v1/ask

FastAPI Chatbot API with Language Models

Features

Ask Question -1

  • Endpoint: /api/v1/ask
  • Method: POST
  • Description: Submit a query and receive an answer from the language model chain.
  • Request Body:
    • Form Data Parameters:
      • query (string): The query or question to ask the model.
  • Response:
    • Content Type: application/json
    • Body:
      • answer (string): The answer generated by the language model chain.
      • documents (array): An array of documents related to the answer.
      • query_time (float): The time taken to process the query in seconds.

Example

Request

POST /api/v1/ask HTTP/1.1
Content-Type: application/json

{
    "query":"HWhat is the safety situation of elephants in Kenya?"
}

Response

HTTP/1.1 200 OK
Content-Type: application/json

{
    "answer": " According",
    "documents": [
        {
            "metadata": {
                "row": 80807,
                "source": "source_documents/HYPERLINK_KENYA_TEXT.csv"
            },
            "page_content": "live in close proximity to elephants and hence can play a positive role in elephant conservation by informing the authorities of the presence of injured elephants. MethodologyPrincipal Findings  Between 2007 and 2011 129 elephants were monitored in Masai Mara Kenya of which 54 had various types of active intentionally caused or passive nonintentionally caused injuries. Also studied were 75 random control samples of apparently unaffected animals. The observed active injuries were as expected"
        },
        {
            "metadata": {
                "row": 43965,
                "source": "source_documents/HYPERLINK_KENYA_TEXT.csv"
            },
            "page_content": "text: Injuries of free ranging African elephants Loxodonta africana africana in various ranges of Kenya. Incidences of injuries to the free ranging African elephants Loxodonta africana africana are common but are rarely analysed to determine the magnitude and their effects on elephant health at population level. We analysed data derived from Kenya Wildlife Service records of reported incidences of injured elephants over a tenyear period 19982007 from all conservation areas in Kenya. A total of"
        },
        {
            "metadata": {
                "row": 34751,
                "source": "source_documents/HYPERLINK_KENYA_TEXT.csv"
            },
            "page_content": "text: Conflict between humans and elephants on private land in northern Kenya. About 3000 elephants live in the LaikipiaSambnru region of northern Kenya  the largest remaining population outside the countrys formal protected areas. The elephants occasionally kill or injure people damage the crops of smallscale farmers drive cattle away from water sources and cause a range of other problems for the human population. As a result a number of elephants have been shot for control purposes in recent"
        },
        {
            "metadata": {
                "row": 28407,
                "source": "source_documents/HYPERLINK_KENYA_TEXT.csv"
            },
            "page_content": "text: Shocking elephants Fences and crop raiders in Laikipia District Kenya. Abstract Electric fences and other barriers to prevent movement of elephants onto arable land are increasingly important conservation tools in Africa as elephant populations become isolated by areas of increasing human settlement. In Laikipia District in Kenya crop raiding by elephants is a serious problem and many different types of elephant barriers have been built over the last 30 years. In order to assess the"
        }
    ],
    "query_time": 50.83
}

Error Responses

  • HTTP 400 Bad Request:

    • Response Body:

      {
        "error": "Please provide a query."
      }
  • HTTP 500 Internal Server Error:

    • Response Body:

      {
        "error": "Failed to set up the language model chain."
      }
  1. GET /docs: FastAPI automatically generates interactive API documentation using Swagger UI. Users can explore the API and test it using this interface.
Authentication

To protect access to the API and manage usage, API key authentication or other authorization mechanisms can be implemented.

About

Building an API using FastAPI, which allows users to have text-based conversations with a Language Model. It is built on GPT4All and Langchain. Useres can interact with Language Models, like LLama2, GPT-3, and can generate human-like text based on the input provided, making it an interesting tool for various applications.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published