J2pipeline
Installation
Create Python 3.12 virtual environment, activate it and run
pip install j2pipeline
Setup
J2pipeline requires an active TCP server listening on port 50027
Server:
- Receives a prompt
- Sends back AI response
Protocol:
- 16 bytes header (message length)
- Message (in UTF-8)
For example:
data: bytes = message.encode(encoding='UTF-8')
size: bytes = f'{len(data):16}'.encode(encoding='UTF-8')
server.send(size)
server.send(data)
Server
-
For personal use, you might consider installing a Telegram GPT server available at
https://github.com/yaz008/TG-GPT-API -
You can write your own server following the described protocol
Usage
Prompt
Prompt creates a function based on a single template file
Params
- path: path to a template file
- process: function that modifies LLM output
- auto_upper: makes sure all arguments passed in the template are in upper case
Example
Suppose we have a translate.j2 file
Translate the following text into {% LANGUAGE %}:
{% TEXT %}
From this template we can than create translate function
from j2pipeline import Prompt
translate: Prompt[str] = Prompt[str](path='translate.j2')
text: str = 'Quelle heure est-il?'
translation: str = translate(language='English', text=text)
print(translation)
In the output we shall see
What time is it?
Pipeline
Pipeline creates a function based on a sequence of templates
Params
- base_path: path to a folder with templates
- reorder: function that takes a list of files and returns reordered one
- process: a dict where keys are template names and values are respective modifiers
- final_process: function that processes the final result
- extension: common extension of the template files
Example
Suppose we have two template files in yoderize folder
yoda.j2:
You are Yoda from Star Wars, so you must speak like him
Rewrite this text in style of Yoda
{% PROMPT %}
translate.j2:
Translate the following text into German preserving the style of Yoda:
{% PROMPT %}
Your response must only contain the translation
From this template we can than create yoderize function
from j2pipeline import Pipeline
yoderize: Pipeline[str] = Pipeline[str](base_path='yoderize',
reorder=lambda _: ['yoda', 'translate'],
final_process=lambda text: f'German Yoda:\n{text}')
yoderized: str = yoderize(prompt='I give you an advice: you should be wise')
print(yoderized)
In the end we shall see
German Yoda:
Weise, sein solltest du. Rat, gebe ich dir.
License
J2pipeline is a free, open-source software distributed under the MIT License
Metadata
Release files for j2pipeline 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| j2pipeline-0.4.0.tar.gz | 7.1 kB | Without provenance | Details for j2pipeline-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| j2pipeline-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for j2pipeline-0.4.0-py3-none-any.whl |
Total release size: 14.7 kB
Release files / j2pipeline-0.4.0.tar.gz
| Download URL | j2pipeline-0.4.0.tar.gz |
|---|---|
| Size | 7.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2fe99e7e7f13bef82beded841de83f05b460aa0f5b31a60c9c613700e00169f3
|
|
BLAKE2b-256 checksum How to use checksums |
798339f87a4d911ff75c97b316691e742b3d608437ec45d2c7f2b8aee1c9a80b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.10
|
Release files / j2pipeline-0.4.0-py3-none-any.whl
| Download URL | j2pipeline-0.4.0-py3-none-any.whl |
|---|---|
| Size | 7.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
96eaa56f838238a1683d0a13b314fcbc6f37e36d1eeeb08eaf10f4eec5003959
|
|
BLAKE2b-256 checksum How to use checksums |
6177b51f1954b7248752f05fe292373c9fdb152602acd6a9b24f875af6917242
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.10
|
Security for j2pipeline 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.