langtree.core¶
Submodules¶
Package Contents¶
Classes¶
A class to represent a buffer with a fixed length. |
|
A class to represent and process custom call and parse operations. |
|
A class to represent and process prompt templates. |
|
Helper class that provides a standard way to create an ABC using |
Functions¶
|
Default call function that returns the provided keyword arguments. |
|
Default parse function that returns the provided output without modifications. |
|
Return a function with specific arguments frozen. |
|
Render a template string by substituting placeholders with provided keyword arguments. |
- class langtree.core.Buffer(length)[source]¶
A class to represent a buffer with a fixed length.
This buffer allows appending and extending its content while ensuring it never exceeds its defined length. If the buffer’s content exceeds its length, items are removed from the beginning.
- property memory¶
Provide access to the buffer’s memory.
- Returns:
The buffer’s memory content.
- Return type:
list
- append(item)[source]¶
Append an item to the buffer and ensure the buffer does not exceed its length.
- Parameters:
item – The item to append.
- extend(item_list)[source]¶
Extend the buffer with a list of items and ensure the buffer does not exceed its length.
- Parameters:
item_list (list) – The list of items to extend the buffer with.
- _shrink()[source]¶
Private method to shrink the buffer to its defined length by removing items from the beginning.
- __add__(item)[source]¶
Handle addition operations with the buffer. Allows for adding a single item or a list of items.
- Parameters:
item – An item or a list of items to add.
- Returns:
The updated buffer.
- Return type:
- langtree.core.default_call(*args, **kwargs)[source]¶
Default call function that returns the provided keyword arguments.
- Parameters:
*args – Variable length argument list.
**kwargs – Arbitrary keyword arguments.
- Returns:
The provided keyword arguments.
- Return type:
dict
- langtree.core.default_parse(output)[source]¶
Default parse function that returns the provided output without modifications.
- Parameters:
output – The output to parse.
- Returns:
The unmodified output.
- langtree.core.freeze(function, **top_kwargs)[source]¶
Return a function with specific arguments frozen.
- Parameters:
function (callable) – The function to freeze arguments for.
**top_kwargs – Keyword arguments to freeze.
- Returns:
The function with specific arguments frozen.
- Return type:
callable
- class langtree.core.Operator(call=default_call, parse=default_parse)[source]¶
Bases:
objectA class to represent and process custom call and parse operations.
- __call__(*args, **kwargs)[source]¶
Call the Operator’s call function and parse its result.
- Parameters:
*args – Variable length argument list.
**kwargs – Arbitrary keyword arguments.
- Returns:
The parsed result of the call function.
- langtree.core.render_prompt(template, **kwargs)[source]¶
Render a template string by substituting placeholders with provided keyword arguments.
- Parameters:
template (str) – The template string containing placeholders.
**kwargs – Keyword arguments representing placeholder-value pairs.
- Returns:
The rendered string after substitutions.
- Return type:
str
- class langtree.core.Prompt(template)[source]¶
A class to represent and process prompt templates.
- __call__(**kwargs)[source]¶
Render the prompt using the provided keyword arguments.
- Parameters:
**kwargs – Keyword arguments for rendering the prompt.
- Returns:
The rendered prompt.
- Return type:
str
- class langtree.core.VectorDatabase[source]¶
Bases:
abc.ABCHelper class that provides a standard way to create an ABC using inheritance.
- abstract insert(vector: List[float], metadata: Any, **kwargs) None[source]¶
Insert a vector into the database with optional metadata and additional parameters.
- Parameters:
vector (List[float]) – The vector to be inserted.
metadata (Any) – Optional metadata associated with the vector.
**kwargs – Additional parameters for insertion.
- abstract query(vector: List[float], top_k: int, **kwargs) List[Any][source]¶
Query the database for the ‘top_k’ closest vectors to the provided vector.
Returns a list of matched vectors’ metadata. Accepts additional parameters.
- Parameters:
vector (List[float]) – The vector used for querying.
top_k (int) – Number of closest vectors to return.
**kwargs – Additional parameters for querying.
- Returns:
List of matched vectors’ metadata.
- Return type:
List[Any]
- __getattr__(name)[source]¶
Override Python’s default behavior when an attribute isn’t found.
This can be used to ‘forward’ method calls to the underlying database object.
- Parameters:
name (str) – The name of the attribute.
- Returns:
The method from the underlying database object.
- Return type:
callable