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, clean_multiline: bool | None = None, processes: int | None = None, logger: Logger = None, ignore_errors: Sequence[BaseException] = None, join: bool = False, join_groupby: Sequence[str] = None, join_flatten: bool = False, 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.
- clean_multiline
Flag that controls whether or not
Langwork
appliesclean_multiline()
to the messages of system_msg. Overrides whatever valuelangworks.config.CLEAN_MULTILINE
is set to.Note
This behaviour is only applied to the system messages directly supplied to this instance. Any nested nodes are subject to behaviour as locally configured or prescribed by
langworks.config.CLEAN_MULTILINE
.Added in version 0.2.0.
- 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.
Added in version 0.1.1.
- ignore_errors
Sequence of errors (and exceptions), which if raised, are ignored by the Langwork, allowing it to continue execution.
Added in version 0.1.1.
- join
Whether to join all received data together before processing it.
Analog to pypeworks’ Node.__init__ join argument
Added in version 0.1.2..
- join_groupby
Parameters by which to group the inputs for the other parameters.
Analog to pypeworks’ Node.__init__ join_groupby argument
Added in version 0.1.2..
- join_flatten
Flag that indicates whether any grouped input should be flattened or not.
Analog to pypeworks’ Node.__init__ join_flatten argument
Added in version 0.1.2..
- nodes
Nodes to embed in the langwork, including ‘Query’ and ‘Langwork’ objects.