Tony20100/langchain_full huggingface dataset:
param requests: Requests [Optional]¶
param return_intermediate_steps: bool = False¶
param tags: Optional[List[str]] = None¶
Optional list of tags associated with the chain. Defaults to None.
These tags will be associated with each call to this chain,
and passed as arguments to the handlers defined in callbacks.
You can use these to eg identify a specific instance of a chain with its use case.
param verbose: bool [Optional]¶
Whether or not run in verbose mode. In verbose mode, some intermediate logs
will be printed to the console. Defaults to the global verbose value,
accessible via langchain.globals.get_verbose().
__call__(inputs: Union[Dict[str, Any], Any], return_only_outputs: bool = False, callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, *, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, run_name: Optional[str] = None, include_run_info: bool = False) → Dict[str, Any]¶
[Deprecated] Execute the chain.
Parameters
inputs (Union[Dict[str, Any], Any]) – Dictionary of inputs, or single input if chain expects
only one param. Should contain all inputs specified in
Chain.input_keys except for inputs that will be set by the chain’s
memory.
return_only_outputs (bool) – Whether to return only outputs in the
response. If True, only new keys generated by this chain will be
returned. If False, both input keys and new keys generated by this
chain will be returned. Defaults to False.
callbacks (Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]]) – Callbacks to use for this chain run. These will be called in
addition to callbacks passed to the chain during construction, but only
these runtime callbacks will propagate to calls to other objects.
update (Optional[DictStrAny]) – values to change/add in the new model. Note: the data is not validated before creating
the new model: you should trust this data
deep (bool) – set to True to make a deep copy of the model
self (Model) – 
Returns
new model instance
Return type
Model
deserialize_json_input(serialized_args: str) → dict[source]¶
Use the serialized typescript dictionary.
Resolve the path, query params dict, and optional requestBody dict.
Parameters
serialized_args (str) – 
Return type
dict
dict(**kwargs: Any) → Dict¶
Dictionary representation of chain.
Expects Chain._chain_type property to be implemented and for memory to benull.
Parameters
**kwargs (Any) – Keyword arguments passed to default pydantic.BaseModel.dict
method.
Returns
A dictionary representation of the chain.
Return type
Dict
Example
chain.dict(exclude_unset=True)
# -> {"_type": "foo", "verbose": False, ...}
classmethod from_api_operation(operation: APIOperation, llm: BaseLanguageModel, requests: Optional[Requests] = None, verbose: bool = False, return_intermediate_steps: bool = False, raw_response: bool = False, callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, **kwargs: Any) → OpenAPIEndpointChain[source]¶
Create an OpenAPIEndpointChain from an operation and a spec.
Parameters
operation (APIOperation) – 
llm (BaseLanguageModel) – 
requests (Optional[Requests]) – 
verbose (bool) – 
return_intermediate_steps (bool) – 
raw_response (bool) – 
callbacks (Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]]) – 
kwargs (Any) – 
Return type
kwargs (Any) – 
Return type
OpenAPIEndpointChain
classmethod from_orm(obj: Any) → Model¶
Parameters
obj (Any) – 
Return type
Model
classmethod from_url_and_method(spec_url: str, path: str, method: str, llm: BaseLanguageModel, requests: Optional[Requests] = None, return_intermediate_steps: bool = False, **kwargs: Any) → OpenAPIEndpointChain[source]¶
Create an OpenAPIEndpoint from a spec at the specified url.
Parameters
spec_url (str) – 
path (str) – 
method (str) – 
llm (BaseLanguageModel) – 
requests (Optional[Requests]) – 
return_intermediate_steps (bool) – 
kwargs (Any) – 
Return type
OpenAPIEndpointChain
get_graph(config: Optional[RunnableConfig] = None) → Graph¶
Return a graph representation of this runnable.
Parameters
config (Optional[RunnableConfig]) – 
Return type
Graph
get_input_schema(config: Optional[RunnableConfig] = None) → Type[BaseModel]¶
Get a pydantic model that can be used to validate input to the runnable.
Runnables that leverage the configurable_fields and configurable_alternatives
methods will have a dynamic input schema that depends on which
configuration the runnable is invoked with.
This method allows to get an input schema for a specific configuration.
Parameters
config (Optional[RunnableConfig]) – A config to use when generating the schema.
Returns
A pydantic model that can be used to validate input.
Return type
Type[BaseModel]
classmethod get_lc_namespace() → List[str]¶
Get the namespace of the langchain object.
For example, if the class is langchain.llms.openai.OpenAI, then the
langchain_google_vertexai.chains.get_output_parser¶
langchain_google_vertexai.chains.get_output_parser(functions: Sequence[Type[BaseModel]]) → Union[BaseOutputParser, BaseGenerationOutputParser][source]¶
Get the appropriate function output parser given the user functions.
Parameters
functions (Sequence[Type[BaseModel]]) – Sequence where element is a dictionary, a pydantic.BaseModel class,
or a Python function. If a dictionary is passed in, it is assumed to
already be a valid OpenAI function.
Returns
A PydanticFunctionsOutputParser
Return type
Union[BaseOutputParser, BaseGenerationOutputParser]
langchain.chains.elasticsearch_database.base.ElasticsearchDatabaseChain¶
class langchain.chains.elasticsearch_database.base.ElasticsearchDatabaseChain[source]¶
Bases: Chain
Chain for interacting with Elasticsearch Database.
Example
from langchain.chains import ElasticsearchDatabaseChain
from langchain_community.llms import OpenAI
from elasticsearch import Elasticsearch
database = Elasticsearch("http://localhost:9200")
db_chain = ElasticsearchDatabaseChain.from_llm(OpenAI(), database)
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 answer_chain: LLMChain [Required]¶
Chain for answering the user question.
param callback_manager: Optional[BaseCallbackManager] = None¶
[DEPRECATED] Use callbacks instead.
param callbacks: Callbacks = None¶
Optional list of callback handlers (or callback manager). Defaults to None.
Callback handlers are called throughout the lifecycle of a call to a chain,
starting with on_chain_start, ending with on_chain_end or on_chain_error.
Each custom chain can optionally call additional callback methods, see Callback docs
for full details.
param database: Any = None¶
Elasticsearch database to connect to of type elasticsearch.Elasticsearch.
param ignore_indices: Optional[List[str]] = None¶
param include_indices: Optional[List[str]] = None¶
param memory: Optional[BaseMemory] = None¶
Optional memory object. Defaults to None.
Memory is a class that gets called at the start
and at the end of every chain. At the start, memory loads variables and passes
them along in the chain. At the end, it saves any returned variables.
There are many different types of memory - please see memory docs
for the full catalog.
param metadata: Optional[Dict[str, Any]] = None¶
for the full catalog.
param metadata: Optional[Dict[str, Any]] = None¶
Optional metadata associated with the chain. Defaults to None.
This metadata will be associated with each call to this chain,
and passed as arguments to the handlers defined in callbacks.
You can use these to eg identify a specific instance of a chain with its use case.
param query_chain: LLMChain [Required]¶
Chain for creating the ES query.
param return_intermediate_steps: bool = False¶
Whether or not to return the intermediate steps along with the final answer.
param sample_documents_in_index_info: int = 3¶
param tags: Optional[List[str]] = None¶
Optional list of tags associated with the chain. Defaults to None.
These tags will be associated with each call to this chain,
and passed as arguments to the handlers defined in callbacks.
You can use these to eg identify a specific instance of a chain with its use case.
param top_k: int = 10¶
Number of results to return from the query
param verbose: bool [Optional]¶
Whether or not run in verbose mode. In verbose mode, some intermediate logs
will be printed to the console. Defaults to the global verbose value,
accessible via langchain.globals.get_verbose().
__call__(inputs: Union[Dict[str, Any], Any], return_only_outputs: bool = False, callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, *, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, run_name: Optional[str] = None, include_run_info: bool = False) → Dict[str, Any]¶
[Deprecated] Execute the chain.
Parameters
inputs (Union[Dict[str, Any], Any]) – Dictionary of inputs, or single input if chain expects
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
the new model: you should trust this data
deep (bool) – set to True to make a deep copy of the model
self (Model) – 
Returns
new model instance
Return type
Model
dict(**kwargs: Any) → Dict¶
Dictionary representation of chain.
Expects Chain._chain_type property to be implemented and for memory to benull.
Parameters
**kwargs (Any) – Keyword arguments passed to default pydantic.BaseModel.dict
method.
Returns
A dictionary representation of the chain.
Return type
Dict
Example
chain.dict(exclude_unset=True)
# -> {"_type": "foo", "verbose": False, ...}
classmethod from_llm(llm: BaseLanguageModel, database: Elasticsearch, *, query_prompt: Optional[BasePromptTemplate] = None, answer_prompt: Optional[BasePromptTemplate] = None, query_output_parser: Optional[BaseLLMOutputParser] = None, **kwargs: Any) → ElasticsearchDatabaseChain[source]¶
Convenience method to construct ElasticsearchDatabaseChain from an LLM.
Parameters
llm (BaseLanguageModel) – The language model to use.
database (Elasticsearch) – The Elasticsearch db.
query_prompt (Optional[BasePromptTemplate]) – The prompt to use for query construction.
answer_prompt (Optional[BasePromptTemplate]) – The prompt to use for answering user question given data.
query_output_parser (Optional[BaseLLMOutputParser]) – The output parser to use for parsing model-generated
ES query. Defaults to SimpleJsonOutputParser.
ES query. Defaults to SimpleJsonOutputParser.
**kwargs (Any) – Additional arguments to pass to the constructor.
Return type
ElasticsearchDatabaseChain
classmethod from_orm(obj: Any) → Model¶
Parameters
obj (Any) – 
Return type
Model
get_graph(config: Optional[RunnableConfig] = None) → Graph¶
Return a graph representation of this runnable.
Parameters
config (Optional[RunnableConfig]) – 
Return type
Graph
get_input_schema(config: Optional[RunnableConfig] = None) → Type[BaseModel]¶
Get a pydantic model that can be used to validate input to the runnable.
Runnables that leverage the configurable_fields and configurable_alternatives
methods will have a dynamic input schema that depends on which
configuration the runnable is invoked with.
This method allows to get an input schema for a specific configuration.
Parameters
config (Optional[RunnableConfig]) – A config to use when generating the schema.
Returns
A pydantic model that can be used to validate input.
Return type
Type[BaseModel]
classmethod get_lc_namespace() → List[str]¶
Get the namespace of the langchain object.
For example, if the class is langchain.llms.openai.OpenAI, then the
namespace is [“langchain”, “llms”, “openai”]
Return type
List[str]
get_name(suffix: Optional[str] = None, *, name: Optional[str] = None) → str¶
Get the name of the runnable.
Parameters
suffix (Optional[str]) – 
name (Optional[str]) – 
Return type
str
get_output_schema(config: Optional[RunnableConfig] = None) → Type[BaseModel]¶
Get a pydantic model that can be used to validate output to the runnable.
langchain.chains.openai_tools.extraction.create_extraction_chain_pydantic¶
langchain.chains.openai_tools.extraction.create_extraction_chain_pydantic(pydantic_schemas: Union[List[Type[BaseModel]], Type[BaseModel]], llm: BaseLanguageModel, system_message: str = 'Extract and save the relevant entities mentioned in the following passage together with their properties.\n\nIf a property is not present and is not required in the function parameters, do not include it in the output.') → Runnable[source]¶
[Deprecated] Creates a chain that extracts information from a passage.
Parameters
pydantic_schemas (Union[List[Type[BaseModel]], Type[BaseModel]]) – The schema of the entities to extract.
llm (BaseLanguageModel) – The language model to use.
system_message (str) – The system message to use for extraction.
Returns
A runnable that extracts information from a passage.
Return type
Runnable
Notes
Deprecated since version 0.1.14: LangChain has introduced a method called with_structured_output thatis available on ChatModels capable of tool calling.You can read more about the method here: https://python.langchain.com/docs/modules/model_io/chat/structured_output/Please follow our extraction use case documentation for more guidelineson how to do information extraction with LLMs.https://python.langchain.com/docs/use_cases/extraction/.with_structured_output does not currently support a list of pydantic schemas. If this is a blocker or if you notice other issues, please provide feedback here:https://github.com/langchain-ai/langchain/discussions/18154 Use
         from langchain_core.pydantic_v1 import BaseModel, Field
         from langchain_anthropic import ChatAnthropic
