rbehzadan/text-chunking-api

By rbehzadan

Updated about 2 years ago

REST API to split text into chunks of specified maximum tokens.

Image
Machine learning & AI
Data science
0

654

rbehzadan/text-chunking-api repository overview

Text Chunking REST API

This Docker image provides a REST API for chunking a given text into pieces of a specified size. It is built using Go, with the prose library for natural language processing and gorilla/mux for routing.

Features

  • Split text into chunks based on the specified maximum number of tokens.
  • Does not split text mid-sentence.
  • Log each request with method, URI, remote address, and duration.
  • Configurable server port through environment variable.

Usage

Pull the Image
docker pull rbehzadan/text-chunking-api:latest
Run the Container
docker run -d -p 8080:8080 rbehzadan/text-chunking-api
Custom Port

To run the server on a different port, set the PORT environment variable:

docker run -d -p 9090:9090 -e PORT=9090 rbehzadan/text-chunking-api
API Endpoints
POST /chunk
  • Request Body:

    {
      "text": "Your text here.",
      "max_tokens": 50
    }
    
  • Response:

    {
      "chunks": ["Chunk 1", "Chunk 2", ...]
    }
    
  • Error Responses:

    • 400 Bad Request for invalid request payload or non-positive max_tokens.
    • 500 Internal Server Error for errors during text processing.
Example Request
curl -X POST http://localhost:8080/chunk -H "Content-Type: application/json" -d '{"text": "Your text here.", "max_tokens": 50}'
Example Response
{
  "chunks": [
    "Your chunked text here."
  ]
}

Environment Variables

  • PORT: Port on which the server will run (default is 8080).

Contributing

  1. Fork the repository at https://github.com/rbehzadan/text-chunking-api.
  2. Create a new branch (git checkout -b feature-branch).
  3. Make your changes.
  4. Commit your changes (git commit -m 'Add new feature').
  5. Push to the branch (git push origin feature-branch).
  6. Create a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgments

Tag summary

Content type

Image

Digest

sha256:a7ca1c484

Size

12.3 MB

Last updated

about 2 years ago

docker pull rbehzadan/text-chunking-api