langchain_contrib.utils package#
Submodules#
langchain_contrib.utils.contexts module#
Module to change the current directory.
- langchain_contrib.utils.contexts.current_directory(path: str | None = None) Generator#
Change the current directory for the duration of this context.
Restores the current directory back to its original value upon exiting the context, even if more directory changes have been made in the meantime. If no path is provided as input, the current directory will be saved and restored on context exit.
- langchain_contrib.utils.contexts.temporary_file(path: str, check_creation: bool = True) Generator#
Ensure that a temporarily created file will stop existing on exit.
Useful for cleanup after tests. By default, this also checks that the file will have been successfully created during the test.
langchain_contrib.utils.fvalues module#
Module to join F-strings.
- langchain_contrib.utils.fvalues.f_join(joiner: str, substrings: List[str | F]) F#
Join strings together while preserving their original F and non-F status.
This function exists to temporarily provide this functionality pending the merge of oughtinc/fvalues#11
- Args:
joiner: The string to join the substrings with. substrings: The substrings to join. Can be either regular strings or F-strings.
- Returns:
The joined string, with all original parts preserved.
langchain_contrib.utils.llm module#
LLM-related utility functions.
- langchain_contrib.utils.llm.call_llm(llm: BaseLanguageModel, prompt: PromptValue, stop: List[str] | None = None) str#
Invoke the LLM’s __call__ function.
The BaseLanguageModel class does not have that function because the function signatures are slightly different for each child class, but you can readily get a str back all the same.
langchain_contrib.utils.safe module#
Module for safe invocation of langchain models.
- langchain_contrib.utils.safe.safe_inputs(lc_object: Chain | BasePromptTemplate, inputs: Dict[str, T]) Dict[str, T]#
Filter for the subset of inputs that correspond to the given object.
Module contents#
Utility code meant for development rather than agents.
- langchain_contrib.utils.call_llm(llm: BaseLanguageModel, prompt: PromptValue, stop: List[str] | None = None) str#
Invoke the LLM’s __call__ function.
The BaseLanguageModel class does not have that function because the function signatures are slightly different for each child class, but you can readily get a str back all the same.
- langchain_contrib.utils.current_directory(path: str | None = None) Generator#
Change the current directory for the duration of this context.
Restores the current directory back to its original value upon exiting the context, even if more directory changes have been made in the meantime. If no path is provided as input, the current directory will be saved and restored on context exit.
- langchain_contrib.utils.f_join(joiner: str, substrings: List[str | F]) F#
Join strings together while preserving their original F and non-F status.
This function exists to temporarily provide this functionality pending the merge of oughtinc/fvalues#11
- Args:
joiner: The string to join the substrings with. substrings: The substrings to join. Can be either regular strings or F-strings.
- Returns:
The joined string, with all original parts preserved.
- langchain_contrib.utils.safe_inputs(lc_object: Chain | BasePromptTemplate, inputs: Dict[str, T]) Dict[str, T]#
Filter for the subset of inputs that correspond to the given object.
- langchain_contrib.utils.temporary_file(path: str, check_creation: bool = True) Generator#
Ensure that a temporarily created file will stop existing on exit.
Useful for cleanup after tests. By default, this also checks that the file will have been successfully created during the test.