class Joke(BaseModel):setup: str = Field(description=”The setup of the joke”)
class Joke(BaseModel):setup: str = Field(description=”The setup of the joke”)
punchline: str = Field(description=”The punchline to the joke”)
# Or any other chat model that supports tools.
# Please reference to to the documentation of structured_output
# to see an up to date list of which models support
# with_structured_output.
model = ChatAnthropic(model=”claude-3-opus-20240229”, temperature=0)
structured_llm = model.with_structured_output(Joke)
structured_llm.invoke(“Tell me a joke about cats.
Make sure to call the Joke function.”)
instead.
Examples using create_extraction_chain_pydantic¶
Generate Synthetic Data
langchain_community.chains.graph_qa.ontotext_graphdb.OntotextGraphDBQAChain¶
class langchain_community.chains.graph_qa.ontotext_graphdb.OntotextGraphDBQAChain[source]¶
Bases: Chain
Question-answering against Ontotext GraphDBhttps://graphdb.ontotext.com/ by generating SPARQL queries.
Security note: Make sure that the database connection uses credentialsthat are narrowly-scoped to only include necessary permissions.
Failure to do so may result in data corruption or loss, since the calling
code may attempt commands that would result in deletion, mutation
of data if appropriately prompted or reading sensitive data if such
data is present in the database.
The best way to guard against such negative outcomes is to (as appropriate)
limit the permissions granted to the credentials used with this tool.
See https://python.langchain.com/docs/security for more information.
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 callback_manager: Optional[BaseCallbackManager] = None¶
[DEPRECATED] Use callbacks instead.
param callbacks: Callbacks = None¶
Optional list of callback handlers (or callback manager). Defaults to None.
Callback handlers are called throughout the lifecycle of a call to a chain,
starting with on_chain_start, ending with on_chain_end or on_chain_error.
Each custom chain can optionally call additional callback methods, see Callback docs
for full details.
param graph: OntotextGraphDBGraph [Required]¶
param max_fix_retries: int [Required]¶
param memory: Optional[BaseMemory] = None¶
Optional memory object. Defaults to None.
Memory is a class that gets called at the start
Optional memory object. Defaults to None.
Memory is a class that gets called at the start
and at the end of every chain. At the start, memory loads variables and passes
them along in the chain. At the end, it saves any returned variables.
There are many different types of memory - please see memory docs
for the full catalog.
param metadata: Optional[Dict[str, Any]] = None¶
Optional metadata associated with the chain. Defaults to None.
This metadata will be associated with each call to this chain,
and passed as arguments to the handlers defined in callbacks.
You can use these to eg identify a specific instance of a chain with its use case.
param qa_chain: LLMChain [Required]¶
param sparql_fix_chain: LLMChain [Required]¶
param sparql_generation_chain: LLMChain [Required]¶
param tags: Optional[List[str]] = None¶
Optional list of tags associated with the chain. Defaults to None.
These tags will be associated with each call to this chain,
and passed as arguments to the handlers defined in callbacks.
You can use these to eg identify a specific instance of a chain with its use case.
param verbose: bool [Optional]¶
Whether or not run in verbose mode. In verbose mode, some intermediate logs
will be printed to the console. Defaults to the global verbose value,
accessible via langchain.globals.get_verbose().
__call__(inputs: Union[Dict[str, Any], Any], return_only_outputs: bool = False, callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, *, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, run_name: Optional[str] = None, include_run_info: bool = False) → Dict[str, Any]¶
[Deprecated] Execute the chain.
Parameters
classmethod from_llm(llm: BaseLanguageModel, *, sparql_generation_prompt: BasePromptTemplate = PromptTemplate(input_variables=['prompt', 'schema'], template='\nWrite a SPARQL SELECT query for querying a graph database.\nThe ontology schema delimited by triple backticks in Turtle format is:\n```\n{schema}\n```\nUse only the classes and properties provided in the schema to construct the SPARQL query.\nDo not use any classes or properties that are not explicitly provided in the SPARQL query.\nInclude all necessary prefixes.\nDo not include any explanations or apologies in your responses.\nDo not wrap the query in backticks.\nDo not include any text except the SPARQL query generated.\nThe question delimited by triple backticks is:\n```\n{prompt}\n```\n'), sparql_fix_prompt: BasePromptTemplate = PromptTemplate(input_variables=['error_message', 'generated_sparql', 'schema'], template='\nThis following SPARQL query delimited by triple backticks\n```\n{generated_sparql}\n```\nis not valid.\nThe error delimited by triple backticks is\n```\n{error_message}\n```\nGive me a correct version of the SPARQL query.\nDo not change the logic of the query.\nDo not include any explanations or apologies in your responses.\nDo not wrap the query in backticks.\nDo not include any text except the SPARQL query generated.\nThe ontology schema delimited by triple backticks in Turtle format is:\n```\n{schema}\n```\n'), max_fix_retries: int = 5, qa_prompt: BasePromptTemplate = PromptTemplate(input_variables=['context', 'prompt'], template="Task: Generate a natural language response from the results of a SPARQL query.\nYou are an assistant that creates well-written and human understandable answers.\nThe information part contains the information
are an assistant that creates well-written and human understandable answers.\nThe information part contains the information provided, which you can use to construct an answer.\nThe information provided is authoritative, you must never doubt it or try to use your internal knowledge to correct it.\nMake your response sound like the information is coming from an AI assistant, but don't add any information.\nDon't use internal knowledge to answer the question, just say you don't know if no information is available.\nInformation:\n{context}\n\nQuestion: {prompt}\nHelpful Answer:"), **kwargs: Any) → OntotextGraphDBQAChain[source]¶
Initialize from LLM.
Parameters
llm (BaseLanguageModel) – 
sparql_generation_prompt (BasePromptTemplate) – 
sparql_fix_prompt (BasePromptTemplate) – 
max_fix_retries (int) – 
qa_prompt (BasePromptTemplate) – 
kwargs (Any) – 
Return type
OntotextGraphDBQAChain
classmethod from_orm(obj: Any) → Model¶
Parameters
obj (Any) – 
Return type
Model
get_graph(config: Optional[RunnableConfig] = None) → Graph¶
Return a graph representation of this runnable.
Parameters
config (Optional[RunnableConfig]) – 
Return type
Graph
get_input_schema(config: Optional[RunnableConfig] = None) → Type[BaseModel]¶
Get a pydantic model that can be used to validate input to the runnable.
Runnables that leverage the configurable_fields and configurable_alternatives
methods will have a dynamic input schema that depends on which
configuration the runnable is invoked with.
This method allows to get an input schema for a specific configuration.
Parameters
config (Optional[RunnableConfig]) – A config to use when generating the schema.
Returns
A pydantic model that can be used to validate input.
Return type
Type[BaseModel]
classmethod get_lc_namespace() → List[str]¶
Get the namespace of the langchain object.
For example, if the class is langchain.llms.openai.OpenAI, then the
namespace is [“langchain”, “llms”, “openai”]
Return type
List[str]
get_name(suffix: Optional[str] = None, *, name: Optional[str] = None) → str¶
Get the name of the runnable.
Parameters
suffix (Optional[str]) – 
name (Optional[str]) – 
Return type
str
Return type
Runnable[Input, Output]
with_types(*, input_type: Optional[Type[Input]] = None, output_type: Optional[Type[Output]] = None) → Runnable[Input, Output]¶
Bind input and output types to a Runnable, returning a new Runnable.
Parameters
input_type (Optional[Type[Input]]) – 
output_type (Optional[Type[Output]]) – 
Return type
Runnable[Input, Output]
property InputType: Type[Input]¶
The type of input this runnable accepts specified as a type annotation.
property OutputType: Type[Output]¶
The type of output this runnable produces specified as a type annotation.
property config_specs: List[ConfigurableFieldSpec]¶
List configurable fields for this runnable.
property input_keys: List[str]¶
Keys expected to be in the chain input.
property input_schema: Type[BaseModel]¶
The type of input this runnable accepts specified as a pydantic model.
property lc_attributes: Dict¶
List of attribute names that should be included in the serialized kwargs.
These attributes must be accepted by the constructor.
property lc_secrets: Dict[str, str]¶
A map of constructor argument names to secret ids.
For example,{“openai_api_key”: “OPENAI_API_KEY”}
name: Optional[str] = None¶
The name of the runnable. Used for debugging and tracing.
property output_keys: List[str]¶
Keys expected to be in the chain output.
property output_schema: Type[BaseModel]¶
The type of output this runnable produces specified as a pydantic model.
Examples using OntotextGraphDBQAChain¶
Ontotext GraphDB
langchain.chains.openai_functions.tagging.create_tagging_chain¶
langchain.chains.openai_functions.tagging.create_tagging_chain(schema: dict, llm: BaseLanguageModel, prompt: Optional[ChatPromptTemplate] = None, **kwargs: Any) → Chain[source]¶
Create a chain that extracts information from a passagebased on a schema.
Parameters
schema (dict) – The schema of the entities to extract.
llm (BaseLanguageModel) – The language model to use.
prompt (Optional[ChatPromptTemplate]) – 
kwargs (Any) – 
Returns
Chain (LLMChain) that can be used to extract information from a passage.
Return type
Chain
Examples using create_tagging_chain¶
ChatLlamaAPI