utils
#
Utility functions for LangChain.
These functions do not depend on any other LangChain module.
Classes
Dummy lock that provides the proper interface but no protection. |
|
|
Create |
|
Async context manager for safely finalizing an asynchronously cleaned-up resource such as an async generator, calling its |
alias of |
|
Formatter that checks for extra keys. |
|
Representation of a callable function to send to an LLM. |
|
Representation of a callable function to the OpenAI API. |
|
Dummy lock that provides the proper interface but no protection. |
|
|
Create |
alias of |
|
Custom exception for Chevron errors. |
Functions
|
Utility batching function for async iterables. |
|
Pure-Python implementation of anext() for testing purposes. |
|
An individual iterator of a |
|
Check if an environment variable is set. |
|
Get a value from a dictionary or an environment variable. |
|
Get a value from a dictionary or an environment variable. |
Convert a raw function/class to an OpenAI function. :param function: A dictionary, Pydantic BaseModel class, TypedDict class, a LangChain Tool object, or a Python function. If a dictionary is passed in, it is assumed to already be a valid OpenAI function, a JSON schema with top-level 'title' key specified, an Anthropic format tool, or an Amazon Bedrock Converse format tool. :param strict: If True, model output is guaranteed to exactly match the JSON Schema provided in the function definition. If None, |
|
Convert a tool-like object to an OpenAI tool schema. |
|
|
Extract all links from a raw HTML string and convert into absolute paths. |
|
Extract all links from a raw HTML string. |
Get bolded text. |
|
|
Get mapping for items to a support color. |
|
Get colored text. |
|
Print text with highlighting and no end characters. |
Determine if running within IPython or Jupyter. |
|
|
Utility batching function. |
|
An individual iterator of a |
Parse a JSON string from a Markdown string and check that it contains the expected keys. |
|
|
Parse a JSON string from a Markdown string. |
|
Parse a JSON string that may be missing closing braces. |
|
Try to substitute $refs in JSON Schema. |
|
Parse a literal from the template. |
|
Do a preliminary check to see if a tag could be a standalone. |
|
Parse a tag from a template. |
|
Do a final check to see if a tag could be a standalone. |
|
Render a mustache template. |
|
Tokenize a mustache template. |
|
Create a pydantic model with the given field definitions. |
|
Create a pydantic model with the given field definitions. |
Get the field names of a Pydantic model. |
|
Get the major version of Pydantic. |
|
Check if the given class is an instance of Pydantic BaseModel. |
|
Check if the given class is a subclass of Pydantic BaseModel. |
|
Check if the installed Pydantic version is 1.x-like. |
|
Check if the installed Pydantic version is 1.x-like. |
|
|
Decorator to run a function before model initialization. |
|
Convert a list to a comma-separated string. |
Stringify a dictionary. |
|
Stringify a value. |
|
|
Build extra kwargs from values and extra_kwargs. |
|
Check the version of a package. |
Convert a string to a SecretStr if needed. |
|
Create a factory method that gets a value from an environment variable. |
|
Get field names, including aliases, for a pydantic class. |
|
|
Dynamically import a module and raise an exception if the module is not installed. |
|
Context manager for mocking out datetime.now() in unit tests. |
|
Raise an error with the response text. |
Secret from env. |
|
|
Validate specified keyword args are mutually exclusive." |
Deprecated functions