Skip to main content

Create LLM pipelines with ease!

Project description

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:

  1. 16 bytes header (message length)
  2. 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

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

j2pipeline-0.3.4.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

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

j2pipeline-0.3.4-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file j2pipeline-0.3.4.tar.gz.

File metadata

  • Download URL: j2pipeline-0.3.4.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for j2pipeline-0.3.4.tar.gz
Algorithm Hash digest
SHA256 4d0e18947bf721f981dd40e55b369116d0623a00ec5be628055797092c6d0b18
MD5 c1ff3005b2b5ad1e23c0e98ebaa341ea
BLAKE2b-256 ffbc1696f3ad009915afa6cf10169d5636d76e349d161682e1fe3262f4cba56d

See more details on using hashes here.

File details

Details for the file j2pipeline-0.3.4-py3-none-any.whl.

File metadata

  • Download URL: j2pipeline-0.3.4-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for j2pipeline-0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9d37e26135aa10f0c4b8b08db53ed7315d117bffc11d19b31de60cd318f20284
MD5 81d803cd46eec8dd3fa7c1f46926d42f
BLAKE2b-256 2a937449cfa9fe98da40cf5888151f7cf6d3e4cd7827e59d9d99ff7f4d31546d

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