Skip to main content

langworks

Flexibly instruct and prompt LLMs in Python

| Documentation |

About

Langworks is an open-source framework build on top of Pypeworks to flexibly instruct and prompt LLMs in Python. It offers the following features:

  • Chained prompting with conditional pathways
  • Templatable prompts and responses using Jinja
  • Guided generation constrained by regex and context-free grammar
  • Mixing and matching of LLMs and LLM servers (with support for llama.cpp and vLLM)
  • Distributed inference with autoscaling support
  • Fine-tuning of sampling parameters per prompt

Install

Langworks is available through the PyPI repository and can be installed using pip:

pip install langworks

Quickstart

A Langwork represents a specialised pipework consisting of Query and Node objects. A Query object encapsulates a templatable prompt that may be passed to a LLM, as well as any guidance on how that LLM may process that prompt. Nodes serve as processing units, to be used to prepare input for Query objects, or to process output received from these objects.

Assuming a vLLM-backend running Llama-3 is available, a Langwork may be instantiated as follows:

from langworks import (
    Connection,
    Langwork,
    Query
)

from pypeworks import (
    Node
)

from langworks.middleware.vllm import (
    SamplingParams,
    vLLM
)

langwork = Langwork(

    # Configuration
    middleware = vLLM(
        url          = "http://127.0.0.1:4000/v1",
        model        = "meta-llama/Meta-Llama-3-8B-Instruct",
        params       = SamplingParams(temperature = 0.3)
    ),

    system_msg = [
        {
            "role": "system",
            "content": (
                "You are a helpful assistant knowledgable about popular trivia."
            )
        }
    ],

    # Logic
    query = Query(

        query = (
            """
            Who or what is more popular: {{ input[0] }} or {{ input[1] }}? Think step-by-step \\
            before stating your final answer, either '{{ input[0] }}' or '{{ input[1] }}', \\
            delimited by triple asterisks (i.e. ***{{ input[0] }}*** or ***{{ input[1] }}***).
            """
        ),

        guidance = (
            """
            Let's think step-by-step\\
            {% gen params = Params(stop = ["***"], include_stop = True) %}\\
            {% choice input, var = "hit" %, params = Params(temperature = 0)}\\
            ***
            """
        )

    ),

    extract = Node(
        lambda context, history: context.get("hit", None)
    ),

    # Connections
    connections = [

        Connection("enter"   , "query"),
        Connection("query"   , "extract"),
        Connection("extract" , "exit")
        
    ]

)

for result in langwork(
    iter([("cats", "dogs"), ("werewolves", "vampires"), ("rock", "pop")])
):
    
    print(result)

Metadata

Release files for langworks 0.3.1

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

Source distribution (sdist)

Source distribution for langworks 0.3.1
File Size Uploaded Provenance Actions
langworks-0.3.1.tar.gz 51.4 kB Without provenance Details for langworks-0.3.1.tar.gz

Built distribution (wheel)

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

Total release size: 129.1 kB

Release files / langworks-0.3.1.tar.gz

Download URL langworks-0.3.1.tar.gz
Size 51.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ecf9586777cefd6068842eadfb3c492f79d26db0a23e253ed4a87ed8c5789b41
BLAKE2b-256 checksum
How to use checksums
b09aeb8920c88751a4d7b5aa1983ca3eed4dd8094419285a5632ff868e2f1fcb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.0

Release files / langworks-0.3.1-py3-none-any.whl

Download URL langworks-0.3.1-py3-none-any.whl
Size 77.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
734d844308a9f87decf6bd3ea5208bb979ef9831049dfb17e60324164eaae0e6
BLAKE2b-256 checksum
How to use checksums
f3c795073918ec66dc231ed5d00acc3b0c9f56186aab61a1606d3672b35ee4ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.0

Security for langworks 0.3.1

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.

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