Skip to main content

texttunnel: Efficient text processing with GPT-3.5 and GPT-4

This package offers a straightforward interface for integrating the GPT-3.5 and GPT-4 models into your natural language processing pipelines. It is optimally designed for the following scenario:

Suppose you possess a corpus of text data that you want to analyze using the GPT-3.5 or GPT-4 models. The goal is to perform extractive NLP tasks such as classification, named entity recognition, translation, summarization, question answering, or sentiment analysis. In this context, the package prioritizes efficiency and tidiness to provide you streamlined results.

Features:

  • 📄 Output Schema: Utilizes JSON Schema alongside OpenAI's function calling schema to define the output data structure.
  • ✔️ Input Validation: Ensures well-structured and error-free API requests by validating input data.
  • ✅ Output Validation: Checks the response data from OpenAI's API against the expected schema to maintain data integrity.
  • 🚦 Asynchronous Requests: Facilitates speedy data processing by sending simultaneous requests to OpenAI's API, while staying within API rate limits.
  • 🚀 Efficient Batching: Supports bulk processing by packing multiple input texts into a single request for the OpenAI's API.
  • 💰 Cost Estimation: Aims for transparency in API utilization cost by providing cost estimates before sending API requests.
  • 💾 Caching: Uses aiohttp_client_cache to avoid redundant requests and reduce cost by caching previous requests. Supports SQLite, MongoDB, DynamoDB and Redis cache backends.
  • 📝 Request Logging: Implements Python's native logging framework for tracking and logging all API requests.

Note that this package only works with function calling and only with the OpenAI API. If you're looking for a more flexible solution, consider instructor and litellm. You might also consider using the OpenAI Batch API as it offers savings compared to synchronous API calls.

⚠️ Maintenance mode: At this time no new features or enhancements are being developed. Only critical bugfixes will be made.

Installation

The package is available on PyPI. To install it, run:

pip install texttunnel

or via poetry:

poetry add texttunnel

Note: If you want to use caching, you need to install the aiohttp_client_cache extras. Please refer to the aiohttp_client_cache documentation for more information.

Usage

Check the docs: https://qagentur.github.io/texttunnel/

Create an account on OpenAI and get an API key. Set it as an environment variable called OPENAI_API_KEY.

Check the examples directory for examples of how to use this package.

If your account has been granted higher rate limits than the ones configured in the models module, you can override the default attributes of the Model class instances. See documentation of the models package module.

Development

To get started with development, follow these steps:

  • clone the repository
  • install poetry if you don't have it yet
  • navigate to the project folder
  • run poetry install to install the dependencies
  • run the tests with poetry run pytest -v

This project uses Google-style docstrings and black formatting. The docs are automatically built based on the docstrings.

Release files for texttunnel 0.3.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for texttunnel 0.3.7
File Size Uploaded
texttunnel-0.3.7.tar.gz 21.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for texttunnel 0.3.7
File Interpreter ABI Platform
texttunnel-0.3.7-py3-none-any.whl Python 3 none any Details

Total release size: 42.4 kB

Release files / texttunnel-0.3.7.tar.gz

Download URL texttunnel-0.3.7.tar.gz
Size 21.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d5dcf62cc57f42b6e6f1bde6e451ac9ac995fb23607b1d8ecdf258fd7f811d01
BLAKE2b-256 checksum
How to use checksums
a8d1a18dbcfd3cd03f22e6862a3edc73de5b74b15a8657568d60781ab1c0e6db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.0 CPython/3.9.12 Darwin/23.4.0

Release files / texttunnel-0.3.7-py3-none-any.whl

Download URL texttunnel-0.3.7-py3-none-any.whl
Size 21.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
110195c366b3b3ee207ff0b87421b4eb8d611695dfd9e26a880ea16cf1255fc4
BLAKE2b-256 checksum
How to use checksums
7e97c47cd3815ff77f28db682d3f46f6a63f8f04258083e53fb47a68b8a1bbb8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.0 CPython/3.9.12 Darwin/23.4.0

Release history Release notifications | RSS feed

This release

0.3.7 This release

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.3

2 release files

0.2.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page