langdash.chains package#
Submodules#
langdash.chains.chains module#
Classes:
|
Class used to represent language chains |
|
|
|
|
|
Class for storing the results of inference. |
- class langdash.chains.chains.LDChain(ld: Langdash, nodes: List[LDNode | str], args: Dict[str, Callable[[str], Any]] | Type = {}, returns: Dict[str, Callable[[str], Any]] | Type = {})[source]#
Bases:
objectClass used to represent language chains
Methods:
Returns the item view of the argument dictionary.
arg_type(name)Return the type of the argument.
cached(model, **model_kwargs)Cache the chain for a specific model
call(ctx, **kwargs)Returns data generated from the LLM within the specified session.
Returns the item view of the return variable dictionary.
return_type(name)Return the type of the return variable.
stream(ctx, **kwargs)Stream data generated from the LLM within the specified session.
- arg_items() ItemsView[str, Callable[[str], Any]][source]#
Returns the item view of the argument dictionary.
- cached(model: str, **model_kwargs) LDChainCached[source]#
Cache the chain for a specific model
- Parameters:
model (str) – The model name
- Returns:
The cached chain
- call(ctx: str | LLMGenerationSession, **kwargs)[source]#
Returns data generated from the LLM within the specified session.
- Parameters:
ctx (Union[str, "LLMGenerationSession"]) – The name of the model, or an existing LLM generation session.
args (LDNodeArgs) – Arguments to pass to the chain. This will be used by any argument or format nodes.
return_session (bool) – Whether or not to return the generation session after generation.
- Returns:
The result, or a tuple with (result, session).
- return_items() ItemsView[str, Callable[[str], Any]][source]#
Returns the item view of the return variable dictionary.
- stream(ctx: str | LLMGenerationSession, **kwargs) Generator[Response, None, None][source]#
Stream data generated from the LLM within the specified session.
- Parameters:
session (Union[str, "LLMGenerationSession"]) – The name of the model, or an existing LLM generation session.
args (LDNodeArgs) – Arguments to pass to the chain. This will be used by any argument or format nodes.
- Returns:
Generator yielding response events.
- class langdash.chains.chains.LDChainCacheStore(_dict: collections.OrderedDict[FrozenSet[Tuple[str, Any]], langdash.chains.chains._LDChainCacheState], _model: str, _model_kwargs: dict)[source]#
Bases:
object
- class langdash.chains.chains.LDChainCached(model: str, model_kwargs: dict, **kwargs)[source]#
Bases:
LDChainMethods:
call(**kwargs)Returns data generated from the LLM within the specified session.
load_cache_store(cache_store)Loads the cache store from previous inference time.
Saves the cache store into an object.
stream(**kwargs)Stream data generated from the LLM within the specified session.
- call(**kwargs)[source]#
Returns data generated from the LLM within the specified session.
- Parameters:
ctx (Union[str, "LLMGenerationSession"]) – The name of the model, or an existing LLM generation session.
args (LDNodeArgs) – Arguments to pass to the chain. This will be used by any argument or format nodes.
return_session (bool) – Whether or not to return the generation session after generation.
- Returns:
The result, or a tuple with (result, session).
- load_cache_store(cache_store: LDChainCacheStore)[source]#
Loads the cache store from previous inference time.
Warning
This function expects that the model data of the parent Langdash instance does not change across session. If it does, a UserWarning is emitted.
- Parameters:
cache_store (LDChainCacheStore) – The cache store.
- Raises:
ValueError – If the model name of the cache store doesn’t match.
- save_cache_store() LDChainCacheStore[source]#
Saves the cache store into an object.
- stream(**kwargs)[source]#
Stream data generated from the LLM within the specified session.
- Parameters:
session (Union[str, "LLMGenerationSession"]) – The name of the model, or an existing LLM generation session.
args (LDNodeArgs) – Arguments to pass to the chain. This will be used by any argument or format nodes.
- Returns:
Generator yielding response events.
- class langdash.chains.chains.LDResult[source]#
Bases:
objectClass for storing the results of inference.
- returns#
Mapping of return keys to return values
- Type:
Dict[str, Any]
- prompt_tokens#
Number of tokens injected to the language model
- Type:
int
- completion_tokens#
Number of tokens generated by the language model
- Type:
int
langdash.chains.nodes module#
Classes:
|
Argument node |
|
Choice node |
|
Format argument node |
|
Base class for langdash nodes. |
|
Repeat node |
|
Return node |
|
Constant text node |
- class langdash.chains.nodes.LDArg(ld: Langdash, arg: str, padleft: str = '', padright: str = '')[source]#
Bases:
LDNodeArgument node
- class langdash.chains.nodes.LDChoice(ld: Langdash, returns: str, choices: str | List[str], padleft: str = '', padright: str = '', argmax: bool = False, return_idx: bool = False)[source]#
Bases:
LDNodeChoice node
- class langdash.chains.nodes.LDFormatArg(ld: Langdash, text: str)[source]#
Bases:
LDNodeFormat argument node
- class langdash.chains.nodes.LDNode(ld: Langdash)[source]#
Bases:
objectBase class for langdash nodes.
- class langdash.chains.nodes.LDRepeat(ld: Langdash, subchain: LDChain, append_source: str, append_target: str, end: str = '', end_threshold: int = 5, max_len: int = -1)[source]#
Bases:
LDNodeRepeat node
- class langdash.chains.nodes.LDReturns(ld: Langdash, returns: str, end: str | int | SpecialToken | List[str] | List[int] | None, padleft: str = '', infer_args: InferArgs | None = None, end_is_token: bool = False, logit_preprocessors: List[LogitPreprocessor] | None = None, maybe_from_args: bool = False)[source]#
Bases:
LDNodeReturn node
- class langdash.chains.nodes.LDText(ld: Langdash, text: str | int | List[int] | SpecialToken, add_special_tokens: bool = False)[source]#
Bases:
LDNodeConstant text node
langdash.chains.typing module#
Classes:
|
Helper type for mapping string into value. |