Skip to main content

Document summarization API service

Project description

wordmill

A work-in-progress.

wordmill is a document summary API service. It provides a simple REST API which accepts requests to summarize a document. Under the hood, it reaches out to a LLM hosted on any OpenAI-compatible API service.

It is designed to abstract away the "AI" details from your user base. Many people in your organization want to summarize documents. Not as many of them care to know all the details related to LLMs, prompts, document prep, model selection, etc. The service will allow administrators to configure and customize these aspects based on the incoming document type. All the end users need to do is request a summary.

Setup

  1. It is recommended to install pyenv.

    NOTE: Make sure to follow all steps! (A, B, C, D, and so on)

  2. Set up the virtual environment:

    pipenv install --dev
    
  3. Add your LLM access info into .env, example:

    LLM_API_KEY=<your key>
    LLM_BASE_URL="https://my-llm-server:443/v1"
    LLM_MODEL_NAME="mistral-7b-instruct"
    

Running API server

To run the server:

pipenv shell
flask run

Example Usage of the API server

The service accepts a request to summarize the document and returns a URL that you should visit to check the status of your summary.

A background task reaches out to the LLM and awaits the response. Eventually, the status of your summarize task will shift to 'done' and you can view the LLM-generated content. Your task may also shift to 'error' if something went wrong.

Since these summaries do not need to be long-lived, currently we are using flask-caching's "SimpleCache" to store the data. For production purposes, the cache service used by flask-caching will need to be changed to redis or memcached

import json
import requests
import time

# load the document you wish to summarize
with open("incident.json") as fp:
    data = json.load(fp)

# customize the prompt passed to the LLM (optional)
requests.post(
    "http://127.0.0.1:8000/prompt",
    json={"prompt": "Please summarize this document:\n\n{document}"}
)

# submit request to summarize and get background task id
id = requests.post("http://127.0.0.1:8000/summarize", json={"document": data}).json()["id"]

# repeatedly check on the 'summarize' task and wait for summary to be generated...
while True:
    time.sleep(5)
    summary = requests.get(f"http://127.0.0.1:8000/summary/{id}").json()
    if summary["status"] == "done":
        print(summary["content"])
        break

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wordmill-0.0.1.tar.gz (37.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wordmill-0.0.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file wordmill-0.0.1.tar.gz.

File metadata

  • Download URL: wordmill-0.0.1.tar.gz
  • Upload date:
  • Size: 37.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for wordmill-0.0.1.tar.gz
Algorithm Hash digest
SHA256 cddccbb4b19ca472b25739971e50f88480eb38de43a533491f65cef85893232f
MD5 828ea5c72d44ad762e6bf373405df471
BLAKE2b-256 08f0336e1fd6d80d918de5ae4a307c812d62207d4d5dcb95e17c0ca8ffe2bce2

See more details on using hashes here.

Provenance

The following attestation bundles were made for wordmill-0.0.1.tar.gz:

Publisher: release.yml on RedHatInsights/wordmill

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file wordmill-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: wordmill-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for wordmill-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7f8663b8353e5ec47725af9a4a52fee0ffaf3f5e53630f54a33f3ac3ecd98a60
MD5 296877ba8edb2287dba7e19951ca24a3
BLAKE2b-256 f731456143f16556689dd79ccff34e7941660b69a2cd12038c669c0c0e6e5298

See more details on using hashes here.

Provenance

The following attestation bundles were made for wordmill-0.0.1-py3-none-any.whl:

Publisher: release.yml on RedHatInsights/wordmill

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page