Tony20100/langchain_full huggingface dataset:
langchain_community.document_compressors.openvino_rerank.OpenVINOReranker¶
class langchain_community.document_compressors.openvino_rerank.OpenVINOReranker[source]¶
Bases: BaseDocumentCompressor
OpenVINO rerank models.
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
param model_kwargs: Dict[str, Any] [Optional]¶
Keyword arguments passed to the model.
param model_name_or_path: str [Required]¶
HuggingFace model id.
param ov_model: Any = None¶
OpenVINO model object.
param tokenizer: Any = None¶
Tokenizer for embedding model.
param top_n: int = 4¶
return Top n texts.
async acompress_documents(documents: Sequence[Document], query: str, callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None) → Sequence[Document]¶
Compress retrieved documents given the query context.
Parameters
documents (Sequence[Document]) – 
query (str) – 
callbacks (Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]]) – 
Return type
Sequence[Document]
compress_documents(documents: Sequence[Document], query: str, callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None) → Sequence[Document][source]¶
Compress retrieved documents given the query context.
Parameters
documents (Sequence[Document]) – 
query (str) – 
callbacks (Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]]) – 
Return type
Sequence[Document]
classmethod construct(_fields_set: Optional[SetStr] = None, **values: Any) → Model¶
dumps_kwargs (Any) – 
Return type
unicode
classmethod parse_file(path: Union[str, Path], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶
Parameters
path (Union[str, Path]) – 
content_type (unicode) – 
encoding (unicode) – 
proto (Protocol) – 
allow_pickle (bool) – 
Return type
Model
classmethod parse_obj(obj: Any) → Model¶
Parameters
obj (Any) – 
Return type
Model
classmethod parse_raw(b: Union[str, bytes], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶
Parameters
b (Union[str, bytes]) – 
content_type (unicode) – 
encoding (unicode) – 
proto (Protocol) – 
allow_pickle (bool) – 
Return type
Model
rerank(request: Any) → Any[source]¶
Parameters
request (Any) – 
Return type
Any
save_model(model_path: str) → bool[source]¶
Parameters
model_path (str) – 
Return type
bool
classmethod schema(by_alias: bool = True, ref_template: unicode = '#/definitions/{model}') → DictStrAny¶
Parameters
by_alias (bool) – 
ref_template (unicode) – 
Return type
DictStrAny
classmethod schema_json(*, by_alias: bool = True, ref_template: unicode = '#/definitions/{model}', **dumps_kwargs: Any) → unicode¶
Parameters
by_alias (bool) – 
ref_template (unicode) – 
dumps_kwargs (Any) – 
Return type
unicode
dumps_kwargs (Any) – 
Return type
unicode
classmethod update_forward_refs(**localns: Any) → None¶
Try to update ForwardRefs on fields based on this Model, globalns and localns.
Parameters
localns (Any) – 
Return type
None
classmethod validate(value: Any) → Model¶
Parameters
value (Any) – 
Return type
Model
Examples using OpenVINOReranker¶
OpenVINO Reranker
langchain_ai21.ai21_base.AI21Base¶
class langchain_ai21.ai21_base.AI21Base[source]¶
Bases: BaseModel
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
param api_host: Optional[str] = None¶
param api_key: Optional[SecretStr] = None¶
Constraints
type = string
writeOnly = True
format = password
param num_retries: Optional[int] = None¶
param timeout_sec: Optional[float] = None¶
classmethod construct(_fields_set: Optional[SetStr] = None, **values: Any) → Model¶
Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data.
Default values are respected, but no other validation is performed.
Behaves as if Config.extra = ‘allow’ was set since it adds all passed values
Parameters
_fields_set (Optional[SetStr]) – 
values (Any) – 
Return type
Model
copy(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, update: Optional[DictStrAny] = None, deep: bool = False) → Model¶
Duplicate a model, optionally choose which fields to include, exclude and change.
Parameters
include (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – fields to include in new model
exclude (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – fields to exclude from new model, as with values this takes precedence over include
update (Optional[DictStrAny]) – values to change/add in the new model. Note: the data is not validated before creating
langchain_cohere.react_multi_hop.parsing.parse_answer_with_prefixes¶
langchain_cohere.react_multi_hop.parsing.parse_answer_with_prefixes(completion: str, prefixes: Dict[str, str]) → Dict[str, str][source]¶
parses string into key-value pairs,
according to patterns supplied in prefixes. Also strips.
if inputs are:completion = “
hello: sam
goodbye then: paul.”,
prefixes = {“greeting”: “hello:”, “farewell”: “goodbye then:”}
the expected returned result is:{“greeting”: “sam”, “farewell”: “paul.”}
Args:completion (str): text to split
prefixes (Dict[str, str]): a key-value dict of keys and patterns.
See example above
Returns:Dict[str, str]: parsed result
Parameters
completion (str) – 
prefixes (Dict[str, str]) – 
Return type
Dict[str, str]
langchain_cohere.react_multi_hop.parsing.parse_citations¶
langchain_cohere.react_multi_hop.parsing.parse_citations(grounded_answer: str, documents: List[MutableMapping]) → Tuple[str, List[CohereCitation]][source]¶
Parses a grounded_generation (from parse_actions) and documents (from
convert_to_documents) into a (generation, CohereCitation list) tuple.
Parameters
grounded_answer (str) – 
documents (List[MutableMapping]) – 
Return type
Tuple[str, List[CohereCitation]]
langchain_cohere.react_multi_hop.prompt.create_directly_answer_tool¶
langchain_cohere.react_multi_hop.prompt.create_directly_answer_tool() → BaseTool[source]¶
directly_answer is a special tool that’s always presented to the model as an
available tool. The model only ever invokes this whilst answering and no AgentAction
is produced, so it only needs to be added to the prompt.
Return type
BaseTool
langchain_cohere.react_multi_hop.prompt.render_intermediate_steps¶
langchain_cohere.react_multi_hop.prompt.render_intermediate_steps(intermediate_steps: List[Tuple[AgentAction, Any]]) → str[source]¶
Renders an agent’s intermediate steps into prompt content.
Parameters
intermediate_steps (List[Tuple[AgentAction, Any]]) – 
Return type
str
langchain_cohere.react_multi_hop.prompt.render_observations¶
langchain_cohere.react_multi_hop.prompt.render_observations(observations: Union[List[Mapping[str, str]], List[str], Mapping[str, str], str], index: int) → Tuple[BaseMessage, int][source]¶
Renders the ‘output’ part of an Agent’s intermediate step into prompt content.
Parameters
observations (Union[List[Mapping[str, str]], List[str], Mapping[str, str], str]) – 
index (int) – 
Return type
Tuple[BaseMessage, int]
langchain_cohere.react_multi_hop.agent.create_cohere_react_agent¶
langchain_cohere.react_multi_hop.agent.create_cohere_react_agent(llm: BaseLanguageModel, tools: Sequence[BaseTool], prompt: ChatPromptTemplate) → Runnable[source]¶
Create an agent that enables multiple tools to be used in sequence to complete
a task.
Parameters
llm (BaseLanguageModel) – The ChatCohere LLM instance to use.
tools (Sequence[BaseTool]) – Tools this agent has access to.
prompt (ChatPromptTemplate) – The prompt to use.
Returns
A Runnable sequence representing an agent. It takes as input all the same input
variables as the prompt passed in does and returns a List[AgentAction] or a
single AgentFinish.
The AgentFinish will have two fields:
* output: str - The output string generated by the model
* citations: List[CohereCitation] - A list of citations that refer to the
output and observations made by the agent. If there are no citations this
list will be empty.
Return type
Runnable
Example
. code-block:: pythonfrom langchain.agents import AgentExecutor
from langchain.prompts import ChatPromptTemplate
from langchain_cohere import ChatCohere, create_cohere_react_agent
prompt = ChatPromptTemplate.from_template(“{input}”)
tools = []  # Populate this with a list of tools you would like to use.
llm = ChatCohere()
agent = create_cohere_react_agent(llm,
tools,
prompt
)
agent_executor = AgentExecutor(agent=agent, tools=tools)
agent_executor.invoke({“input”: “In what year was the company that was founded as Sound of Music added to the S&P 500?”,
})
langchain_cohere.react_multi_hop.parsing.CohereToolsReactAgentOutputParser¶
class langchain_cohere.react_multi_hop.parsing.CohereToolsReactAgentOutputParser[source]¶
Bases: BaseOutputParser[Union[List[AgentAction], AgentFinish]]
Parses a message into agent actions/finish.
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
async abatch(inputs: List[Input], config: Optional[Union[RunnableConfig, List[RunnableConfig]]] = None, *, return_exceptions: bool = False, **kwargs: Optional[Any]) → List[Output]¶
Default implementation runs ainvoke in parallel using asyncio.gather.
The default implementation of batch works well for IO bound runnables.
Subclasses should override this method if they can batch more efficiently;
e.g., if the underlying runnable uses an API which supports a batch mode.
Parameters
inputs (List[Input]) – 
config (Optional[Union[RunnableConfig, List[RunnableConfig]]]) – 
return_exceptions (bool) – 
kwargs (Optional[Any]) – 
Return type
List[Output]
async abatch_as_completed(inputs: Sequence[Input], config: Optional[Union[RunnableConfig, Sequence[RunnableConfig]]] = None, *, return_exceptions: bool = False, **kwargs: Optional[Any]) → AsyncIterator[Tuple[int, Union[Output, Exception]]]¶
Run ainvoke in parallel on a list of inputs,
yielding results as they complete.
Parameters
inputs (Sequence[Input]) – 
config (Optional[Union[RunnableConfig, Sequence[RunnableConfig]]]) – 
return_exceptions (bool) – 
kwargs (Optional[Any]) – 
Return type
return_exceptions (bool) – 
kwargs (Optional[Any]) – 
Return type
AsyncIterator[Tuple[int, Union[Output, Exception]]]
async ainvoke(input: Union[str, BaseMessage], config: Optional[RunnableConfig] = None, **kwargs: Optional[Any]) → T¶
Default implementation of ainvoke, calls invoke from a thread.
The default implementation allows usage of async code even if
the runnable did not implement a native async version of invoke.
Subclasses should override this method if they can run asynchronously.
Parameters
input (Union[str, BaseMessage]) – 
config (Optional[RunnableConfig]) – 
kwargs (Optional[Any]) – 
Return type
T
async aparse(text: str) → T¶
Parse a single string model output into some structure.
Parameters
text (str) – String output of a language model.
Returns
Structured output.
Return type
T
async aparse_result(result: List[Generation], *, partial: bool = False) → T¶
Parse a list of candidate model Generations into a specific format.
The return value is parsed from only the first Generation in the result, whichis assumed to be the highest-likelihood Generation.
Parameters
result (List[Generation]) – A list of Generations to be parsed. The Generations are assumed
to be different candidate outputs for a single model input.
partial (bool) – 
Returns
Structured output.
Return type
T
assign(**kwargs: Union[Runnable[Dict[str, Any], Any], Callable[[Dict[str, Any]], Any], Mapping[str, Union[Runnable[Dict[str, Any], Any], Callable[[Dict[str, Any]], Any]]]]) → RunnableSerializable[Any, Any]¶
Assigns new fields to the dict output of this runnable.
Returns a new runnable.
def _lambda(x: int) -> int:
    return x + 1
runnable = RunnableLambda(_lambda)
print(runnable.map().invoke([1, 2, 3])) # [2, 3, 4]
Return type
Runnable[List[Input], List[Output]]
parse(text: str) → Union[List[AgentAction], AgentFinish][source]¶
Parse a single string model output into some structure.
Parameters
text (str) – String output of a language model.
Returns
Structured output.
Return type
Union[List[AgentAction], AgentFinish]
classmethod parse_file(path: Union[str, Path], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶
Parameters
path (Union[str, Path]) – 
content_type (unicode) – 
encoding (unicode) – 
proto (Protocol) – 
allow_pickle (bool) – 
Return type
Model
classmethod parse_obj(obj: Any) → Model¶
Parameters
obj (Any) – 
Return type
Model
classmethod parse_raw(b: Union[str, bytes], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶
Parameters
b (Union[str, bytes]) – 
content_type (unicode) – 
encoding (unicode) – 
proto (Protocol) – 
allow_pickle (bool) – 
Return type
Model
parse_result(result: List[Generation], *, partial: bool = False) → T¶
Parse a list of candidate model Generations into a specific format.
The return value is parsed from only the first Generation in the result, whichis assumed to be the highest-likelihood Generation.
Parameters
Parameters
result (List[Generation]) – A list of Generations to be parsed. The Generations are assumed
to be different candidate outputs for a single model input.
partial (bool) – 
Returns
Structured output.
Return type
T
parse_with_prompt(completion: str, prompt: PromptValue) → Any¶
Parse the output of an LLM call with the input prompt for context.
The prompt is largely provided in the event the OutputParser wants
to retry or fix the output in some way, and needs information from
the prompt to do so.
Parameters
completion (str) – String output of a language model.
prompt (PromptValue) – Input PromptValue.
Returns
Structured output
Return type
Any
pick(keys: Union[str, List[str]]) → RunnableSerializable[Any, Any]¶
Pick keys from the dict output of this runnable.
Pick single key:import json
from langchain_core.runnables import RunnableLambda, RunnableMap
as_str = RunnableLambda(str)
as_json = RunnableLambda(json.loads)
chain = RunnableMap(str=as_str, json=as_json)
chain.invoke("[1, 2, 3]")
# -> {"str": "[1, 2, 3]", "json": [1, 2, 3]}
json_only_chain = chain.pick("json")
json_only_chain.invoke("[1, 2, 3]")
# -> [1, 2, 3]
Pick list of keys:from typing import Any
import json
from langchain_core.runnables import RunnableLambda, RunnableMap
as_str = RunnableLambda(str)
as_json = RunnableLambda(json.loads)
def as_bytes(x: Any) -> bytes:
    return bytes(x, "utf-8")
chain = RunnableMap(
    str=as_str,
    json=as_json,
await sequence.abatch([1, 2, 3])
# -> [4, 6, 8]
Parameters
others (Union[Runnable[Any, Other], Callable[[Any], Other]]) – 
name (Optional[str]) – 
Return type
RunnableSerializable[Input, Other]
classmethod schema(by_alias: bool = True, ref_template: unicode = '#/definitions/{model}') → DictStrAny¶
Parameters
by_alias (bool) – 
ref_template (unicode) – 
Return type
DictStrAny
classmethod schema_json(*, by_alias: bool = True, ref_template: unicode = '#/definitions/{model}', **dumps_kwargs: Any) → unicode¶
Parameters
by_alias (bool) – 
ref_template (unicode) – 
dumps_kwargs (Any) – 
Return type
unicode
stream(input: Input, config: Optional[RunnableConfig] = None, **kwargs: Optional[Any]) → Iterator[Output]¶
Default implementation of stream, which calls invoke.
Subclasses should override this method if they support streaming output.
Parameters
input (Input) – 
config (Optional[RunnableConfig]) – 
kwargs (Optional[Any]) – 
Return type
Iterator[Output]
to_json() → Union[SerializedConstructor, SerializedNotImplemented]¶
Serialize the runnable to JSON.
Return type
Union[SerializedConstructor, SerializedNotImplemented]
to_json_not_implemented() → SerializedNotImplemented¶
Return type
SerializedNotImplemented
transform(input: Iterator[Input], config: Optional[RunnableConfig] = None, **kwargs: Optional[Any]) → Iterator[Output]¶
Default implementation of transform, which buffers input and then calls stream.
Subclasses should override this method if they can start producing output while
input is still being generated.
Parameters
input (Iterator[Input]) –
langchain_cohere.react_multi_hop.prompt.multi_hop_prompt¶
langchain_cohere.react_multi_hop.prompt.multi_hop_prompt(tools: Sequence[BaseTool], prompt: ChatPromptTemplate) → Callable[[Dict], BasePromptTemplate][source]¶
The returned function produces a BasePromptTemplate suitable for multi-hop.
Parameters
tools (Sequence[BaseTool]) – 
prompt (ChatPromptTemplate) – 
Return type
Callable[[Dict], BasePromptTemplate]
langchain_cohere.react_multi_hop.prompt.render_type¶
langchain_cohere.react_multi_hop.prompt.render_type(type_: str, is_optional: bool) → str[source]¶
Renders a tool’s type into prompt content. Types should be Python types, but JSON
schema is allowed and converted.
Parameters
type_ (str) – 
is_optional (bool) – 
Return type
str
langchain_cohere.react_multi_hop.parsing.parse_jsonified_tool_use_generation¶
langchain_cohere.react_multi_hop.parsing.parse_jsonified_tool_use_generation(tool_use_generation: str, tool_use_prefix: str) → List[Dict][source]¶
Parses model-generated jsonified actions.
Expects input of the form
“{tool_use_prefix}: ```json
[{list of jsonified objects}]```”
outputs parsed list of jsonified objects.
Parameters
tool_use_generation (str) – 
tool_use_prefix (str) – 
Return type
List[Dict]
langchain_experimental.prompt_injection_identifier.hugging_face_identifier.HuggingFaceInjectionIdentifier¶
class langchain_experimental.prompt_injection_identifier.hugging_face_identifier.HuggingFaceInjectionIdentifier[source]¶
Bases: BaseTool
Tool that uses HuggingFace Prompt Injection model to
detect prompt injection attacks.
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
param args_schema: Optional[Type[BaseModel]] = None¶
Pydantic model class to validate and parse the tool’s input arguments.
param callback_manager: Optional[BaseCallbackManager] = None¶
Deprecated. Please use callbacks instead.
param callbacks: Callbacks = None¶
Callbacks to be called during tool execution.
param description: str = 'A wrapper around HuggingFace Prompt Injection security model. Useful for when you need to ensure that prompt is free of injection attacks. Input should be any message from the user.'¶
Used to tell the model how/when/why to use the tool.
You can provide few-shot examples as a part of the description.
param handle_tool_error: Optional[Union[bool, str, Callable[[ToolException], str]]] = False¶
Handle the content of the ToolException thrown.
param handle_validation_error: Optional[Union[bool, str, Callable[[ValidationError], str]]] = False¶
Handle the content of the ValidationError thrown.
param injection_label: str = 'INJECTION'¶
Label for prompt injection detection model.
Defaults to INJECTION. Value depends on the model used.
Label of the injection for prompt injection detection.
param metadata: Optional[Dict[str, Any]] = None¶
Optional metadata associated with the tool. Defaults to None
This metadata will be associated with each call to this tool,
and passed as arguments to the handlers defined in callbacks.
and passed as arguments to the handlers defined in callbacks.
You can use these to eg identify a specific instance of a tool with its use case.
param model: Union[Pipeline, str, None] [Optional]¶
Model to use for prompt injection detection.
Can be specified as transformers Pipeline or string. String should correspond to themodel name of a text-classification transformers model. Defaults to
protectai/deberta-v3-base-prompt-injection-v2 model.
param return_direct: bool = False¶
Whether to return the tool’s output directly. Setting this to True means
that after the tool is called, the AgentExecutor will stop looping.
param tags: Optional[List[str]] = None¶
Optional list of tags associated with the tool. Defaults to None
These tags will be associated with each call to this tool,
and passed as arguments to the handlers defined in callbacks.
You can use these to eg identify a specific instance of a tool with its use case.
param threshold: float = 0.5¶
Threshold for prompt injection detection.
Defaults to 0.5.
Threshold for prompt injection detection.
param verbose: bool = False¶
Whether to log the tool’s progress.
__call__(tool_input: str, callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None) → str¶
[Deprecated] Make tool callable.
Notes
Deprecated since version langchain-core==0.1.47: Use invoke instead.
Parameters
tool_input (str) – 
callbacks (Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]]) – 
Return type
str
async abatch(inputs: List[Input], config: Optional[Union[RunnableConfig, List[RunnableConfig]]] = None, *, return_exceptions: bool = False, **kwargs: Optional[Any]) → List[Output]¶
langchain_experimental.prompt_injection_identifier.hugging_face_identifier.PromptInjectionException¶
class langchain_experimental.prompt_injection_identifier.hugging_face_identifier.PromptInjectionException(message: str = 'Prompt injection attack detected', score: float = 1.0)[source]¶
Exception raised when prompt injection attack is detected.
Parameters
message (str) – 
score (float) –
langchain_upstage.layout_analysis_parsers.get_from_param_or_env¶
langchain_upstage.layout_analysis_parsers.get_from_param_or_env(key: str, param: Optional[str] = None, env_key: Optional[str] = None, default: Optional[str] = None) → str[source]¶
Get a value from a param or an environment variable.
Parameters
key (str) – 
param (Optional[str]) – 
env_key (Optional[str]) – 
default (Optional[str]) – 
Return type
str
langchain_upstage.layout_analysis_parsers.validate_file_path¶
langchain_upstage.layout_analysis_parsers.validate_file_path(file_path: str) → None[source]¶
Validates if a file exists at the given file path.
Parameters
file_path (str) – The path to the file.
Raises
FileNotFoundError – If the file does not exist at the given file path.
Return type
None
langchain_upstage.layout_analysis_parsers.parse_output¶
langchain_upstage.layout_analysis_parsers.parse_output(data: dict, output_type: Union[Literal['text', 'html'], dict]) → str[source]¶
Parse the output data based on the specified output type.
Parameters
data (dict) – The data to be parsed.
output_type (Union[OutputType, dict]) – The output type to parse the element data
into.
Returns
The parsed output.
Return type
str
Raises
ValueError – If the output type is invalid.
langchain_upstage.layout_analysis_parsers.validate_api_key¶
langchain_upstage.layout_analysis_parsers.validate_api_key(api_key: str) → None[source]¶
Validates the provided API key.
Parameters
api_key (str) – The API key to be validated.
Raises
ValueError – If the API key is empty or None.
Returns
None
Return type
None