Langwork

Langwork#

class langworks.Langwork#

A Langwork is a specialised pypeworks’ Pipework allowing for easy access to LLMs.

Fundamentals#

__init__(system_msg: Thread | None = None, ignore_history: bool = False, context: dict | None = None, ignore_context: bool | Sequence[str] | None = None, middleware: Middleware | None = None, processes: int | None = None, logger: Logger = None, ignore_errors: Sequence[BaseException] = None, connections: list[Connection] = [], **nodes: Query | type[Langwork] | Node)#

Sets up a Langwork object, a generic pipework based on the pypeworks framework designed specifically to query generative AIs.

Parameters#

system_msg

System messages to prepend to any history provided by a Query. When the input specifies a specific history, the system messages are not prepended.

ignore_history

Flag that signals whether any history provided by Query or input should be ignored. By default these histories are taken into account. If set to True, these histories are ignored, and each prompt starts with the given system messages, as if starting a new thread.

context

Context used by Langworks’ DSL to fill in any templated parts of any queries, history or guidance included in the prompt passed to the LLM. In case the Query or Langwork also define a context, the available contexts are merged. When duplicate attributes are observed, the value is copied from the most specific context, i.e. input context over Query context, and Query context over Langwork context.

ignore_context

Controls how contexts passed by argument are handled. By default contexts specified by Langwork may be overwritten by langworks.query.Query or contexts passed by argument. However, when ignore_context is set, Langwork blocks this behaviour, instead maintaining the context as specified by Langwork. When ignore_context is set to True none of the keys specified by Langwork may be overwritten. Alternatively, if a sequence of keys is passed, only the keys specified are protected from overwriting.

middleware

The middleware used to connect to the LLM. If not defined, the framework will try to use any middlewares included in the specifications of individual Query objects.

processes

The number of worker processes to use to operate the Langwork. By default this number is equal to the number of logical CPUs in the system.

connections

Specification of connections in the langwork. See pypework’s documentation for further information.

logger

Logger compatible with Python’s logging module, providing control over the registration of events occuring within the langwork.

ignore_errors

Sequence of errors (and exceptions), which if raised, are ignored by the Pipework, allowing it to continue execution.

nodes

Nodes to embed in the langwork, including ‘Query’ and ‘Langwork’ objects.