Skip to main content

AI text generator

Project description

Text Jenerator

A Unified Python Interface for Modular Text Generation.

Text Jenerator is a framework designed to provide a consistent, abstract interface for deploying and interacting with various Large Language Models (LLMs). By separating the generic configuration and workflow from the model-specific implementation, it enables you to easily switch between different model backends—such as local GGUF models (via Llama-CPP), Hugging Face Transformers, or proprietary APIs (e.g., OpenAI, Gemini), with no code changes besides the config you pass.

Features

  • Modular Architecture: Uses Abstract Base Classes (ABC) to enforce a clean separation between the model details, meaning you only need to instantiate the TextGenerator class and call generate_text(), no matter which model you're using.
  • Automatic Setup: Handles generic tasks like device detection (CPU/CUDA) and data type selection (bfloat16, float16, float32) in the base class.
  • Plug-and-Play Models: Easily integrate new models by creating concrete child classes that implement two simple abstract methods (create_pipeline and run_pipeline).
  • Model Registry: Uses a decorator (@register_model) to automatically track and load available generation backends.

Installation

pip install textjenerator

The core package has minimal dependencies. Model-specific implementations (e.g., for Llama-CPP or Transformers) require their respective libraries.

Models

Text Jenerator is BYOM. You can put the local model path or a HuggingFace ID in your config.

Quick Start & Usage

Config

Your project should include a config file (defaults are at textjenerator.config). A basic config might look like this:

config = {
    # model
    "model": "llama-cpp",
    "model_path": ".models/Llama-3.2-3B-Instruct-Q4_K_M.gguf",

    # hardware/system
    "device": "cpu",
    "dtype": "float32",

    # LLM
    "max_context_size": 4096,
    "number_of_threads": 8 ,
    "verbose_warnings": False,
    "messages_to_keep_in_context": 4,
    "max_tokens_per_response": 256,
    "temperature": 0.7 ,
    "top_p": 0.9,
    "top_k": 50,
    "messages": [ 
          {"role": "system", "content": """You are Jenbot, an expert, helpful, and diligent assistant. You provide the user with accurate answers to their queries. You are polite, friendly, and a little sarcastic."""},
          {"role": "user", "content": """Hi, who are you?"""},
    ]
}

Run the Generation

To run the main workflow:

from textjenerator.models import registry
from config import config # or load your config however you prefer

text_generator = registry.get_model_class(config) # Choose which model you want from the registry
response = text_generator.generate_text() # create pipeline and run it
print(response)

You can also do these steps separately if you want to keep the model in memory. In this case you can pass a new config, typically this will be to include the cumulative chat history, but you could also change other settings on the fly e.g.:

  • Reduce temperature for a coding question
  • Increase temperature for a creative writing request
  • Increase max_tokens_per_response if you expect a longer reply
text_generator = registry.get_model_class(config)
text_generator.create_pipeline()
response = text_generator.run_pipeline()
print(response)

# or pass another, doesn't have to be the whole thing:
new_config = {
    "messages": [ 
        {"role": "system", "content": """You are Jenbot, an expert, helpful, and diligent assistant. You provide the user with accurate answers to their queries. You are polite, friendly, and a little sarcastic."""},
        {"role": "user", "content": """Hi, who are you?"""},
        {"role": "assistant", "content": """You must be wondering who I am. Well, let me introduce myself: I'm Jenbot, your friendly AI assistant. I'm here to help answer any questions you may have, provide information on a wide range of topics, and even offer a dash of sarcasm when the situation calls for it."""},
        {"role": "user", "content": """What are your thoughts on the hard problem of consciousness?"""},
    ]
}
response = text_generator.run_pipeline(new_config)
print(response)

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

textjenerator-0.1.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

textjenerator-0.1.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file textjenerator-0.1.0.tar.gz.

File metadata

  • Download URL: textjenerator-0.1.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.3 Linux/6.14.0-36-generic

File hashes

Hashes for textjenerator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 851349ee5accc97c6126500901d4042e793ca413043a4541205b01fb525c3a88
MD5 264aa5212f6d3a9ba5b9d05fe0c1ee69
BLAKE2b-256 2ba075fb744250bdf498d9d34a96328dfc1a63e14d759ee078344a0b4229ae9a

See more details on using hashes here.

File details

Details for the file textjenerator-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: textjenerator-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.3 Linux/6.14.0-36-generic

File hashes

Hashes for textjenerator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2a09377dcedd954d3abfbb745c711f0adb2472b7863d085ff6ffe696770869b8
MD5 f651d002b5cb069bf60a57589c24240e
BLAKE2b-256 6556fa00065f42911bb2895b6ebe1adb54cc43af862fc7f8273439fad8b6a873

See more details on using hashes here.

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