id
stringlengths
14
15
text
stringlengths
44
2.47k
source
stringlengths
61
181
7271edb1045c-0
langchain.storage.exceptions.InvalidKeyException¶ class langchain.storage.exceptions.InvalidKeyException[source]¶ Raised when a key is invalid; e.g., uses incorrect characters.
https://api.python.langchain.com/en/latest/storage/langchain.storage.exceptions.InvalidKeyException.html
2e49d50ebdf3-0
langchain.storage.in_memory.InMemoryStore¶ class langchain.storage.in_memory.InMemoryStore[source]¶ In-memory implementation of the BaseStore using a dictionary. store¶ The underlying dictionary that stores the key-value pairs. Type Dict[str, Any] Examples from langchain.storage import InMemoryStore store = InMemorySto...
https://api.python.langchain.com/en/latest/storage/langchain.storage.in_memory.InMemoryStore.html
2e49d50ebdf3-1
Set the values for the given keys. Parameters key_value_pairs (Sequence[Tuple[str, V]]) – A sequence of key-value pairs. Returns None yield_keys(prefix: Optional[str] = None) → Iterator[str][source]¶ Get an iterator over keys that match the given prefix. Parameters prefix (str, optional) – The prefix to match. Defaults...
https://api.python.langchain.com/en/latest/storage/langchain.storage.in_memory.InMemoryStore.html
2b4282f35a7a-0
langchain.storage.encoder_backed.EncoderBackedStore¶ class langchain.storage.encoder_backed.EncoderBackedStore(store: BaseStore[str, Any], key_encoder: Callable[[K], str], value_serializer: Callable[[V], bytes], value_deserializer: Callable[[Any], V])[source]¶ Wraps a store with key and value encoders/decoders. Example...
https://api.python.langchain.com/en/latest/storage/langchain.storage.encoder_backed.EncoderBackedStore.html
2b4282f35a7a-1
yield_keys(*[, prefix]) Get an iterator over keys that match the given prefix. __init__(store: BaseStore[str, Any], key_encoder: Callable[[K], str], value_serializer: Callable[[V], bytes], value_deserializer: Callable[[Any], V]) → None[source]¶ Initialize an EncodedStore. mdelete(keys: Sequence[K]) → None[source]¶ Dele...
https://api.python.langchain.com/en/latest/storage/langchain.storage.encoder_backed.EncoderBackedStore.html
635e254b4763-0
langchain.storage.redis.RedisStore¶ class langchain.storage.redis.RedisStore(*, client: Any = None, redis_url: Optional[str] = None, client_kwargs: Optional[dict] = None, ttl: Optional[int] = None, namespace: Optional[str] = None)[source]¶ BaseStore implementation using Redis as the underlying store. Examples Create a ...
https://api.python.langchain.com/en/latest/storage/langchain.storage.redis.RedisStore.html
635e254b4763-1
yield_keys(*[, prefix]) Yield keys in the store. __init__(*, client: Any = None, redis_url: Optional[str] = None, client_kwargs: Optional[dict] = None, ttl: Optional[int] = None, namespace: Optional[str] = None) → None[source]¶ Initialize the RedisStore with a Redis connection. Must provide either a Redis client or a r...
https://api.python.langchain.com/en/latest/storage/langchain.storage.redis.RedisStore.html
e7fe948551cf-0
langchain.storage.file_system.LocalFileStore¶ class langchain.storage.file_system.LocalFileStore(root_path: Union[str, Path])[source]¶ BaseStore interface that works on the local file system. Examples Create a LocalFileStore instance and perform operations on it: from langchain.storage import LocalFileStore # Instantia...
https://api.python.langchain.com/en/latest/storage/langchain.storage.file_system.LocalFileStore.html
e7fe948551cf-1
Delete the given keys and their associated values. Parameters keys (Sequence[str]) – A sequence of keys to delete. Returns None mget(keys: Sequence[str]) → List[Optional[bytes]][source]¶ Get the values associated with the given keys. Parameters keys – A sequence of keys. Returns A sequence of optional values associated...
https://api.python.langchain.com/en/latest/storage/langchain.storage.file_system.LocalFileStore.html
514d60cfa03c-0
langchain_experimental.data_anonymizer.deanonymizer_mapping.DeanonymizerMapping¶ class langchain_experimental.data_anonymizer.deanonymizer_mapping.DeanonymizerMapping(mapping: Dict[str, Dict[str, str]] = <factory>)[source]¶ Attributes data Return the deanonymizer mapping mapping Methods __init__([mapping]) update(new_m...
https://api.python.langchain.com/en/latest/data_anonymizer/langchain_experimental.data_anonymizer.deanonymizer_mapping.DeanonymizerMapping.html
9ebf6937d824-0
langchain_experimental.data_anonymizer.faker_presidio_mapping.get_pseudoanonymizer_mapping¶ langchain_experimental.data_anonymizer.faker_presidio_mapping.get_pseudoanonymizer_mapping(seed: Optional[int] = None) → Dict[str, Callable][source]¶
https://api.python.langchain.com/en/latest/data_anonymizer/langchain_experimental.data_anonymizer.faker_presidio_mapping.get_pseudoanonymizer_mapping.html
c4278481015b-0
langchain_experimental.data_anonymizer.base.ReversibleAnonymizerBase¶ class langchain_experimental.data_anonymizer.base.ReversibleAnonymizerBase[source]¶ Base abstract class for reversible anonymizers. Methods __init__() anonymize(text[, language]) Anonymize text deanonymize(text) Deanonymize text __init__()¶ anonymize...
https://api.python.langchain.com/en/latest/data_anonymizer/langchain_experimental.data_anonymizer.base.ReversibleAnonymizerBase.html
b42847b2a3a3-0
langchain_experimental.data_anonymizer.base.AnonymizerBase¶ class langchain_experimental.data_anonymizer.base.AnonymizerBase[source]¶ Base abstract class for anonymizers. It is public and non-virtual because it allows wrapping the behavior for all methods in a base class. Methods __init__() anonymize(text[, language]) ...
https://api.python.langchain.com/en/latest/data_anonymizer/langchain_experimental.data_anonymizer.base.AnonymizerBase.html
1f337796c783-0
langchain.agents.format_scratchpad.xml.format_xml¶ langchain.agents.format_scratchpad.xml.format_xml(intermediate_steps: List[Tuple[AgentAction, str]]) → str[source]¶
https://api.python.langchain.com/en/latest/agents.format_scratchpad/langchain.agents.format_scratchpad.xml.format_xml.html
ee4bda468c91-0
langchain.agents.format_scratchpad.openai_functions.format_to_openai_functions¶ langchain.agents.format_scratchpad.openai_functions.format_to_openai_functions(intermediate_steps: Sequence[Tuple[AgentAction, str]]) → List[BaseMessage][source]¶ Format intermediate steps. :param intermediate_steps: Steps the LLM has taken...
https://api.python.langchain.com/en/latest/agents.format_scratchpad/langchain.agents.format_scratchpad.openai_functions.format_to_openai_functions.html
86e07fb20a95-0
langchain.agents.format_scratchpad.log_to_messages.format_log_to_messages¶ langchain.agents.format_scratchpad.log_to_messages.format_log_to_messages(intermediate_steps: List[Tuple[AgentAction, str]], template_tool_response: str = '{observation}') → List[BaseMessage][source]¶ Construct the scratchpad that lets the agent...
https://api.python.langchain.com/en/latest/agents.format_scratchpad/langchain.agents.format_scratchpad.log_to_messages.format_log_to_messages.html
cc797f6c5b0f-0
langchain.agents.format_scratchpad.log.format_log_to_str¶ langchain.agents.format_scratchpad.log.format_log_to_str(intermediate_steps: List[Tuple[AgentAction, str]], observation_prefix: str = 'Observation: ', llm_prefix: str = 'Thought: ') → str[source]¶ Construct the scratchpad that lets the agent continue its thought...
https://api.python.langchain.com/en/latest/agents.format_scratchpad/langchain.agents.format_scratchpad.log.format_log_to_str.html
5cbdcf24676e-0
langchain.prompts.pipeline.PipelinePromptTemplate¶ class langchain.prompts.pipeline.PipelinePromptTemplate[source]¶ Bases: BasePromptTemplate A prompt template for composing multiple prompt templates together. This can be useful when you want to reuse parts of prompts. A PipelinePrompt consists of two main parts: final...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.pipeline.PipelinePromptTemplate.html
5cbdcf24676e-1
Subclasses should override this method if they can batch more efficiently. async ainvoke(input: Input, config: Optional[RunnableConfig] = None, **kwargs: Any) → Output¶ Default implementation of ainvoke, which calls invoke in a thread pool. Subclasses should override this method if they can run asynchronously. async as...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.pipeline.PipelinePromptTemplate.html
5cbdcf24676e-2
input is still being generated. batch(inputs: List[Input], config: Optional[Union[RunnableConfig, List[RunnableConfig]]] = None, *, return_exceptions: bool = False, **kwargs: Optional[Any]) → List[Output]¶ Default implementation of batch, which calls invoke N times. Subclasses should override this method if they can ba...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.pipeline.PipelinePromptTemplate.html
5cbdcf24676e-3
kwargs – Any arguments to be passed to the prompt template. Returns A formatted string. Example: prompt.format(variable1="foo") format_prompt(**kwargs: Any) → PromptValue[source]¶ Create Chat Messages. classmethod from_orm(obj: Any) → Model¶ classmethod get_lc_namespace() → List[str]¶ Get the namespace of the langchain...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.pipeline.PipelinePromptTemplate.html
5cbdcf24676e-4
by calling invoke() with each input. classmethod parse_file(path: Union[str, Path], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶ classmethod parse_obj(obj: Any) → Model¶ classmethod parse_raw(b: Union[str, bytes], *, content_type: unicode = No...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.pipeline.PipelinePromptTemplate.html
5cbdcf24676e-5
input is still being generated. classmethod update_forward_refs(**localns: Any) → None¶ Try to update ForwardRefs on fields based on this Model, globalns and localns. classmethod validate(value: Any) → Model¶ with_config(config: Optional[RunnableConfig] = None, **kwargs: Any) → Runnable[Input, Output]¶ Bind config to a...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.pipeline.PipelinePromptTemplate.html
22f50f7347ee-0
langchain.prompts.few_shot.FewShotPromptTemplate¶ class langchain.prompts.few_shot.FewShotPromptTemplate[source]¶ Bases: _FewShotPromptTemplateMixin, StringPromptTemplate Prompt template that contains few shot examples. Create a new model by parsing and validating input data from keyword arguments. Raises ValidationErr...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.few_shot.FewShotPromptTemplate.html
22f50f7347ee-1
param validate_template: bool = True¶ Whether or not to try validating the template. async abatch(inputs: List[Input], config: Optional[Union[RunnableConfig, List[RunnableConfig]]] = None, *, return_exceptions: bool = False, **kwargs: Optional[Any]) → List[Output]¶ Default implementation of abatch, which calls ainvoke ...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.few_shot.FewShotPromptTemplate.html
22f50f7347ee-2
The jsonpatch ops can be applied in order to construct state. async atransform(input: AsyncIterator[Input], config: Optional[RunnableConfig] = None, **kwargs: Optional[Any]) → AsyncIterator[Output]¶ Default implementation of atransform, which buffers input and calls astream. Subclasses should override this method if th...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.few_shot.FewShotPromptTemplate.html
22f50f7347ee-3
the new model: you should trust this data deep – set to True to make a deep copy of the model Returns new model instance dict(**kwargs: Any) → Dict[source]¶ Return a dictionary of the prompt. format(**kwargs: Any) → str[source]¶ Format the prompt with the inputs. Parameters **kwargs – Any arguments to be passed to the ...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.few_shot.FewShotPromptTemplate.html
22f50f7347ee-4
classmethod lc_id() → List[str]¶ A unique identifier for this class for serialization purposes. The unique identifier is a list of strings that describes the path to the object. map() → Runnable[List[Input], List[Output]]¶ Return a new Runnable that maps a list of inputs to a list of outputs, by calling invoke() with e...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.few_shot.FewShotPromptTemplate.html
22f50f7347ee-5
to_json_not_implemented() → 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...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.few_shot.FewShotPromptTemplate.html
22f50f7347ee-6
A map of constructor argument names to secret ids. For example,{“openai_api_key”: “OPENAI_API_KEY”} property output_schema: Type[pydantic.main.BaseModel]¶ Examples using FewShotPromptTemplate¶ Select by maximal marginal relevance (MMR) Select by n-gram overlap
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.few_shot.FewShotPromptTemplate.html
137000f934a0-0
langchain.prompts.chat.MessagesPlaceholder¶ class langchain.prompts.chat.MessagesPlaceholder[source]¶ Bases: BaseMessagePromptTemplate Prompt template that assumes variable is already list of messages. Create a new model by parsing and validating input data from keyword arguments. Raises ValidationError if the input da...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.MessagesPlaceholder.html
137000f934a0-1
deep – set to True to make a deep copy of the model Returns new model instance dict(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, ex...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.MessagesPlaceholder.html
137000f934a0-2
Generate a JSON representation of the model, include and exclude arguments as per dict(). encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps(). classmethod lc_id() → List[str]¶ A unique identifier for this class for serialization purposes. The unique identifier is a ...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.MessagesPlaceholder.html
137000f934a0-3
A map of constructor argument names to secret ids. For example,{“openai_api_key”: “OPENAI_API_KEY”} Examples using MessagesPlaceholder¶ Set env var OPENAI_API_KEY or load from a .env file: Conversational Retrieval Agent Agents Memory in LLMChain Add Memory to OpenAI Functions Agent Types of `MessagePromptTemplate` Addi...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.MessagesPlaceholder.html
d4416108cdeb-0
langchain.prompts.example_selector.semantic_similarity.MaxMarginalRelevanceExampleSelector¶ class langchain.prompts.example_selector.semantic_similarity.MaxMarginalRelevanceExampleSelector[source]¶ Bases: SemanticSimilarityExampleSelector ExampleSelector that selects examples based on Max Marginal Relevance. This was s...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.example_selector.semantic_similarity.MaxMarginalRelevanceExampleSelector.html
d4416108cdeb-1
Duplicate a model, optionally choose which fields to include, exclude and change. Parameters include – fields to include in new model exclude – fields to exclude from new model, as with values this takes precedence over include update – values to change/add in the new model. Note: the data is not validated before creat...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.example_selector.semantic_similarity.MaxMarginalRelevanceExampleSelector.html
d4416108cdeb-2
Returns The ExampleSelector instantiated, backed by a vector store. classmethod from_orm(obj: Any) → Model¶ json(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, ex...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.example_selector.semantic_similarity.MaxMarginalRelevanceExampleSelector.html
d4416108cdeb-3
Try to update ForwardRefs on fields based on this Model, globalns and localns. classmethod validate(value: Any) → Model¶ Examples using MaxMarginalRelevanceExampleSelector¶ Select by maximal marginal relevance (MMR)
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.example_selector.semantic_similarity.MaxMarginalRelevanceExampleSelector.html
677e495f6ca1-0
langchain.prompts.chat.HumanMessagePromptTemplate¶ class langchain.prompts.chat.HumanMessagePromptTemplate[source]¶ Bases: BaseStringMessagePromptTemplate Human message prompt template. This is a message sent from the user. Create a new model by parsing and validating input data from keyword arguments. Raises Validatio...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.HumanMessagePromptTemplate.html
677e495f6ca1-1
deep – set to True to make a deep copy of the model Returns new model instance dict(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, ex...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.HumanMessagePromptTemplate.html
677e495f6ca1-2
Get the namespace of the langchain object. For example, if the class is langchain.llms.openai.OpenAI, then the namespace is [“langchain”, “llms”, “openai”] classmethod is_lc_serializable() → bool¶ Return whether or not the class is serializable. json(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = No...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.HumanMessagePromptTemplate.html
677e495f6ca1-3
classmethod schema_json(*, by_alias: bool = True, ref_template: unicode = '#/definitions/{model}', **dumps_kwargs: Any) → unicode¶ to_json() → Union[SerializedConstructor, SerializedNotImplemented]¶ to_json_not_implemented() → SerializedNotImplemented¶ classmethod update_forward_refs(**localns: Any) → None¶ Try to upda...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.HumanMessagePromptTemplate.html
dd3d8ce318f0-0
langchain.prompts.example_selector.ngram_overlap.ngram_overlap_score¶ langchain.prompts.example_selector.ngram_overlap.ngram_overlap_score(source: List[str], example: List[str]) → float[source]¶ Compute ngram overlap score of source and example as sentence_bleu score. Use sentence_bleu with method1 smoothing function a...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.example_selector.ngram_overlap.ngram_overlap_score.html
b58c446bef41-0
langchain.prompts.example_selector.semantic_similarity.sorted_values¶ langchain.prompts.example_selector.semantic_similarity.sorted_values(values: Dict[str, str]) → List[Any][source]¶ Return a list of values in dict sorted by key.
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.example_selector.semantic_similarity.sorted_values.html
6dd2e9371aa7-0
langchain.prompts.base.StringPromptTemplate¶ class langchain.prompts.base.StringPromptTemplate[source]¶ Bases: BasePromptTemplate, ABC String prompt that exposes the format method, returning a prompt. Create a new model by parsing and validating input data from keyword arguments. Raises ValidationError if the input dat...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.base.StringPromptTemplate.html
6dd2e9371aa7-1
Subclasses should override this method if they support streaming output. async astream_log(input: Any, config: Optional[RunnableConfig] = None, *, include_names: Optional[Sequence[str]] = None, include_types: Optional[Sequence[str]] = None, include_tags: Optional[Sequence[str]] = None, exclude_names: Optional[Sequence[...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.base.StringPromptTemplate.html
6dd2e9371aa7-2
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 copy(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclu...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.base.StringPromptTemplate.html
6dd2e9371aa7-3
classmethod is_lc_serializable() → bool¶ Return whether this class is serializable. json(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = Fals...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.base.StringPromptTemplate.html
6dd2e9371aa7-4
Save the prompt. Parameters file_path – Path to directory to save prompt to. Example: .. code-block:: python prompt.save(file_path=”path/prompt.yaml”) classmethod schema(by_alias: bool = True, ref_template: unicode = '#/definitions/{model}') → DictStrAny¶ classmethod schema_json(*, by_alias: bool = True, ref_template: ...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.base.StringPromptTemplate.html
6dd2e9371aa7-5
Bind config to a Runnable, returning a new Runnable. with_fallbacks(fallbacks: ~typing.Sequence[~langchain.schema.runnable.base.Runnable[~langchain.schema.runnable.utils.Input, ~langchain.schema.runnable.utils.Output]], *, exceptions_to_handle: ~typing.Tuple[~typing.Type[BaseException], ...] = (<class 'Exception'>,)) →...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.base.StringPromptTemplate.html
f75ae5246571-0
langchain.prompts.example_selector.ngram_overlap.NGramOverlapExampleSelector¶ class langchain.prompts.example_selector.ngram_overlap.NGramOverlapExampleSelector[source]¶ Bases: BaseExampleSelector, BaseModel Select and order examples based on ngram overlap score (sentence_bleu score). https://www.nltk.org/_modules/nltk...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.example_selector.ngram_overlap.NGramOverlapExampleSelector.html
f75ae5246571-1
Behaves as if Config.extra = ‘allow’ was set since it adds all passed values 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...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.example_selector.ngram_overlap.NGramOverlapExampleSelector.html
f75ae5246571-2
classmethod from_orm(obj: Any) → Model¶ json(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_n...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.example_selector.ngram_overlap.NGramOverlapExampleSelector.html
f75ae5246571-3
classmethod update_forward_refs(**localns: Any) → None¶ Try to update ForwardRefs on fields based on this Model, globalns and localns. classmethod validate(value: Any) → Model¶ Examples using NGramOverlapExampleSelector¶ Select by n-gram overlap
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.example_selector.ngram_overlap.NGramOverlapExampleSelector.html
9654fbfce9bb-0
langchain.prompts.base.validate_jinja2¶ langchain.prompts.base.validate_jinja2(template: str, input_variables: List[str]) → None[source]¶ Validate that the input variables are valid for the template. Issues a warning if missing or extra variables are found. Parameters template – The template string. input_variables – T...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.base.validate_jinja2.html
5c308883a34d-0
langchain.prompts.example_selector.length_based.LengthBasedExampleSelector¶ class langchain.prompts.example_selector.length_based.LengthBasedExampleSelector[source]¶ Bases: BaseExampleSelector, BaseModel Select examples based on length. Create a new model by parsing and validating input data from keyword arguments. Rai...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.example_selector.length_based.LengthBasedExampleSelector.html
5c308883a34d-1
exclude – fields to exclude from new model, as with values this takes precedence over include update – 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 – set to True to make a deep copy of the model Returns new model instance dict(*, i...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.example_selector.length_based.LengthBasedExampleSelector.html
5c308883a34d-2
classmethod parse_obj(obj: Any) → Model¶ classmethod parse_raw(b: Union[str, bytes], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶ classmethod schema(by_alias: bool = True, ref_template: unicode = '#/definitions/{model}') → DictStrAny¶ classmet...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.example_selector.length_based.LengthBasedExampleSelector.html
bbc0d0ed0f6c-0
langchain.prompts.chat.ChatPromptValue¶ class langchain.prompts.chat.ChatPromptValue[source]¶ Bases: PromptValue Chat prompt value. A type of a prompt value that is built from messages. Create a new model by parsing and validating input data from keyword arguments. Raises ValidationError if the input data cannot be par...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.ChatPromptValue.html
bbc0d0ed0f6c-1
deep – set to True to make a deep copy of the model Returns new model instance dict(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, ex...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.ChatPromptValue.html
bbc0d0ed0f6c-2
The unique identifier is a list of strings that describes the path to the object. classmethod parse_file(path: Union[str, Path], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶ classmethod parse_obj(obj: Any) → Model¶ classmethod parse_raw(b: Uni...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.ChatPromptValue.html
499c7922b887-0
langchain.prompts.few_shot_with_templates.FewShotPromptWithTemplates¶ class langchain.prompts.few_shot_with_templates.FewShotPromptWithTemplates[source]¶ Bases: StringPromptTemplate Prompt template that contains few shot examples. Create a new model by parsing and validating input data from keyword arguments. Raises Va...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.few_shot_with_templates.FewShotPromptWithTemplates.html
499c7922b887-1
param validate_template: bool = True¶ Whether or not to try validating the template. async abatch(inputs: List[Input], config: Optional[Union[RunnableConfig, List[RunnableConfig]]] = None, *, return_exceptions: bool = False, **kwargs: Optional[Any]) → List[Output]¶ Default implementation of abatch, which calls ainvoke ...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.few_shot_with_templates.FewShotPromptWithTemplates.html
499c7922b887-2
The jsonpatch ops can be applied in order to construct state. async atransform(input: AsyncIterator[Input], config: Optional[RunnableConfig] = None, **kwargs: Optional[Any]) → AsyncIterator[Output]¶ Default implementation of atransform, which buffers input and calls astream. Subclasses should override this method if th...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.few_shot_with_templates.FewShotPromptWithTemplates.html
499c7922b887-3
the new model: you should trust this data deep – set to True to make a deep copy of the model Returns new model instance dict(**kwargs: Any) → Dict[source]¶ Return a dictionary of the prompt. format(**kwargs: Any) → str[source]¶ Format the prompt with the inputs. Parameters kwargs – Any arguments to be passed to the pr...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.few_shot_with_templates.FewShotPromptWithTemplates.html
499c7922b887-4
classmethod lc_id() → List[str]¶ A unique identifier for this class for serialization purposes. The unique identifier is a list of strings that describes the path to the object. map() → Runnable[List[Input], List[Output]]¶ Return a new Runnable that maps a list of inputs to a list of outputs, by calling invoke() with e...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.few_shot_with_templates.FewShotPromptWithTemplates.html
499c7922b887-5
to_json_not_implemented() → 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...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.few_shot_with_templates.FewShotPromptWithTemplates.html
499c7922b887-6
A map of constructor argument names to secret ids. For example,{“openai_api_key”: “OPENAI_API_KEY”} property output_schema: Type[pydantic.main.BaseModel]¶
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.few_shot_with_templates.FewShotPromptWithTemplates.html
d3129c4883f8-0
langchain.prompts.chat.SystemMessagePromptTemplate¶ class langchain.prompts.chat.SystemMessagePromptTemplate[source]¶ Bases: BaseStringMessagePromptTemplate System message prompt template. This is a message that is not sent to the user. Create a new model by parsing and validating input data from keyword arguments. Rai...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.SystemMessagePromptTemplate.html
d3129c4883f8-1
deep – set to True to make a deep copy of the model Returns new model instance dict(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, ex...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.SystemMessagePromptTemplate.html
d3129c4883f8-2
Get the namespace of the langchain object. For example, if the class is langchain.llms.openai.OpenAI, then the namespace is [“langchain”, “llms”, “openai”] classmethod is_lc_serializable() → bool¶ Return whether or not the class is serializable. json(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = No...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.SystemMessagePromptTemplate.html
d3129c4883f8-3
classmethod schema_json(*, by_alias: bool = True, ref_template: unicode = '#/definitions/{model}', **dumps_kwargs: Any) → unicode¶ to_json() → Union[SerializedConstructor, SerializedNotImplemented]¶ to_json_not_implemented() → SerializedNotImplemented¶ classmethod update_forward_refs(**localns: Any) → None¶ Try to upda...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.SystemMessagePromptTemplate.html
5ee5adb5bbac-0
langchain.prompts.example_selector.semantic_similarity.SemanticSimilarityExampleSelector¶ class langchain.prompts.example_selector.semantic_similarity.SemanticSimilarityExampleSelector[source]¶ Bases: BaseExampleSelector, BaseModel Example selector that selects examples based on SemanticSimilarity. Create a new model b...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.example_selector.semantic_similarity.SemanticSimilarityExampleSelector.html
5ee5adb5bbac-1
exclude – fields to exclude from new model, as with values this takes precedence over include update – 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 – set to True to make a deep copy of the model Returns new model instance dict(*, i...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.example_selector.semantic_similarity.SemanticSimilarityExampleSelector.html
5ee5adb5bbac-2
classmethod from_orm(obj: Any) → Model¶ json(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_n...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.example_selector.semantic_similarity.SemanticSimilarityExampleSelector.html
5ee5adb5bbac-3
classmethod validate(value: Any) → Model¶ Examples using SemanticSimilarityExampleSelector¶ Select by maximal marginal relevance (MMR) Few-shot examples for chat models
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.example_selector.semantic_similarity.SemanticSimilarityExampleSelector.html
811670faeaad-0
langchain.prompts.base.check_valid_template¶ langchain.prompts.base.check_valid_template(template: str, template_format: str, input_variables: List[str]) → None[source]¶ Check that template string is valid.
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.base.check_valid_template.html
ea984763b08b-0
langchain.prompts.chat.BaseMessagePromptTemplate¶ class langchain.prompts.chat.BaseMessagePromptTemplate[source]¶ Bases: Serializable, ABC Base class for message prompt templates. Create a new model by parsing and validating input data from keyword arguments. Raises ValidationError if the input data cannot be parsed to...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.BaseMessagePromptTemplate.html
ea984763b08b-1
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude. abstract format_messages(**kwargs: Any) → List[BaseMessage][source]¶ Format messages from kwargs. Should return a list of BaseMessages. Parameters **kwargs – Keyword arguments to use for formatting. Returns List...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.BaseMessagePromptTemplate.html
ea984763b08b-2
classmethod parse_obj(obj: Any) → Model¶ classmethod parse_raw(b: Union[str, bytes], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶ classmethod schema(by_alias: bool = True, ref_template: unicode = '#/definitions/{model}') → DictStrAny¶ classmet...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.BaseMessagePromptTemplate.html
edb17fa3c817-0
langchain.prompts.chat.AIMessagePromptTemplate¶ class langchain.prompts.chat.AIMessagePromptTemplate[source]¶ Bases: BaseStringMessagePromptTemplate AI message prompt template. This is a message sent from the AI. Create a new model by parsing and validating input data from keyword arguments. Raises ValidationError if t...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.AIMessagePromptTemplate.html
edb17fa3c817-1
deep – set to True to make a deep copy of the model Returns new model instance dict(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, ex...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.AIMessagePromptTemplate.html
edb17fa3c817-2
Get the namespace of the langchain object. For example, if the class is langchain.llms.openai.OpenAI, then the namespace is [“langchain”, “llms”, “openai”] classmethod is_lc_serializable() → bool¶ Return whether or not the class is serializable. json(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = No...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.AIMessagePromptTemplate.html
edb17fa3c817-3
classmethod schema_json(*, by_alias: bool = True, ref_template: unicode = '#/definitions/{model}', **dumps_kwargs: Any) → unicode¶ to_json() → Union[SerializedConstructor, SerializedNotImplemented]¶ to_json_not_implemented() → SerializedNotImplemented¶ classmethod update_forward_refs(**localns: Any) → None¶ Try to upda...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.AIMessagePromptTemplate.html
184034559e5f-0
langchain.prompts.chat.ChatPromptTemplate¶ class langchain.prompts.chat.ChatPromptTemplate[source]¶ Bases: BaseChatPromptTemplate A prompt template for chat models. Use to create flexible templated prompts for chat models. Examples from langchain.prompts import ChatPromptTemplate template = ChatPromptTemplate.from_mess...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.ChatPromptTemplate.html
184034559e5f-1
Default implementation of ainvoke, which calls invoke in a thread pool. Subclasses should override this method if they can run asynchronously. append(message: Union[BaseMessagePromptTemplate, BaseMessage, BaseChatPromptTemplate, Tuple[str, str], Tuple[Type, str], str]) → None[source]¶ Append message to the end of the c...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.ChatPromptTemplate.html
184034559e5f-2
Subclasses should override this method if they can start producing output while input is still being generated. batch(inputs: List[Input], config: Optional[Union[RunnableConfig, List[RunnableConfig]]] = None, *, return_exceptions: bool = False, **kwargs: Optional[Any]) → List[Output]¶ Default implementation of batch, w...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.ChatPromptTemplate.html
184034559e5f-3
dict(**kwargs: Any) → Dict¶ Return dictionary representation of prompt. extend(messages: Sequence[Union[BaseMessagePromptTemplate, BaseMessage, BaseChatPromptTemplate, Tuple[str, str], Tuple[Type, str], str]]) → None[source]¶ Extend the chat template with a sequence of messages. format(**kwargs: Any) → str[source]¶ For...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.ChatPromptTemplate.html
184034559e5f-4
messages – sequence of message representations. A message can be represented using the following formats: (1) BaseMessagePromptTemplate, (2) BaseMessage, (3) 2-tuple of (message type, template); e.g., (“human”, “{user_input}”), (4) 2-tuple of (message class, template), (4) a string which is shorthand for (“human”, temp...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.ChatPromptTemplate.html
184034559e5f-5
classmethod from_template(template: str, **kwargs: Any) → ChatPromptTemplate[source]¶ Create a chat prompt template from a template string. Creates a chat template consisting of a single message assumed to be from the human. Parameters template – template string **kwargs – keyword arguments to pass to the constructor. ...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.ChatPromptTemplate.html
184034559e5f-6
Return a new Runnable that maps a list of inputs to a list of outputs, by calling invoke() with each input. classmethod parse_file(path: Union[str, Path], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶ classmethod parse_obj(obj: Any) → Model¶ cl...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.ChatPromptTemplate.html
184034559e5f-7
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. to_json() → Union[SerializedConstructor, SerializedNotImplemented]¶ to_json_not_implem...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.ChatPromptTemplate.html
184034559e5f-8
property input_schema: type[pydantic.main.BaseModel]¶ property lc_attributes: Dict¶ Return a 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...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.chat.ChatPromptTemplate.html
9a40bdfced75-0
langchain.prompts.prompt.Prompt¶ langchain.prompts.prompt.Prompt¶ alias of PromptTemplate
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.prompt.Prompt.html
e4f83056ff6d-0
langchain.prompts.example_selector.base.BaseExampleSelector¶ class langchain.prompts.example_selector.base.BaseExampleSelector[source]¶ Interface for selecting examples to include in prompts. Methods __init__() add_example(example) Add new example to store for a key. select_examples(input_variables) Select which exampl...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.example_selector.base.BaseExampleSelector.html
41f25dc1fdc2-0
langchain.prompts.few_shot.FewShotChatMessagePromptTemplate¶ class langchain.prompts.few_shot.FewShotChatMessagePromptTemplate[source]¶ Bases: BaseChatPromptTemplate, _FewShotPromptTemplateMixin Chat prompt template that supports few-shot examples. The high level structure of produced by this prompt template is a list ...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.few_shot.FewShotChatMessagePromptTemplate.html
41f25dc1fdc2-1
Prompt template with dynamically selected examples: from langchain.prompts import SemanticSimilarityExampleSelector from langchain.embeddings import OpenAIEmbeddings from langchain.vectorstores import Chroma examples = [ {"input": "2+2", "output": "4"}, {"input": "2+3", "output": "5"}, {"input": "2+4", "out...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.few_shot.FewShotChatMessagePromptTemplate.html
41f25dc1fdc2-2
print(final_prompt.format_messages(input="What's 3+3?")) # Use within an LLM from langchain.chat_models import ChatAnthropic chain = final_prompt | ChatAnthropic() chain.invoke({"input": "What's 3+3?"}) Create a new model by parsing and validating input data from keyword arguments. Raises ValidationError if the input d...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.few_shot.FewShotChatMessagePromptTemplate.html
41f25dc1fdc2-3
Default implementation of ainvoke, which calls invoke in a thread pool. Subclasses should override this method if they can run asynchronously. async astream(input: Input, config: Optional[RunnableConfig] = None, **kwargs: Optional[Any]) → AsyncIterator[Output]¶ Default implementation of astream, which calls ainvoke. Su...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.few_shot.FewShotChatMessagePromptTemplate.html
41f25dc1fdc2-4
Default implementation of batch, which calls invoke N times. Subclasses should override this method if they can batch more efficiently. bind(**kwargs: Any) → Runnable[Input, Output]¶ Bind arguments to a Runnable, returning a new Runnable. classmethod construct(_fields_set: Optional[SetStr] = None, **values: Any) → Mode...
https://api.python.langchain.com/en/latest/prompts/langchain.prompts.few_shot.FewShotChatMessagePromptTemplate.html