id
stringlengths
14
16
text
stringlengths
13
2.7k
source
stringlengths
57
178
22449ede29f6-7
API. Use this method when you want to: take advantage of batched calls, need more output from the model than just the top generated value, are building chains that are agnostic to the underlying language modeltype (e.g., pure text completion models vs chat models). Parameters prompts – List of PromptValues. A PromptValue is an object that can be converted to match the format of any language model (string for pure text generation models and BaseMessages for chat models). stop – Stop words to use when generating. Model output is cut off at the first occurrence of any of these substrings. callbacks – Callbacks to pass through. Used for executing additional functionality, such as logging or streaming, throughout generation. **kwargs – Arbitrary additional keyword arguments. These are usually passed to the model provider API call. Returns An LLMResult, which contains a list of candidate Generations for each inputprompt and additional model provider-specific output. 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 – A config to use when generating the schema. Returns A pydantic model that can be used to validate input. 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”] get_num_tokens(text: str) → int¶
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.jinachat.JinaChat.html
22449ede29f6-8
get_num_tokens(text: str) → int¶ Get the number of tokens present in the text. Useful for checking if an input will fit in a model’s context window. Parameters text – The string input to tokenize. Returns The integer number of tokens in the text. get_num_tokens_from_messages(messages: List[BaseMessage]) → int¶ Get the number of tokens in the messages. Useful for checking if an input will fit in a model’s context window. Parameters messages – The message inputs to tokenize. Returns The sum of the number of tokens across the messages. get_output_schema(config: Optional[RunnableConfig] = None) → Type[BaseModel]¶ Get a pydantic model that can be used to validate output to the runnable. Runnables that leverage the configurable_fields and configurable_alternatives methods will have a dynamic output schema that depends on which configuration the runnable is invoked with. This method allows to get an output schema for a specific configuration. Parameters config – A config to use when generating the schema. Returns A pydantic model that can be used to validate output. get_token_ids(text: str) → List[int]¶ Return the ordered ids of the tokens in a text. Parameters text – The string input to tokenize. Returns A list of ids corresponding to the tokens in the text, in order they occurin the text. invoke(input: Union[PromptValue, str, List[BaseMessage]], config: Optional[RunnableConfig] = None, *, stop: Optional[List[str]] = None, **kwargs: Any) → BaseMessage¶ Transform a single input into an output. Override to implement. Parameters input – The input to the runnable. config – A config to use when invoking the runnable.
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.jinachat.JinaChat.html
22449ede29f6-9
config – A config to use when invoking the runnable. The config supports standard keys like ‘tags’, ‘metadata’ for tracing purposes, ‘max_concurrency’ for controlling how much work to do in parallel, and other keys. Please refer to the RunnableConfig for more details. Returns The output of the runnable. classmethod is_lc_serializable() → bool[source]¶ Return whether this model can be serialized by Langchain. 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_none: bool = False, encoder: Optional[Callable[[Any], Any]] = None, models_as_dict: bool = True, **dumps_kwargs: Any) → unicode¶ 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 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 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¶
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.jinachat.JinaChat.html
22449ede29f6-10
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¶ predict(text: str, *, stop: Optional[Sequence[str]] = None, **kwargs: Any) → str¶ Pass a single string input to the model and return a string prediction. Use this method when passing in raw text. If you want to pass in specifictypes of chat messages, use predict_messages. Parameters text – String input to pass to the model. stop – Stop words to use when generating. Model output is cut off at the first occurrence of any of these substrings. **kwargs – Arbitrary additional keyword arguments. These are usually passed to the model provider API call. Returns Top model prediction as a string. predict_messages(messages: List[BaseMessage], *, stop: Optional[Sequence[str]] = None, **kwargs: Any) → BaseMessage¶ Pass a message sequence to the model and return a message prediction. Use this method when passing in chat messages. If you want to pass in raw text,use predict. Parameters messages – A sequence of chat messages corresponding to a single model input. stop – Stop words to use when generating. Model output is cut off at the first occurrence of any of these substrings. **kwargs – Arbitrary additional keyword arguments. These are usually passed to the model provider API call. Returns Top model prediction as a message. classmethod schema(by_alias: bool = True, ref_template: unicode = '#/definitions/{model}') → DictStrAny¶ classmethod schema_json(*, by_alias: bool = True, ref_template: unicode = '#/definitions/{model}', **dumps_kwargs: Any) → unicode¶
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.jinachat.JinaChat.html
22449ede29f6-11
stream(input: Union[PromptValue, str, List[BaseMessage]], config: Optional[RunnableConfig] = None, *, stop: Optional[List[str]] = None, **kwargs: Any) → Iterator[BaseMessageChunk]¶ 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_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 output while 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 Runnable, returning a new Runnable. with_fallbacks(fallbacks: Sequence[Runnable[Input, Output]], *, exceptions_to_handle: Tuple[Type[BaseException], ...] = (<class 'Exception'>,)) → RunnableWithFallbacksT[Input, Output]¶ Add fallbacks to a runnable, returning a new Runnable. Parameters fallbacks – A sequence of runnables to try if the original runnable fails. exceptions_to_handle – A tuple of exception types to handle. Returns A new Runnable that will try the original runnable, and then each fallback in order, upon failures.
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.jinachat.JinaChat.html
22449ede29f6-12
fallback in order, upon failures. with_listeners(*, on_start: Optional[Listener] = None, on_end: Optional[Listener] = None, on_error: Optional[Listener] = None) → Runnable[Input, Output]¶ Bind lifecycle listeners to a Runnable, returning a new Runnable. on_start: Called before the runnable starts running, with the Run object. on_end: Called after the runnable finishes running, with the Run object. on_error: Called if the runnable throws an error, with the Run object. The Run object contains information about the run, including its id, type, input, output, error, start_time, end_time, and any tags or metadata added to the run. with_retry(*, retry_if_exception_type: ~typing.Tuple[~typing.Type[BaseException], ...] = (<class 'Exception'>,), wait_exponential_jitter: bool = True, stop_after_attempt: int = 3) → Runnable[Input, Output]¶ Create a new Runnable that retries the original runnable on exceptions. Parameters retry_if_exception_type – A tuple of exception types to retry on wait_exponential_jitter – Whether to add jitter to the wait time between retries stop_after_attempt – The maximum number of attempts to make before giving up Returns A new Runnable that retries the original runnable on exceptions. 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. property InputType: TypeAlias¶ Get the input type for this runnable. property OutputType: Any¶ Get the output type for this runnable. property config_specs: List[langchain.schema.runnable.utils.ConfigurableFieldSpec]¶ List configurable fields for this runnable.
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.jinachat.JinaChat.html
22449ede29f6-13
List configurable fields for this runnable. property input_schema: Type[pydantic.main.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”} property output_schema: Type[pydantic.main.BaseModel]¶ The type of output this runnable produces specified as a pydantic model. Examples using JinaChat¶ JinaChat
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.jinachat.JinaChat.html
78c9503636e4-0
langchain.chat_models.bedrock.ChatPromptAdapter¶ class langchain.chat_models.bedrock.ChatPromptAdapter[source]¶ Adapter class to prepare the inputs from Langchain to prompt format that Chat model expects. Methods __init__() convert_messages_to_prompt(provider, messages) __init__()¶ classmethod convert_messages_to_prompt(provider: str, messages: List[BaseMessage]) → str[source]¶
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.bedrock.ChatPromptAdapter.html
13dd0c5bbf33-0
langchain.chat_models.fireworks.acompletion_with_retry_streaming¶ async langchain.chat_models.fireworks.acompletion_with_retry_streaming(llm: ChatFireworks, use_retry: bool, *, run_manager: Optional[AsyncCallbackManagerForLLMRun] = None, **kwargs: Any) → Any[source]¶ Use tenacity to retry the completion call for streaming.
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.fireworks.acompletion_with_retry_streaming.html
878159846395-0
langchain.chat_models.minimax.MiniMaxChat¶ class langchain.chat_models.minimax.MiniMaxChat[source]¶ Bases: MinimaxCommon, BaseChatModel Wrapper around Minimax large language models. To use, you should have the environment variable MINIMAX_GROUP_ID and MINIMAX_API_KEY set with your API token, or pass it as a named parameter to the constructor. Example from langchain.chat_models import MiniMaxChat llm = MiniMaxChat(model_name="abab5-chat") 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 cache: Optional[bool] = None¶ Whether to cache the response. param callback_manager: Optional[BaseCallbackManager] = None¶ Callback manager to add to the run trace. param callbacks: Callbacks = None¶ Callbacks to add to the run trace. param max_tokens: int = 256¶ Denotes the number of tokens to predict per generation. param metadata: Optional[Dict[str, Any]] = None¶ Metadata to add to the run trace. param minimax_api_host: Optional[str] = None¶ param minimax_api_key: Optional[str] = None¶ param minimax_group_id: Optional[str] = None¶ param model: str = 'abab5.5-chat'¶ Model name to use. param model_kwargs: Dict[str, Any] [Optional]¶ Holds any model parameters valid for create call not explicitly specified. param tags: Optional[List[str]] = None¶ Tags to add to the run trace. param temperature: float = 0.7¶ A non-negative float that tunes the degree of randomness in generation. param top_p: float = 0.95¶
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.minimax.MiniMaxChat.html
878159846395-1
param top_p: float = 0.95¶ Total probability mass of tokens to consider at each step. param verbose: bool [Optional]¶ Whether to print out response text. __call__(messages: List[BaseMessage], stop: Optional[List[str]] = None, callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, **kwargs: Any) → BaseMessage¶ Call self as a function. 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. async agenerate(messages: List[List[BaseMessage]], stop: Optional[List[str]] = None, callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, *, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, run_name: Optional[str] = None, **kwargs: Any) → LLMResult¶ Top Level call async agenerate_prompt(prompts: List[PromptValue], stop: Optional[List[str]] = None, callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, **kwargs: Any) → LLMResult¶ Asynchronously pass a sequence of prompts and return model generations. This method should make use of batched calls for models that expose a batched API. Use this method when you want to: take advantage of batched calls, need more output from the model than just the top generated value,
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.minimax.MiniMaxChat.html
878159846395-2
need more output from the model than just the top generated value, are building chains that are agnostic to the underlying language modeltype (e.g., pure text completion models vs chat models). Parameters prompts – List of PromptValues. A PromptValue is an object that can be converted to match the format of any language model (string for pure text generation models and BaseMessages for chat models). stop – Stop words to use when generating. Model output is cut off at the first occurrence of any of these substrings. callbacks – Callbacks to pass through. Used for executing additional functionality, such as logging or streaming, throughout generation. **kwargs – Arbitrary additional keyword arguments. These are usually passed to the model provider API call. Returns An LLMResult, which contains a list of candidate Generations for each inputprompt and additional model provider-specific output. async ainvoke(input: Union[PromptValue, str, List[BaseMessage]], config: Optional[RunnableConfig] = None, *, stop: Optional[List[str]] = None, **kwargs: Any) → BaseMessage¶ 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. async apredict(text: str, *, stop: Optional[Sequence[str]] = None, **kwargs: Any) → str¶ Asynchronously pass a string to the model and return a string prediction. Use this method when calling pure text generation models and only the topcandidate generation is needed. Parameters text – String input to pass to the model. stop – Stop words to use when generating. Model output is cut off at the first occurrence of any of these substrings. **kwargs – Arbitrary additional keyword arguments. These are usually passed
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.minimax.MiniMaxChat.html
878159846395-3
**kwargs – Arbitrary additional keyword arguments. These are usually passed to the model provider API call. Returns Top model prediction as a string. async apredict_messages(messages: List[BaseMessage], *, stop: Optional[Sequence[str]] = None, **kwargs: Any) → BaseMessage¶ Asynchronously pass messages to the model and return a message prediction. Use this method when calling chat models and only the topcandidate generation is needed. Parameters messages – A sequence of chat messages corresponding to a single model input. stop – Stop words to use when generating. Model output is cut off at the first occurrence of any of these substrings. **kwargs – Arbitrary additional keyword arguments. These are usually passed to the model provider API call. Returns Top model prediction as a message. async astream(input: Union[PromptValue, str, List[BaseMessage]], config: Optional[RunnableConfig] = None, *, stop: Optional[List[str]] = None, **kwargs: Any) → AsyncIterator[BaseMessageChunk]¶ Default implementation of astream, which calls ainvoke. Subclasses should override this method if they support streaming output. async astream_log(input: Any, config: Optional[RunnableConfig] = None, *, diff: bool = True, include_names: Optional[Sequence[str]] = None, include_types: Optional[Sequence[str]] = None, include_tags: Optional[Sequence[str]] = None, exclude_names: Optional[Sequence[str]] = None, exclude_types: Optional[Sequence[str]] = None, exclude_tags: Optional[Sequence[str]] = None, **kwargs: Optional[Any]) → Union[AsyncIterator[RunLogPatch], AsyncIterator[RunLog]]¶ Stream all output from a runnable, as reported to the callback system. This includes all inner runs of LLMs, Retrievers, Tools, etc.
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.minimax.MiniMaxChat.html
878159846395-4
This includes all inner runs of LLMs, Retrievers, Tools, etc. Output is streamed as Log objects, which include a list of jsonpatch ops that describe how the state of the run has changed in each step, and the final state of the run. 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 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 runs invoke in parallel using a thread pool executor. 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. bind(**kwargs: Any) → Runnable[Input, Output]¶ Bind arguments to a Runnable, returning a new Runnable. call_as_llm(message: str, stop: Optional[List[str]] = None, **kwargs: Any) → str¶ config_schema(*, include: Optional[Sequence[str]] = None) → Type[BaseModel]¶ The type of config this runnable accepts specified as a pydantic model. To mark a field as configurable, see the configurable_fields and configurable_alternatives methods. Parameters include – A list of fields to include in the config schema. Returns A pydantic model that can be used to validate config.
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.minimax.MiniMaxChat.html
878159846395-5
Returns A pydantic model that can be used to validate config. configurable_alternatives(which: ConfigurableField, default_key: str = 'default', **kwargs: Union[Runnable[Input, Output], Callable[[], Runnable[Input, Output]]]) → RunnableSerializable[Input, Output]¶ configurable_fields(**kwargs: Union[ConfigurableField, ConfigurableFieldSingleOption, ConfigurableFieldMultiOption]) → RunnableSerializable[Input, Output]¶ 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 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 – 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 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(**kwargs: Any) → Dict¶ Return a dictionary of the LLM. classmethod from_orm(obj: Any) → Model¶
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.minimax.MiniMaxChat.html
878159846395-6
classmethod from_orm(obj: Any) → Model¶ generate(messages: List[List[BaseMessage]], stop: Optional[List[str]] = None, callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, *, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, run_name: Optional[str] = None, **kwargs: Any) → LLMResult¶ Top Level call generate_prompt(prompts: List[PromptValue], stop: Optional[List[str]] = None, callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, **kwargs: Any) → LLMResult¶ Pass a sequence of prompts to the model and return model generations. This method should make use of batched calls for models that expose a batched API. Use this method when you want to: take advantage of batched calls, need more output from the model than just the top generated value, are building chains that are agnostic to the underlying language modeltype (e.g., pure text completion models vs chat models). Parameters prompts – List of PromptValues. A PromptValue is an object that can be converted to match the format of any language model (string for pure text generation models and BaseMessages for chat models). stop – Stop words to use when generating. Model output is cut off at the first occurrence of any of these substrings. callbacks – Callbacks to pass through. Used for executing additional functionality, such as logging or streaming, throughout generation. **kwargs – Arbitrary additional keyword arguments. These are usually passed to the model provider API call. Returns An LLMResult, which contains a list of candidate Generations for each inputprompt and additional model provider-specific output. get_input_schema(config: Optional[RunnableConfig] = None) → Type[BaseModel]¶
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.minimax.MiniMaxChat.html
878159846395-7
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 – A config to use when generating the schema. Returns A pydantic model that can be used to validate input. 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”] get_num_tokens(text: str) → int¶ Get the number of tokens present in the text. Useful for checking if an input will fit in a model’s context window. Parameters text – The string input to tokenize. Returns The integer number of tokens in the text. get_num_tokens_from_messages(messages: List[BaseMessage]) → int¶ Get the number of tokens in the messages. Useful for checking if an input will fit in a model’s context window. Parameters messages – The message inputs to tokenize. Returns The sum of the number of tokens across the messages. get_output_schema(config: Optional[RunnableConfig] = None) → Type[BaseModel]¶ Get a pydantic model that can be used to validate output to the runnable. Runnables that leverage the configurable_fields and configurable_alternatives methods will have a dynamic output schema that depends on which configuration the runnable is invoked with. This method allows to get an output schema for a specific configuration. Parameters config – A config to use when generating the schema. Returns A pydantic model that can be used to validate output.
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.minimax.MiniMaxChat.html
878159846395-8
Returns A pydantic model that can be used to validate output. get_token_ids(text: str) → List[int]¶ Return the ordered ids of the tokens in a text. Parameters text – The string input to tokenize. Returns A list of ids corresponding to the tokens in the text, in order they occurin the text. invoke(input: Union[PromptValue, str, List[BaseMessage]], config: Optional[RunnableConfig] = None, *, stop: Optional[List[str]] = None, **kwargs: Any) → BaseMessage¶ Transform a single input into an output. Override to implement. Parameters input – The input to the runnable. config – A config to use when invoking the runnable. The config supports standard keys like ‘tags’, ‘metadata’ for tracing purposes, ‘max_concurrency’ for controlling how much work to do in parallel, and other keys. Please refer to the RunnableConfig for more details. Returns The output of the runnable. classmethod is_lc_serializable() → bool¶ Is this class 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 = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Optional[Callable[[Any], Any]] = None, models_as_dict: bool = True, **dumps_kwargs: Any) → unicode¶ 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]¶
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.minimax.MiniMaxChat.html
878159846395-9
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 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 = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶ predict(text: str, *, stop: Optional[Sequence[str]] = None, **kwargs: Any) → str¶ Pass a single string input to the model and return a string prediction. Use this method when passing in raw text. If you want to pass in specifictypes of chat messages, use predict_messages. Parameters text – String input to pass to the model. stop – Stop words to use when generating. Model output is cut off at the first occurrence of any of these substrings. **kwargs – Arbitrary additional keyword arguments. These are usually passed to the model provider API call. Returns Top model prediction as a string. predict_messages(messages: List[BaseMessage], *, stop: Optional[Sequence[str]] = None, **kwargs: Any) → BaseMessage¶ Pass a message sequence to the model and return a message prediction. Use this method when passing in chat messages. If you want to pass in raw text,use predict. Parameters messages – A sequence of chat messages corresponding to a single model input.
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.minimax.MiniMaxChat.html
878159846395-10
Parameters messages – A sequence of chat messages corresponding to a single model input. stop – Stop words to use when generating. Model output is cut off at the first occurrence of any of these substrings. **kwargs – Arbitrary additional keyword arguments. These are usually passed to the model provider API call. Returns Top model prediction as a message. classmethod schema(by_alias: bool = True, ref_template: unicode = '#/definitions/{model}') → DictStrAny¶ classmethod schema_json(*, by_alias: bool = True, ref_template: unicode = '#/definitions/{model}', **dumps_kwargs: Any) → unicode¶ stream(input: Union[PromptValue, str, List[BaseMessage]], config: Optional[RunnableConfig] = None, *, stop: Optional[List[str]] = None, **kwargs: Any) → Iterator[BaseMessageChunk]¶ 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_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 output while 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 Runnable, returning a new Runnable.
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.minimax.MiniMaxChat.html
878159846395-11
Bind config to a Runnable, returning a new Runnable. with_fallbacks(fallbacks: Sequence[Runnable[Input, Output]], *, exceptions_to_handle: Tuple[Type[BaseException], ...] = (<class 'Exception'>,)) → RunnableWithFallbacksT[Input, Output]¶ Add fallbacks to a runnable, returning a new Runnable. Parameters fallbacks – A sequence of runnables to try if the original runnable fails. exceptions_to_handle – A tuple of exception types to handle. Returns A new Runnable that will try the original runnable, and then each fallback in order, upon failures. with_listeners(*, on_start: Optional[Listener] = None, on_end: Optional[Listener] = None, on_error: Optional[Listener] = None) → Runnable[Input, Output]¶ Bind lifecycle listeners to a Runnable, returning a new Runnable. on_start: Called before the runnable starts running, with the Run object. on_end: Called after the runnable finishes running, with the Run object. on_error: Called if the runnable throws an error, with the Run object. The Run object contains information about the run, including its id, type, input, output, error, start_time, end_time, and any tags or metadata added to the run. with_retry(*, retry_if_exception_type: ~typing.Tuple[~typing.Type[BaseException], ...] = (<class 'Exception'>,), wait_exponential_jitter: bool = True, stop_after_attempt: int = 3) → Runnable[Input, Output]¶ Create a new Runnable that retries the original runnable on exceptions. Parameters retry_if_exception_type – A tuple of exception types to retry on wait_exponential_jitter – Whether to add jitter to the wait time between retries stop_after_attempt – The maximum number of attempts to make before giving up
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.minimax.MiniMaxChat.html
878159846395-12
between retries stop_after_attempt – The maximum number of attempts to make before giving up Returns A new Runnable that retries the original runnable on exceptions. 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. property InputType: TypeAlias¶ Get the input type for this runnable. property OutputType: Any¶ Get the output type for this runnable. property config_specs: List[langchain.schema.runnable.utils.ConfigurableFieldSpec]¶ List configurable fields for this runnable. property input_schema: Type[pydantic.main.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”} property output_schema: Type[pydantic.main.BaseModel]¶ The type of output this runnable produces specified as a pydantic model.
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.minimax.MiniMaxChat.html
50d1a460c5aa-0
langchain.chat_models.azure_openai.AzureChatOpenAI¶ class langchain.chat_models.azure_openai.AzureChatOpenAI[source]¶ Bases: ChatOpenAI Azure OpenAI Chat Completion API. To use this class you must have a deployed model on Azure OpenAI. Use deployment_name in the constructor to refer to the “Model deployment name” in the Azure portal. In addition, you should have the openai python package installed, and the following environment variables set or passed in constructor in lower case: - AZURE_OPENAI_API_KEY - AZURE_OPENAI_API_ENDPOINT - AZURE_OPENAI_AD_TOKEN - OPENAI_API_VERSION - OPENAI_PROXY For example, if you have gpt-35-turbo deployed, with the deployment name 35-turbo-dev, the constructor should look like: AzureChatOpenAI( azure_deployment="35-turbo-dev", openai_api_version="2023-05-15", ) Be aware the API version may change. You can also specify the version of the model using model_version constructor parameter, as Azure OpenAI doesn’t return model version with the response. Default is empty. When you specify the version, it will be appended to the model name in the response. Setting correct version will help you to calculate the cost properly. Model version is not validated, so make sure you set it correctly to get the correct cost. Any parameters that are valid to be passed to the openai.create call can be passed in, even if not explicitly saved on this class. 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 azure_ad_token: Union[str, None] = None¶ Your Azure Active Directory token.
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.azure_openai.AzureChatOpenAI.html
50d1a460c5aa-1
Your Azure Active Directory token. Automatically inferred from env var AZURE_OPENAI_AD_TOKEN if not provided. For more: https://www.microsoft.com/en-us/security/business/identity-access/microsoft-entra-id. param azure_ad_token_provider: Union[str, None] = None¶ A function that returns an Azure Active Directory token. Will be invoked on every request. param azure_endpoint: Union[str, None] = None¶ Your Azure endpoint, including the resource. Automatically inferred from env var AZURE_OPENAI_ENDPOINT if not provided. Example: https://example-resource.azure.openai.com/ param cache: Optional[bool] = None¶ Whether to cache the response. param callback_manager: Optional[BaseCallbackManager] = None¶ Callback manager to add to the run trace. param callbacks: Callbacks = None¶ Callbacks to add to the run trace. param default_headers: Union[Mapping[str, str], None] = None¶ param default_query: Union[Mapping[str, object], None] = None¶ param deployment_name: Union[str, None] = None (alias 'azure_deployment')¶ A model deployment. If given sets the base client URL to include /deployments/{azure_deployment}. Note: this means you won’t be able to use non-deployment endpoints. param http_client: Union[Any, None] = None¶ Optional httpx.Client. param max_retries: int = 2¶ Maximum number of retries to make when generating. param max_tokens: Optional[int] = None¶ Maximum number of tokens to generate. param metadata: Optional[Dict[str, Any]] = None¶ Metadata to add to the run trace. param model_kwargs: Dict[str, Any] [Optional]¶ Holds any model parameters valid for create call not explicitly specified.
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.azure_openai.AzureChatOpenAI.html
50d1a460c5aa-2
Holds any model parameters valid for create call not explicitly specified. param model_name: str = 'gpt-3.5-turbo' (alias 'model')¶ Model name to use. param model_version: str = ''¶ Legacy, for openai<1.0.0 support. param n: int = 1¶ Number of chat completions to generate for each prompt. param openai_api_base: Optional[str] = None (alias 'base_url')¶ Base URL path for API requests, leave blank if not using a proxy or service emulator. param openai_api_key: Union[str, None] = None (alias 'api_key')¶ Automatically inferred from env var AZURE_OPENAI_API_KEY if not provided. param openai_api_type: str = ''¶ Legacy, for openai<1.0.0 support. param openai_api_version: str = '' (alias 'api_version')¶ Automatically inferred from env var OPENAI_API_VERSION if not provided. param openai_organization: Optional[str] = None (alias 'organization')¶ Automatically inferred from env var OPENAI_ORG_ID if not provided. param openai_proxy: Optional[str] = None¶ param request_timeout: Union[float, Tuple[float, float], Any, None] = None (alias 'timeout')¶ Timeout for requests to OpenAI completion API. Can be float, httpx.Timeout or None. param streaming: bool = False¶ Whether to stream the results or not. param tags: Optional[List[str]] = None¶ Tags to add to the run trace. param temperature: float = 0.7¶ What sampling temperature to use. param tiktoken_model_name: Optional[str] = None¶ The model name to pass to tiktoken when using this class.
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.azure_openai.AzureChatOpenAI.html
50d1a460c5aa-3
The model name to pass to tiktoken when using this class. Tiktoken is used to count the number of tokens in documents to constrain them to be under a certain limit. By default, when set to None, this will be the same as the embedding model name. However, there are some cases where you may want to use this Embedding class with a model name not supported by tiktoken. This can include when using Azure embeddings or when using one of the many model providers that expose an OpenAI-like API but with different models. In those cases, in order to avoid erroring when tiktoken is called, you can specify a model name to use here. param validate_base_url: bool = True¶ For backwards compatibility. If legacy val openai_api_base is passed in, try to infer if it is a base_url or azure_endpoint and update accordingly. param verbose: bool [Optional]¶ Whether to print out response text. __call__(messages: List[BaseMessage], stop: Optional[List[str]] = None, callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, **kwargs: Any) → BaseMessage¶ Call self as a function. 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.
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.azure_openai.AzureChatOpenAI.html
50d1a460c5aa-4
e.g., if the underlying runnable uses an API which supports a batch mode. async agenerate(messages: List[List[BaseMessage]], stop: Optional[List[str]] = None, callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, *, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, run_name: Optional[str] = None, **kwargs: Any) → LLMResult¶ Top Level call async agenerate_prompt(prompts: List[PromptValue], stop: Optional[List[str]] = None, callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, **kwargs: Any) → LLMResult¶ Asynchronously pass a sequence of prompts and return model generations. This method should make use of batched calls for models that expose a batched API. Use this method when you want to: take advantage of batched calls, need more output from the model than just the top generated value, are building chains that are agnostic to the underlying language modeltype (e.g., pure text completion models vs chat models). Parameters prompts – List of PromptValues. A PromptValue is an object that can be converted to match the format of any language model (string for pure text generation models and BaseMessages for chat models). stop – Stop words to use when generating. Model output is cut off at the first occurrence of any of these substrings. callbacks – Callbacks to pass through. Used for executing additional functionality, such as logging or streaming, throughout generation. **kwargs – Arbitrary additional keyword arguments. These are usually passed to the model provider API call. Returns An LLMResult, which contains a list of candidate Generations for each inputprompt and additional model provider-specific output.
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.azure_openai.AzureChatOpenAI.html
50d1a460c5aa-5
async ainvoke(input: Union[PromptValue, str, List[BaseMessage]], config: Optional[RunnableConfig] = None, *, stop: Optional[List[str]] = None, **kwargs: Any) → BaseMessage¶ 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. async apredict(text: str, *, stop: Optional[Sequence[str]] = None, **kwargs: Any) → str¶ Asynchronously pass a string to the model and return a string prediction. Use this method when calling pure text generation models and only the topcandidate generation is needed. Parameters text – String input to pass to the model. stop – Stop words to use when generating. Model output is cut off at the first occurrence of any of these substrings. **kwargs – Arbitrary additional keyword arguments. These are usually passed to the model provider API call. Returns Top model prediction as a string. async apredict_messages(messages: List[BaseMessage], *, stop: Optional[Sequence[str]] = None, **kwargs: Any) → BaseMessage¶ Asynchronously pass messages to the model and return a message prediction. Use this method when calling chat models and only the topcandidate generation is needed. Parameters messages – A sequence of chat messages corresponding to a single model input. stop – Stop words to use when generating. Model output is cut off at the first occurrence of any of these substrings. **kwargs – Arbitrary additional keyword arguments. These are usually passed to the model provider API call. Returns Top model prediction as a message.
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.azure_openai.AzureChatOpenAI.html
50d1a460c5aa-6
to the model provider API call. Returns Top model prediction as a message. async astream(input: Union[PromptValue, str, List[BaseMessage]], config: Optional[RunnableConfig] = None, *, stop: Optional[List[str]] = None, **kwargs: Any) → AsyncIterator[BaseMessageChunk]¶ Default implementation of astream, which calls ainvoke. Subclasses should override this method if they support streaming output. async astream_log(input: Any, config: Optional[RunnableConfig] = None, *, diff: bool = True, include_names: Optional[Sequence[str]] = None, include_types: Optional[Sequence[str]] = None, include_tags: Optional[Sequence[str]] = None, exclude_names: Optional[Sequence[str]] = None, exclude_types: Optional[Sequence[str]] = None, exclude_tags: Optional[Sequence[str]] = None, **kwargs: Optional[Any]) → Union[AsyncIterator[RunLogPatch], AsyncIterator[RunLog]]¶ Stream all output from a runnable, as reported to the callback system. This includes all inner runs of LLMs, Retrievers, Tools, etc. Output is streamed as Log objects, which include a list of jsonpatch ops that describe how the state of the run has changed in each step, and the final state of the run. 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 they can start producing output while input is still being generated.
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.azure_openai.AzureChatOpenAI.html
50d1a460c5aa-7
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 runs invoke in parallel using a thread pool executor. 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. bind(**kwargs: Any) → Runnable[Input, Output]¶ Bind arguments to a Runnable, returning a new Runnable. bind_functions(functions: Sequence[Union[Dict[str, Any], Type[BaseModel], Callable]], function_call: Optional[str] = None, **kwargs: Any) → Runnable[Union[PromptValue, str, List[BaseMessage]], BaseMessage]¶ Bind functions (and other objects) to this chat model. Parameters functions – A list of function definitions to bind to this chat model. Can be a dictionary, pydantic model, or callable. Pydantic models and callables will be automatically converted to their schema dictionary representation. function_call – Which function to require the model to call. Must be the name of the single provided function or “auto” to automatically determine which function to call (if any). kwargs – Any additional parameters to pass to the Runnable constructor. call_as_llm(message: str, stop: Optional[List[str]] = None, **kwargs: Any) → str¶ completion_with_retry(run_manager: Optional[CallbackManagerForLLMRun] = None, **kwargs: Any) → Any¶ Use tenacity to retry the completion call. config_schema(*, include: Optional[Sequence[str]] = None) → Type[BaseModel]¶
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.azure_openai.AzureChatOpenAI.html
50d1a460c5aa-8
The type of config this runnable accepts specified as a pydantic model. To mark a field as configurable, see the configurable_fields and configurable_alternatives methods. Parameters include – A list of fields to include in the config schema. Returns A pydantic model that can be used to validate config. configurable_alternatives(which: ConfigurableField, default_key: str = 'default', **kwargs: Union[Runnable[Input, Output], Callable[[], Runnable[Input, Output]]]) → RunnableSerializable[Input, Output]¶ configurable_fields(**kwargs: Union[ConfigurableField, ConfigurableFieldSingleOption, ConfigurableFieldMultiOption]) → RunnableSerializable[Input, Output]¶ 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 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 – 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 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(**kwargs: Any) → Dict¶
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.azure_openai.AzureChatOpenAI.html
50d1a460c5aa-9
Returns new model instance dict(**kwargs: Any) → Dict¶ Return a dictionary of the LLM. classmethod from_orm(obj: Any) → Model¶ generate(messages: List[List[BaseMessage]], stop: Optional[List[str]] = None, callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, *, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, run_name: Optional[str] = None, **kwargs: Any) → LLMResult¶ Top Level call generate_prompt(prompts: List[PromptValue], stop: Optional[List[str]] = None, callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, **kwargs: Any) → LLMResult¶ Pass a sequence of prompts to the model and return model generations. This method should make use of batched calls for models that expose a batched API. Use this method when you want to: take advantage of batched calls, need more output from the model than just the top generated value, are building chains that are agnostic to the underlying language modeltype (e.g., pure text completion models vs chat models). Parameters prompts – List of PromptValues. A PromptValue is an object that can be converted to match the format of any language model (string for pure text generation models and BaseMessages for chat models). stop – Stop words to use when generating. Model output is cut off at the first occurrence of any of these substrings. callbacks – Callbacks to pass through. Used for executing additional functionality, such as logging or streaming, throughout generation. **kwargs – Arbitrary additional keyword arguments. These are usually passed to the model provider API call. Returns
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.azure_openai.AzureChatOpenAI.html
50d1a460c5aa-10
to the model provider API call. Returns An LLMResult, which contains a list of candidate Generations for each inputprompt and additional model provider-specific output. 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 – A config to use when generating the schema. Returns A pydantic model that can be used to validate input. 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”] get_num_tokens(text: str) → int¶ Get the number of tokens present in the text. Useful for checking if an input will fit in a model’s context window. Parameters text – The string input to tokenize. Returns The integer number of tokens in the text. get_num_tokens_from_messages(messages: List[BaseMessage]) → int¶ Calculate num tokens for gpt-3.5-turbo and gpt-4 with tiktoken package. Official documentation: https://github.com/openai/openai-cookbook/blob/ main/examples/How_to_format_inputs_to_ChatGPT_models.ipynb get_output_schema(config: Optional[RunnableConfig] = None) → Type[BaseModel]¶ Get a pydantic model that can be used to validate output to the runnable. Runnables that leverage the configurable_fields and configurable_alternatives
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.azure_openai.AzureChatOpenAI.html
50d1a460c5aa-11
Runnables that leverage the configurable_fields and configurable_alternatives methods will have a dynamic output schema that depends on which configuration the runnable is invoked with. This method allows to get an output schema for a specific configuration. Parameters config – A config to use when generating the schema. Returns A pydantic model that can be used to validate output. get_token_ids(text: str) → List[int]¶ Get the tokens present in the text with tiktoken package. invoke(input: Union[PromptValue, str, List[BaseMessage]], config: Optional[RunnableConfig] = None, *, stop: Optional[List[str]] = None, **kwargs: Any) → BaseMessage¶ Transform a single input into an output. Override to implement. Parameters input – The input to the runnable. config – A config to use when invoking the runnable. The config supports standard keys like ‘tags’, ‘metadata’ for tracing purposes, ‘max_concurrency’ for controlling how much work to do in parallel, and other keys. Please refer to the RunnableConfig for more details. Returns The output of the runnable. classmethod is_lc_serializable() → bool¶ Return whether this model can be serialized by Langchain. 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_none: bool = False, encoder: Optional[Callable[[Any], Any]] = None, models_as_dict: bool = True, **dumps_kwargs: Any) → unicode¶ Generate a JSON representation of the model, include and exclude arguments as per dict().
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.azure_openai.AzureChatOpenAI.html
50d1a460c5aa-12
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 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 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 = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶ predict(text: str, *, stop: Optional[Sequence[str]] = None, **kwargs: Any) → str¶ Pass a single string input to the model and return a string prediction. Use this method when passing in raw text. If you want to pass in specifictypes of chat messages, use predict_messages. Parameters text – String input to pass to the model. stop – Stop words to use when generating. Model output is cut off at the first occurrence of any of these substrings. **kwargs – Arbitrary additional keyword arguments. These are usually passed to the model provider API call. Returns Top model prediction as a string. predict_messages(messages: List[BaseMessage], *, stop: Optional[Sequence[str]] = None, **kwargs: Any) → BaseMessage¶ Pass a message sequence to the model and return a message prediction.
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.azure_openai.AzureChatOpenAI.html
50d1a460c5aa-13
Pass a message sequence to the model and return a message prediction. Use this method when passing in chat messages. If you want to pass in raw text,use predict. Parameters messages – A sequence of chat messages corresponding to a single model input. stop – Stop words to use when generating. Model output is cut off at the first occurrence of any of these substrings. **kwargs – Arbitrary additional keyword arguments. These are usually passed to the model provider API call. Returns Top model prediction as a message. classmethod schema(by_alias: bool = True, ref_template: unicode = '#/definitions/{model}') → DictStrAny¶ classmethod schema_json(*, by_alias: bool = True, ref_template: unicode = '#/definitions/{model}', **dumps_kwargs: Any) → unicode¶ stream(input: Union[PromptValue, str, List[BaseMessage]], config: Optional[RunnableConfig] = None, *, stop: Optional[List[str]] = None, **kwargs: Any) → Iterator[BaseMessageChunk]¶ 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_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 output while 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¶
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.azure_openai.AzureChatOpenAI.html
50d1a460c5aa-14
classmethod validate(value: Any) → Model¶ with_config(config: Optional[RunnableConfig] = None, **kwargs: Any) → Runnable[Input, Output]¶ Bind config to a Runnable, returning a new Runnable. with_fallbacks(fallbacks: Sequence[Runnable[Input, Output]], *, exceptions_to_handle: Tuple[Type[BaseException], ...] = (<class 'Exception'>,)) → RunnableWithFallbacksT[Input, Output]¶ Add fallbacks to a runnable, returning a new Runnable. Parameters fallbacks – A sequence of runnables to try if the original runnable fails. exceptions_to_handle – A tuple of exception types to handle. Returns A new Runnable that will try the original runnable, and then each fallback in order, upon failures. with_listeners(*, on_start: Optional[Listener] = None, on_end: Optional[Listener] = None, on_error: Optional[Listener] = None) → Runnable[Input, Output]¶ Bind lifecycle listeners to a Runnable, returning a new Runnable. on_start: Called before the runnable starts running, with the Run object. on_end: Called after the runnable finishes running, with the Run object. on_error: Called if the runnable throws an error, with the Run object. The Run object contains information about the run, including its id, type, input, output, error, start_time, end_time, and any tags or metadata added to the run. with_retry(*, retry_if_exception_type: ~typing.Tuple[~typing.Type[BaseException], ...] = (<class 'Exception'>,), wait_exponential_jitter: bool = True, stop_after_attempt: int = 3) → Runnable[Input, Output]¶ Create a new Runnable that retries the original runnable on exceptions. Parameters
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.azure_openai.AzureChatOpenAI.html
50d1a460c5aa-15
Create a new Runnable that retries the original runnable on exceptions. Parameters retry_if_exception_type – A tuple of exception types to retry on wait_exponential_jitter – Whether to add jitter to the wait time between retries stop_after_attempt – The maximum number of attempts to make before giving up Returns A new Runnable that retries the original runnable on exceptions. 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. property InputType: TypeAlias¶ Get the input type for this runnable. property OutputType: Any¶ Get the output type for this runnable. property config_specs: List[langchain.schema.runnable.utils.ConfigurableFieldSpec]¶ List configurable fields for this runnable. property input_schema: Type[pydantic.main.BaseModel]¶ The type of input this runnable accepts specified as a pydantic model. property lc_attributes: Dict[str, Any]¶ 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”} property output_schema: Type[pydantic.main.BaseModel]¶ The type of output this runnable produces specified as a pydantic model. Examples using AzureChatOpenAI¶ Azure Azure OpenAI
lang/api.python.langchain.com/en/latest/chat_models/langchain.chat_models.azure_openai.AzureChatOpenAI.html
a784db12ddd4-0
langchain.chat_loaders.imessage.IMessageChatLoader¶ class langchain.chat_loaders.imessage.IMessageChatLoader(path: Optional[Union[str, Path]] = None)[source]¶ Load chat sessions from the iMessage chat.db SQLite file. It only works on macOS when you have iMessage enabled and have the chat.db file. The chat.db file is likely located at ~/Library/Messages/chat.db. However, your terminal may not have permission to access this file. To resolve this, you can copy the file to a different location, change the permissions of the file, or grant full disk access for your terminal emulator in System Settings > Security and Privacy > Full Disk Access. Initialize the IMessageChatLoader. Parameters path (str or Path, optional) – Path to the chat.db SQLite file. Defaults to None, in which case the default path ~/Library/Messages/chat.db will be used. Methods __init__([path]) Initialize the IMessageChatLoader. lazy_load() Lazy load the chat sessions from the iMessage chat.db and yield them in the required format. load() Eagerly load the chat sessions into memory. __init__(path: Optional[Union[str, Path]] = None)[source]¶ Initialize the IMessageChatLoader. Parameters path (str or Path, optional) – Path to the chat.db SQLite file. Defaults to None, in which case the default path ~/Library/Messages/chat.db will be used. lazy_load() → Iterator[ChatSession][source]¶ Lazy load the chat sessions from the iMessage chat.db and yield them in the required format. Yields ChatSession – Loaded chat session. load() → List[ChatSession]¶ Eagerly load the chat sessions into memory. Examples using IMessageChatLoader¶ iMessage
lang/api.python.langchain.com/en/latest/chat_loaders/langchain.chat_loaders.imessage.IMessageChatLoader.html
8cb9e8b0278a-0
langchain.chat_loaders.utils.merge_chat_runs_in_session¶ langchain.chat_loaders.utils.merge_chat_runs_in_session(chat_session: ChatSession, delimiter: str = '\n\n') → ChatSession[source]¶ Merge chat runs together in a chat session. A chat run is a sequence of messages from the same sender. Parameters chat_session – A chat session. Returns A chat session with merged chat runs.
lang/api.python.langchain.com/en/latest/chat_loaders/langchain.chat_loaders.utils.merge_chat_runs_in_session.html
a320ebde5e83-0
langchain.chat_loaders.facebook_messenger.SingleFileFacebookMessengerChatLoader¶ class langchain.chat_loaders.facebook_messenger.SingleFileFacebookMessengerChatLoader(path: Union[Path, str])[source]¶ Load Facebook Messenger chat data from a single file. Parameters path (Union[Path, str]) – The path to the chat file. path¶ The path to the chat file. Type Path Methods __init__(path) lazy_load() Lazy loads the chat data from the file. load() Eagerly load the chat sessions into memory. __init__(path: Union[Path, str]) → None[source]¶ lazy_load() → Iterator[ChatSession][source]¶ Lazy loads the chat data from the file. Yields ChatSession – A chat session containing the loaded messages. load() → List[ChatSession]¶ Eagerly load the chat sessions into memory. Examples using SingleFileFacebookMessengerChatLoader¶ Facebook Messenger
lang/api.python.langchain.com/en/latest/chat_loaders/langchain.chat_loaders.facebook_messenger.SingleFileFacebookMessengerChatLoader.html
a6e14632bc6f-0
langchain.chat_loaders.gmail.GMailLoader¶ class langchain.chat_loaders.gmail.GMailLoader(creds: Any, n: int = 100, raise_error: bool = False)[source]¶ Load data from GMail. There are many ways you could want to load data from GMail. This loader is currently fairly opinionated in how to do so. The way it does it is it first looks for all messages that you have sent. It then looks for messages where you are responding to a previous email. It then fetches that previous email, and creates a training example of that email, followed by your email. Note that there are clear limitations here. For example, all examples created are only looking at the previous email for context. To use: Set up a Google Developer Account:Go to the Google Developer Console, create a project, and enable the Gmail API for that project. This will give you a credentials.json file that you’ll need later. Methods __init__(creds[, n, raise_error]) lazy_load() Lazy load the chat sessions. load() Eagerly load the chat sessions into memory. __init__(creds: Any, n: int = 100, raise_error: bool = False) → None[source]¶ lazy_load() → Iterator[ChatSession][source]¶ Lazy load the chat sessions. load() → List[ChatSession]¶ Eagerly load the chat sessions into memory. Examples using GMailLoader¶ GMail
lang/api.python.langchain.com/en/latest/chat_loaders/langchain.chat_loaders.gmail.GMailLoader.html
5873ffb75469-0
langchain.chat_loaders.telegram.TelegramChatLoader¶ class langchain.chat_loaders.telegram.TelegramChatLoader(path: Union[str, Path])[source]¶ Load telegram conversations to LangChain chat messages. To export, use the Telegram Desktop app from https://desktop.telegram.org/, select a conversation, click the three dots in the top right corner, and select “Export chat history”. Then select “Machine-readable JSON” (preferred) to export. Note: the ‘lite’ versions of the desktop app (like “Telegram for MacOS”) do not support exporting chat history. Initialize the TelegramChatLoader. Parameters path (Union[str, Path]) – Path to the exported Telegram chat zip, directory, json, or HTML file. Methods __init__(path) Initialize the TelegramChatLoader. lazy_load() Lazy load the messages from the chat file and yield them in as chat sessions. load() Eagerly load the chat sessions into memory. __init__(path: Union[str, Path])[source]¶ Initialize the TelegramChatLoader. Parameters path (Union[str, Path]) – Path to the exported Telegram chat zip, directory, json, or HTML file. lazy_load() → Iterator[ChatSession][source]¶ Lazy load the messages from the chat file and yield them in as chat sessions. Yields ChatSession – The loaded chat session. load() → List[ChatSession]¶ Eagerly load the chat sessions into memory. Examples using TelegramChatLoader¶ Telegram
lang/api.python.langchain.com/en/latest/chat_loaders/langchain.chat_loaders.telegram.TelegramChatLoader.html
040a03f9d70a-0
langchain.chat_loaders.slack.SlackChatLoader¶ class langchain.chat_loaders.slack.SlackChatLoader(path: Union[str, Path])[source]¶ Load Slack conversations from a dump zip file. Initialize the chat loader with the path to the exported Slack dump zip file. Parameters path – Path to the exported Slack dump zip file. Methods __init__(path) Initialize the chat loader with the path to the exported Slack dump zip file. lazy_load() Lazy load the chat sessions from the Slack dump file and yield them in the required format. load() Eagerly load the chat sessions into memory. __init__(path: Union[str, Path])[source]¶ Initialize the chat loader with the path to the exported Slack dump zip file. Parameters path – Path to the exported Slack dump zip file. lazy_load() → Iterator[ChatSession][source]¶ Lazy load the chat sessions from the Slack dump file and yield them in the required format. Returns Iterator of chat sessions containing messages. load() → List[ChatSession]¶ Eagerly load the chat sessions into memory. Examples using SlackChatLoader¶ Slack
lang/api.python.langchain.com/en/latest/chat_loaders/langchain.chat_loaders.slack.SlackChatLoader.html
89bcaa648e1c-0
langchain.chat_loaders.whatsapp.WhatsAppChatLoader¶ class langchain.chat_loaders.whatsapp.WhatsAppChatLoader(path: str)[source]¶ Load WhatsApp conversations from a dump zip file or directory. Initialize the WhatsAppChatLoader. Parameters path (str) – Path to the exported WhatsApp chat zip directory, folder, or file. To generate the dump, open the chat, click the three dots in the top right corner, and select “More”. Then select “Export chat” and choose “Without media”. Methods __init__(path) Initialize the WhatsAppChatLoader. lazy_load() Lazy load the messages from the chat file and yield them as chat sessions. load() Eagerly load the chat sessions into memory. __init__(path: str)[source]¶ Initialize the WhatsAppChatLoader. Parameters path (str) – Path to the exported WhatsApp chat zip directory, folder, or file. To generate the dump, open the chat, click the three dots in the top right corner, and select “More”. Then select “Export chat” and choose “Without media”. lazy_load() → Iterator[ChatSession][source]¶ Lazy load the messages from the chat file and yield them as chat sessions. Yields Iterator[ChatSession] – The loaded chat sessions. load() → List[ChatSession]¶ Eagerly load the chat sessions into memory. Examples using WhatsAppChatLoader¶ WhatsApp WhatsApp Chat
lang/api.python.langchain.com/en/latest/chat_loaders/langchain.chat_loaders.whatsapp.WhatsAppChatLoader.html
e43afedd7eb3-0
langchain.chat_loaders.facebook_messenger.FolderFacebookMessengerChatLoader¶ class langchain.chat_loaders.facebook_messenger.FolderFacebookMessengerChatLoader(path: Union[str, Path])[source]¶ Load Facebook Messenger chat data from a folder. Parameters path (Union[str, Path]) – The path to the directory containing the chat files. path¶ The path to the directory containing the chat files. Type Path Methods __init__(path) lazy_load() Lazy loads the chat data from the folder. load() Eagerly load the chat sessions into memory. __init__(path: Union[str, Path]) → None[source]¶ lazy_load() → Iterator[ChatSession][source]¶ Lazy loads the chat data from the folder. Yields ChatSession – A chat session containing the loaded messages. load() → List[ChatSession]¶ Eagerly load the chat sessions into memory. Examples using FolderFacebookMessengerChatLoader¶ Facebook Messenger Chat loaders
lang/api.python.langchain.com/en/latest/chat_loaders/langchain.chat_loaders.facebook_messenger.FolderFacebookMessengerChatLoader.html
db0b9c1afb76-0
langchain.chat_loaders.utils.map_ai_messages_in_session¶ langchain.chat_loaders.utils.map_ai_messages_in_session(chat_sessions: ChatSession, sender: str) → ChatSession[source]¶ Convert messages from the specified ‘sender’ to AI messages. This is useful for fine-tuning the AI to adapt to your voice.
lang/api.python.langchain.com/en/latest/chat_loaders/langchain.chat_loaders.utils.map_ai_messages_in_session.html
68a57d230eb4-0
langchain.chat_loaders.base.BaseChatLoader¶ class langchain.chat_loaders.base.BaseChatLoader[source]¶ Base class for chat loaders. Methods __init__() lazy_load() Lazy load the chat sessions. load() Eagerly load the chat sessions into memory. __init__()¶ abstract lazy_load() → Iterator[ChatSession][source]¶ Lazy load the chat sessions. load() → List[ChatSession][source]¶ Eagerly load the chat sessions into memory.
lang/api.python.langchain.com/en/latest/chat_loaders/langchain.chat_loaders.base.BaseChatLoader.html
abeafee5c022-0
langchain.chat_loaders.utils.merge_chat_runs¶ langchain.chat_loaders.utils.merge_chat_runs(chat_sessions: Iterable[ChatSession]) → Iterator[ChatSession][source]¶ Merge chat runs together. A chat run is a sequence of messages from the same sender. Parameters chat_sessions – A list of chat sessions. Returns A list of chat sessions with merged chat runs. Examples using merge_chat_runs¶ Facebook Messenger Slack WhatsApp iMessage Telegram Discord
lang/api.python.langchain.com/en/latest/chat_loaders/langchain.chat_loaders.utils.merge_chat_runs.html
66c5516fabd9-0
langchain.chat_loaders.utils.map_ai_messages¶ langchain.chat_loaders.utils.map_ai_messages(chat_sessions: Iterable[ChatSession], sender: str) → Iterator[ChatSession][source]¶ Convert messages from the specified ‘sender’ to AI messages. This is useful for fine-tuning the AI to adapt to your voice. Examples using map_ai_messages¶ Facebook Messenger GMail Slack WhatsApp iMessage Telegram Discord
lang/api.python.langchain.com/en/latest/chat_loaders/langchain.chat_loaders.utils.map_ai_messages.html
0f64d3ee668c-0
langchain.chat_loaders.langsmith.LangSmithDatasetChatLoader¶ class langchain.chat_loaders.langsmith.LangSmithDatasetChatLoader(*, dataset_name: str, client: Optional['Client'] = None)[source]¶ Load chat sessions from a LangSmith dataset with the “chat” data type. dataset_name¶ The name of the LangSmith dataset. Type str client¶ Instance of LangSmith client for fetching data. Type Client Initialize a new LangSmithChatDatasetLoader instance. Parameters dataset_name – The name of the LangSmith dataset. client – An instance of LangSmith client; if not provided, a new client instance will be created. Methods __init__(*, dataset_name[, client]) Initialize a new LangSmithChatDatasetLoader instance. lazy_load() Lazy load the chat sessions from the specified LangSmith dataset. load() Eagerly load the chat sessions into memory. __init__(*, dataset_name: str, client: Optional['Client'] = None)[source]¶ Initialize a new LangSmithChatDatasetLoader instance. Parameters dataset_name – The name of the LangSmith dataset. client – An instance of LangSmith client; if not provided, a new client instance will be created. lazy_load() → Iterator[ChatSession][source]¶ Lazy load the chat sessions from the specified LangSmith dataset. This method fetches the chat data from the dataset and converts each data point to chat sessions on-the-fly, yielding one session at a time. Returns Iterator of chat sessions containing messages. load() → List[ChatSession]¶ Eagerly load the chat sessions into memory.
lang/api.python.langchain.com/en/latest/chat_loaders/langchain.chat_loaders.langsmith.LangSmithDatasetChatLoader.html
8202a5fb4333-0
langchain.chat_loaders.langsmith.LangSmithRunChatLoader¶ class langchain.chat_loaders.langsmith.LangSmithRunChatLoader(runs: Iterable[Union[str, Run]], client: Optional['Client'] = None)[source]¶ Load chat sessions from a list of LangSmith “llm” runs. runs¶ The list of LLM run IDs or run objects. Type Iterable[Union[str, Run]] client¶ Instance of LangSmith client for fetching data. Type Client Initialize a new LangSmithRunChatLoader instance. Parameters runs – List of LLM run IDs or run objects. client – An instance of LangSmith client, if not provided, a new client instance will be created. Methods __init__(runs[, client]) Initialize a new LangSmithRunChatLoader instance. lazy_load() Lazy load the chat sessions from the iterable of run IDs. load() Eagerly load the chat sessions into memory. __init__(runs: Iterable[Union[str, Run]], client: Optional['Client'] = None)[source]¶ Initialize a new LangSmithRunChatLoader instance. Parameters runs – List of LLM run IDs or run objects. client – An instance of LangSmith client, if not provided, a new client instance will be created. lazy_load() → Iterator[ChatSession][source]¶ Lazy load the chat sessions from the iterable of run IDs. This method fetches the runs and converts them to chat sessions on-the-fly, yielding one session at a time. Returns Iterator of chat sessions containing messages. load() → List[ChatSession]¶ Eagerly load the chat sessions into memory.
lang/api.python.langchain.com/en/latest/chat_loaders/langchain.chat_loaders.langsmith.LangSmithRunChatLoader.html
0305acca9815-0
langchain_experimental.rl_chain.base.embed_dict_type¶ langchain_experimental.rl_chain.base.embed_dict_type(item: Dict, model: Any) → Dict[str, Any][source]¶ Helper function to embed a dictionary item.
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.base.embed_dict_type.html
262a0cb7d104-0
langchain_experimental.rl_chain.pick_best_chain.PickBestSelected¶ class langchain_experimental.rl_chain.pick_best_chain.PickBestSelected(index: Optional[int] = None, probability: Optional[float] = None, score: Optional[float] = None)[source]¶ Attributes index probability score Methods __init__([index, probability, score]) __init__(index: Optional[int] = None, probability: Optional[float] = None, score: Optional[float] = None)[source]¶
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.pick_best_chain.PickBestSelected.html
eae2e12d96b2-0
langchain_experimental.rl_chain.base.ToSelectFrom¶ langchain_experimental.rl_chain.base.ToSelectFrom(anything: Any) → _ToSelectFrom[source]¶
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.base.ToSelectFrom.html
aee80cad87de-0
langchain_experimental.rl_chain.base.get_based_on_and_to_select_from¶ langchain_experimental.rl_chain.base.get_based_on_and_to_select_from(inputs: Dict[str, Any]) → Tuple[Dict, Dict][source]¶
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.base.get_based_on_and_to_select_from.html
940acd484191-0
langchain_experimental.rl_chain.pick_best_chain.PickBest¶ class langchain_experimental.rl_chain.pick_best_chain.PickBest[source]¶ Bases: RLChain[PickBestEvent] PickBest is a class designed to leverage the Vowpal Wabbit (VW) model for reinforcement learning with a context, with the goal of modifying the prompt before the LLM call. Each invocation of the chain’s run() method should be equipped with a set of potential actions (ToSelectFrom) and will result in the selection of a specific action based on the BasedOn input. This chosen action then informs the LLM (Language Model) prompt for the subsequent response generation. The standard operation flow of this Chain includes: The Chain is invoked with inputs containing the BasedOn criteria and a list of potential actions (ToSelectFrom). An action is selected based on the BasedOn input. The LLM is called with the dynamic prompt, producing a response. If a selection_scorer is provided, it is used to score the selection. The internal Vowpal Wabbit model is updated with the BasedOn input, the chosen ToSelectFrom action, and the resulting score from the scorer. The final response is returned. Expected input dictionary format: At least one variable encapsulated within BasedOn to serve as the selection criteria. A single list variable within ToSelectFrom, representing potential actions for the VW model. This list can take the form of: A list of strings, e.g., action = ToSelectFrom([“action1”, “action2”, “action3”]) A list of list of strings e.g. action = ToSelectFrom([[“action1”, “another identifier of action1”], [“action2”, “another identifier of action2”]])
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.pick_best_chain.PickBest.html
940acd484191-1
A list of dictionaries, where each dictionary represents an action with namespace names as keys and corresponding action strings as values. For instance, action = ToSelectFrom([{“namespace1”: [“action1”, “another identifier of action1”], “namespace2”: “action2”}, {“namespace1”: “action3”, “namespace2”: “action4”}]). Extends:RLChain feature_embedder¶ Is an advanced attribute. Responsible for embedding the BasedOn and ToSelectFrom inputs. If omitted, a default embedder is utilized. Type PickBestFeatureEmbedder, optional 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 active_policy: Policy = <langchain_experimental.rl_chain.base.RLChain._NoOpPolicy object>¶ param auto_embed: bool = False¶ 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 llm_chain: Chain [Required]¶ 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¶
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.pick_best_chain.PickBest.html
940acd484191-2
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 metrics: Optional[Union[MetricsTrackerRollingWindow, MetricsTrackerAverage]] = None¶ param prompt: BasePromptTemplate [Required]¶ param selection_scorer: Union[SelectionScorer, None] = None¶ param selection_scorer_activated: bool = True¶ 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]¶ Execute the chain. Parameters inputs – 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.
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.pick_best_chain.PickBest.html
940acd484191-3
Chain.input_keys except for inputs that will be set by the chain’s memory. return_only_outputs – 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 – 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. tags – List of string tags to pass to all callbacks. These will be passed in addition to tags passed to the chain during construction, but only these runtime tags will propagate to calls to other objects. metadata – Optional metadata associated with the chain. Defaults to None include_run_info – Whether to include run info in the response. Defaults to False. Returns A dict of named outputs. Should contain all outputs specified inChain.output_keys. 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.
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.pick_best_chain.PickBest.html
940acd484191-4
e.g., if the underlying runnable uses an API which supports a batch mode. async acall(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]¶ Asynchronously execute the chain. Parameters inputs – 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 – 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 – 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. tags – List of string tags to pass to all callbacks. These will be passed in addition to tags passed to the chain during construction, but only these runtime tags will propagate to calls to other objects. metadata – Optional metadata associated with the chain. Defaults to None include_run_info – Whether to include run info in the response. Defaults to False. Returns A dict of named outputs. Should contain all outputs specified inChain.output_keys. activate_selection_scorer() → None¶ Activates the selection scorer, meaning that the chain will attempt to use the selection scorer to score responses.
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.pick_best_chain.PickBest.html
940acd484191-5
async ainvoke(input: Dict[str, Any], config: Optional[RunnableConfig] = None, **kwargs: Any) → Dict[str, Any]¶ 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. apply(input_list: List[Dict[str, Any]], callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None) → List[Dict[str, str]]¶ Call the chain on all inputs in the list. async arun(*args: Any, callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Convenience method for executing chain. The main difference between this method and Chain.__call__ is that this method expects inputs to be passed directly in as positional arguments or keyword arguments, whereas Chain.__call__ expects a single input dictionary with all the inputs Parameters *args – If the chain expects a single input, it can be passed in as the sole positional argument. callbacks – 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. tags – List of string tags to pass to all callbacks. These will be passed in addition to tags passed to the chain during construction, but only these runtime tags will propagate to calls to other objects. **kwargs – If the chain expects multiple inputs, they can be passed in directly as keyword arguments. Returns The chain output. Example
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.pick_best_chain.PickBest.html
940acd484191-6
directly as keyword arguments. Returns The chain output. Example # Suppose we have a single-input chain that takes a 'question' string: await chain.arun("What's the temperature in Boise, Idaho?") # -> "The temperature in Boise is..." # Suppose we have a multi-input chain that takes a 'question' string # and 'context' string: question = "What's the temperature in Boise, Idaho?" context = "Weather report for Boise, Idaho on 07/03/23..." await chain.arun(question=question, context=context) # -> "The temperature in Boise is..." async astream(input: Input, config: Optional[RunnableConfig] = None, **kwargs: Optional[Any]) → AsyncIterator[Output]¶ Default implementation of astream, which calls ainvoke. Subclasses should override this method if they support streaming output. async astream_log(input: Any, config: Optional[RunnableConfig] = None, *, diff: bool = True, include_names: Optional[Sequence[str]] = None, include_types: Optional[Sequence[str]] = None, include_tags: Optional[Sequence[str]] = None, exclude_names: Optional[Sequence[str]] = None, exclude_types: Optional[Sequence[str]] = None, exclude_tags: Optional[Sequence[str]] = None, **kwargs: Optional[Any]) → Union[AsyncIterator[RunLogPatch], AsyncIterator[RunLog]]¶ Stream all output from a runnable, as reported to the callback system. This includes all inner runs of LLMs, Retrievers, Tools, etc. Output is streamed as Log objects, which include a list of jsonpatch ops that describe how the state of the run has changed in each step, and the final state of the run. The jsonpatch ops can be applied in order to construct state.
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.pick_best_chain.PickBest.html
940acd484191-7
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 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 runs invoke in parallel using a thread pool executor. 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. bind(**kwargs: Any) → Runnable[Input, Output]¶ Bind arguments to a Runnable, returning a new Runnable. config_schema(*, include: Optional[Sequence[str]] = None) → Type[BaseModel]¶ The type of config this runnable accepts specified as a pydantic model. To mark a field as configurable, see the configurable_fields and configurable_alternatives methods. Parameters include – A list of fields to include in the config schema. Returns A pydantic model that can be used to validate config. configurable_alternatives(which: ConfigurableField, default_key: str = 'default', **kwargs: Union[Runnable[Input, Output], Callable[[], Runnable[Input, Output]]]) → RunnableSerializable[Input, Output]¶ configurable_fields(**kwargs: Union[ConfigurableField, ConfigurableFieldSingleOption, ConfigurableFieldMultiOption]) → RunnableSerializable[Input, Output]¶
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.pick_best_chain.PickBest.html
940acd484191-8
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 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 – 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 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 deactivate_selection_scorer() → None¶ Deactivates the selection scorer, meaning that the chain will no longer attempt to use the selection scorer to score responses. dict(**kwargs: Any) → Dict¶ Dictionary representation of chain. Expects Chain._chain_type property to be implemented and for memory to benull. Parameters **kwargs – Keyword arguments passed to default pydantic.BaseModel.dict method. Returns A dictionary representation of the chain. Example chain.dict(exclude_unset=True) # -> {"_type": "foo", "verbose": False, ...}
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.pick_best_chain.PickBest.html
940acd484191-9
# -> {"_type": "foo", "verbose": False, ...} classmethod from_llm(llm: ~langchain.schema.language_model.BaseLanguageModel, prompt: ~langchain.schema.prompt_template.BasePromptTemplate, selection_scorer: ~typing.Union[~langchain_experimental.rl_chain.base.AutoSelectionScorer, object] = <object object>, **kwargs: ~typing.Any) → PickBest[source]¶ classmethod from_orm(obj: Any) → Model¶ 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 – A config to use when generating the schema. Returns A pydantic model that can be used to validate input. 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”] get_output_schema(config: Optional[RunnableConfig] = None) → Type[BaseModel]¶ Get a pydantic model that can be used to validate output to the runnable. Runnables that leverage the configurable_fields and configurable_alternatives methods will have a dynamic output schema that depends on which configuration the runnable is invoked with. This method allows to get an output schema for a specific configuration. Parameters config – A config to use when generating the schema. Returns A pydantic model that can be used to validate output.
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.pick_best_chain.PickBest.html
940acd484191-10
Returns A pydantic model that can be used to validate output. invoke(input: Dict[str, Any], config: Optional[RunnableConfig] = None, **kwargs: Any) → Dict[str, Any]¶ Transform a single input into an output. Override to implement. Parameters input – The input to the runnable. config – A config to use when invoking the runnable. The config supports standard keys like ‘tags’, ‘metadata’ for tracing purposes, ‘max_concurrency’ for controlling how much work to do in parallel, and other keys. Please refer to the RunnableConfig for more details. Returns The output of the runnable. classmethod is_lc_serializable() → bool¶ Is this class 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 = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Optional[Callable[[Any], Any]] = None, models_as_dict: bool = True, **dumps_kwargs: Any) → unicode¶ 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 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 each input.
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.pick_best_chain.PickBest.html
940acd484191-11
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 = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶ prep_inputs(inputs: Union[Dict[str, Any], Any]) → Dict[str, str]¶ Validate and prepare chain inputs, including adding inputs from memory. Parameters inputs – Dictionary of raw 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. Returns A dictionary of all inputs, including those added by the chain’s memory. prep_outputs(inputs: Dict[str, str], outputs: Dict[str, str], return_only_outputs: bool = False) → Dict[str, str]¶ Validate and prepare chain outputs, and save info about this run to memory. Parameters inputs – Dictionary of chain inputs, including any inputs added by chain memory. outputs – Dictionary of initial chain outputs. return_only_outputs – Whether to only return the chain outputs. If False, inputs are also added to the final outputs. Returns A dict of the final chain outputs. run(*args: Any, callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Convenience method for executing chain. The main difference between this method and Chain.__call__ is that this
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.pick_best_chain.PickBest.html
940acd484191-12
The main difference between this method and Chain.__call__ is that this method expects inputs to be passed directly in as positional arguments or keyword arguments, whereas Chain.__call__ expects a single input dictionary with all the inputs Parameters *args – If the chain expects a single input, it can be passed in as the sole positional argument. callbacks – 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. tags – List of string tags to pass to all callbacks. These will be passed in addition to tags passed to the chain during construction, but only these runtime tags will propagate to calls to other objects. **kwargs – If the chain expects multiple inputs, they can be passed in directly as keyword arguments. Returns The chain output. Example # Suppose we have a single-input chain that takes a 'question' string: chain.run("What's the temperature in Boise, Idaho?") # -> "The temperature in Boise is..." # Suppose we have a multi-input chain that takes a 'question' string # and 'context' string: question = "What's the temperature in Boise, Idaho?" context = "Weather report for Boise, Idaho on 07/03/23..." chain.run(question=question, context=context) # -> "The temperature in Boise is..." save(file_path: Union[Path, str]) → None¶ Save the chain. Expects Chain._chain_type property to be implemented and for memory to benull. Parameters file_path – Path to file to save the chain to. Example chain.save(file_path="path/chain.yaml") save_progress() → None¶ This function should be called to save the state of the learned policy model.
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.pick_best_chain.PickBest.html
940acd484191-13
This function should be called to save the state of the learned policy model. classmethod schema(by_alias: bool = True, ref_template: unicode = '#/definitions/{model}') → DictStrAny¶ classmethod schema_json(*, by_alias: bool = True, ref_template: unicode = '#/definitions/{model}', **dumps_kwargs: Any) → 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. to_json() → Union[SerializedConstructor, SerializedNotImplemented]¶ 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 output while 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. update_with_delayed_score(score: float, chain_response: Dict[str, Any], force_score: bool = False) → None¶ Updates the learned policy with the score provided. Will raise an error if selection_scorer is set, and force_score=True was not provided during the method call classmethod validate(value: Any) → Model¶ with_config(config: Optional[RunnableConfig] = None, **kwargs: Any) → Runnable[Input, Output]¶ Bind config to a Runnable, returning a new Runnable.
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.pick_best_chain.PickBest.html
940acd484191-14
Bind config to a Runnable, returning a new Runnable. with_fallbacks(fallbacks: Sequence[Runnable[Input, Output]], *, exceptions_to_handle: Tuple[Type[BaseException], ...] = (<class 'Exception'>,)) → RunnableWithFallbacksT[Input, Output]¶ Add fallbacks to a runnable, returning a new Runnable. Parameters fallbacks – A sequence of runnables to try if the original runnable fails. exceptions_to_handle – A tuple of exception types to handle. Returns A new Runnable that will try the original runnable, and then each fallback in order, upon failures. with_listeners(*, on_start: Optional[Listener] = None, on_end: Optional[Listener] = None, on_error: Optional[Listener] = None) → Runnable[Input, Output]¶ Bind lifecycle listeners to a Runnable, returning a new Runnable. on_start: Called before the runnable starts running, with the Run object. on_end: Called after the runnable finishes running, with the Run object. on_error: Called if the runnable throws an error, with the Run object. The Run object contains information about the run, including its id, type, input, output, error, start_time, end_time, and any tags or metadata added to the run. with_retry(*, retry_if_exception_type: ~typing.Tuple[~typing.Type[BaseException], ...] = (<class 'Exception'>,), wait_exponential_jitter: bool = True, stop_after_attempt: int = 3) → Runnable[Input, Output]¶ Create a new Runnable that retries the original runnable on exceptions. Parameters retry_if_exception_type – A tuple of exception types to retry on wait_exponential_jitter – Whether to add jitter to the wait time between retries stop_after_attempt – The maximum number of attempts to make before giving up
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.pick_best_chain.PickBest.html
940acd484191-15
between retries stop_after_attempt – The maximum number of attempts to make before giving up Returns A new Runnable that retries the original runnable on exceptions. 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. property InputType: Type[langchain.schema.runnable.utils.Input]¶ The type of input this runnable accepts specified as a type annotation. property OutputType: Type[langchain.schema.runnable.utils.Output]¶ The type of output this runnable produces specified as a type annotation. property config_specs: List[langchain.schema.runnable.utils.ConfigurableFieldSpec]¶ List configurable fields for this runnable. property input_keys: List[str]¶ Expect input key. :meta private: property input_schema: Type[pydantic.main.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”} property output_schema: Type[pydantic.main.BaseModel]¶ The type of output this runnable produces specified as a pydantic model.
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.pick_best_chain.PickBest.html
9c69c7e0334a-0
langchain_experimental.rl_chain.base.Policy¶ class langchain_experimental.rl_chain.base.Policy(**kwargs: Any)[source]¶ Methods __init__(**kwargs) learn(event) log(event) predict(event) save() __init__(**kwargs: Any)[source]¶ abstract learn(event: TEvent) → None[source]¶ abstract log(event: TEvent) → None[source]¶ abstract predict(event: TEvent) → Any[source]¶ save() → None[source]¶
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.base.Policy.html
3e1fcaaaa373-0
langchain_experimental.rl_chain.base.VwPolicy¶ class langchain_experimental.rl_chain.base.VwPolicy(model_repo: ModelRepository, vw_cmd: List[str], feature_embedder: Embedder, vw_logger: VwLogger, *args: Any, **kwargs: Any)[source]¶ Methods __init__(model_repo, vw_cmd, ...) learn(event) log(event) predict(event) save() __init__(model_repo: ModelRepository, vw_cmd: List[str], feature_embedder: Embedder, vw_logger: VwLogger, *args: Any, **kwargs: Any)[source]¶ learn(event: TEvent) → None[source]¶ log(event: TEvent) → None[source]¶ predict(event: TEvent) → Any[source]¶ save() → None[source]¶
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.base.VwPolicy.html
d653fe19cee9-0
langchain_experimental.rl_chain.base.prepare_inputs_for_autoembed¶ langchain_experimental.rl_chain.base.prepare_inputs_for_autoembed(inputs: Dict[str, Any]) → Dict[str, Any][source]¶ go over all the inputs and if something is either wrapped in _ToSelectFrom or _BasedOn, and if their inner values are not already _Embed, then wrap them in EmbedAndKeep while retaining their _ToSelectFrom or _BasedOn status
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.base.prepare_inputs_for_autoembed.html
29844a900e07-0
langchain_experimental.rl_chain.model_repository.ModelRepository¶ class langchain_experimental.rl_chain.model_repository.ModelRepository(folder: Union[str, PathLike], with_history: bool = True, reset: bool = False)[source]¶ Methods __init__(folder[, with_history, reset]) get_tag() has_history() load(commandline) save(workspace) __init__(folder: Union[str, PathLike], with_history: bool = True, reset: bool = False)[source]¶ get_tag() → str[source]¶ has_history() → bool[source]¶ load(commandline: List[str]) → vw.Workspace[source]¶ save(workspace: vw.Workspace) → None[source]¶
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.model_repository.ModelRepository.html
c9b8cf473fcd-0
langchain_experimental.rl_chain.pick_best_chain.PickBestRandomPolicy¶ class langchain_experimental.rl_chain.pick_best_chain.PickBestRandomPolicy(feature_embedder: Embedder, **kwargs: Any)[source]¶ Methods __init__(feature_embedder, **kwargs) learn(event) log(event) predict(event) save() __init__(feature_embedder: Embedder, **kwargs: Any)[source]¶ learn(event: PickBestEvent) → None[source]¶ log(event: PickBestEvent) → None[source]¶ predict(event: PickBestEvent) → List[Tuple[int, float]][source]¶ save() → None¶
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.pick_best_chain.PickBestRandomPolicy.html
7a9b0eec93c5-0
langchain_experimental.rl_chain.base.stringify_embedding¶ langchain_experimental.rl_chain.base.stringify_embedding(embedding: List) → str[source]¶
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.base.stringify_embedding.html
9aa4eeaa2394-0
langchain_experimental.rl_chain.base.Selected¶ class langchain_experimental.rl_chain.base.Selected[source]¶ Methods __init__() __init__()¶
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.base.Selected.html
3528c277ac77-0
langchain_experimental.rl_chain.base.parse_lines¶ langchain_experimental.rl_chain.base.parse_lines(parser: vw.TextFormatParser, input_str: str) → List['vw.Example'][source]¶
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.base.parse_lines.html
e718f1d80b16-0
langchain_experimental.rl_chain.metrics.MetricsTrackerRollingWindow¶ class langchain_experimental.rl_chain.metrics.MetricsTrackerRollingWindow(window_size: int, step: int)[source]¶ Attributes score Methods __init__(window_size, step) on_decision() on_feedback(value) to_pandas() __init__(window_size: int, step: int)[source]¶ on_decision() → None[source]¶ on_feedback(value: float) → None[source]¶ to_pandas() → pd.DataFrame[source]¶
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.metrics.MetricsTrackerRollingWindow.html
384d38dbb928-0
langchain_experimental.rl_chain.metrics.MetricsTrackerAverage¶ class langchain_experimental.rl_chain.metrics.MetricsTrackerAverage(step: int)[source]¶ Attributes score Methods __init__(step) on_decision() on_feedback(score) to_pandas() __init__(step: int)[source]¶ on_decision() → None[source]¶ on_feedback(score: float) → None[source]¶ to_pandas() → pd.DataFrame[source]¶
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.metrics.MetricsTrackerAverage.html
a55edf129336-0
langchain_experimental.rl_chain.base.BasedOn¶ langchain_experimental.rl_chain.base.BasedOn(anything: Any) → _BasedOn[source]¶
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.base.BasedOn.html
52b364e26b2f-0
langchain_experimental.rl_chain.pick_best_chain.PickBestFeatureEmbedder¶ class langchain_experimental.rl_chain.pick_best_chain.PickBestFeatureEmbedder(auto_embed: bool, model: Optional[Any] = None, *args: Any, **kwargs: Any)[source]¶ Text Embedder class that embeds the BasedOn and ToSelectFrom inputs into a format that can be used by the learning policy model name The type of embeddings to be used for feature representation. Defaults to BERT SentenceTransformer. Type Any, optional Methods __init__(auto_embed[, model]) format(event) format_auto_embed_off(event) Converts the BasedOn and ToSelectFrom into a format that can be used by VW format_auto_embed_on(event) get_context_and_action_embeddings(event) get_indexed_dot_product(context_emb, action_embs) get_label(event) __init__(auto_embed: bool, model: Optional[Any] = None, *args: Any, **kwargs: Any)[source]¶ format(event: PickBestEvent) → str[source]¶ format_auto_embed_off(event: PickBestEvent) → str[source]¶ Converts the BasedOn and ToSelectFrom into a format that can be used by VW format_auto_embed_on(event: PickBestEvent) → str[source]¶ get_context_and_action_embeddings(event: PickBestEvent) → tuple[source]¶ get_indexed_dot_product(context_emb: List, action_embs: List) → Dict[source]¶ get_label(event: PickBestEvent) → tuple[source]¶
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.pick_best_chain.PickBestFeatureEmbedder.html
51ad3f944a36-0
langchain_experimental.rl_chain.vw_logger.VwLogger¶ class langchain_experimental.rl_chain.vw_logger.VwLogger(path: Optional[Union[str, PathLike]])[source]¶ Methods __init__(path) log(vw_ex) logging_enabled() __init__(path: Optional[Union[str, PathLike]])[source]¶ log(vw_ex: str) → None[source]¶ logging_enabled() → bool[source]¶
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.vw_logger.VwLogger.html
a0b6520316a2-0
langchain_experimental.rl_chain.base.AutoSelectionScorer¶ class langchain_experimental.rl_chain.base.AutoSelectionScorer[source]¶ Bases: SelectionScorer[Event], 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 llm_chain: langchain.chains.llm.LLMChain [Required]¶ param prompt: Optional[langchain.schema.prompt_template.BasePromptTemplate] = None¶ param scoring_criteria_template_str: Optional[str] = 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 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 – 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 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
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.base.AutoSelectionScorer.html
a0b6520316a2-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, exclude_defaults: bool = False, exclude_none: bool = False) → DictStrAny¶ Generate a dictionary representation of the model, optionally specifying which fields to include or exclude. classmethod from_orm(obj: Any) → Model¶ static get_default_prompt() → ChatPromptTemplate[source]¶ static get_default_system_prompt() → SystemMessagePromptTemplate[source]¶ 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_none: bool = False, encoder: Optional[Callable[[Any], Any]] = None, models_as_dict: bool = True, **dumps_kwargs: Any) → unicode¶ 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 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¶
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.base.AutoSelectionScorer.html
a0b6520316a2-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¶ classmethod schema_json(*, by_alias: bool = True, ref_template: unicode = '#/definitions/{model}', **dumps_kwargs: Any) → unicode¶ score_response(inputs: Dict[str, Any], llm_response: str, event: Event) → float[source]¶ 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¶
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.base.AutoSelectionScorer.html
9fb2f2cbc456-0
langchain_experimental.rl_chain.base.is_stringtype_instance¶ langchain_experimental.rl_chain.base.is_stringtype_instance(item: Any) → bool[source]¶ Helper function to check if an item is a string.
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.base.is_stringtype_instance.html
620e00b2bebc-0
langchain_experimental.rl_chain.base.Embed¶ langchain_experimental.rl_chain.base.Embed(anything: Any, keep: bool = False) → Any[source]¶
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.base.Embed.html
000fca84a00b-0
langchain_experimental.rl_chain.base.embed_list_type¶ langchain_experimental.rl_chain.base.embed_list_type(item: list, model: Any, namespace: Optional[str] = None) → List[Dict[str, Union[str, List[str]]]][source]¶
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.base.embed_list_type.html
6bfcced260ee-0
langchain_experimental.rl_chain.base.RLChain¶ class langchain_experimental.rl_chain.base.RLChain[source]¶ Bases: Chain, Generic[TEvent] The RLChain class leverages the Vowpal Wabbit (VW) model as a learned policy for reinforcement learning. - llm_chain Represents the underlying Language Model chain. Type Chain - prompt The template for the base prompt. Type BasePromptTemplate - selection_scorer Scorer for the selection. Can be set to None. Type Union[SelectionScorer, None] - policy The policy used by the chain to learn to populate a dynamic prompt. Type Optional[Policy] - auto_embed Determines if embedding should be automatic. Default is False. Type bool - metrics Tracker for metrics, can be set to None. Type Optional[Union[MetricsTrackerRollingWindow, MetricsTrackerAverage]] Initialization Attributes: feature_embedder (Embedder): Embedder used for the BasedOn and ToSelectFrom inputs. model_save_dir (str, optional): Directory for saving the VW model. Default is the current directory. reset_model (bool): If set to True, the model starts training from scratch. Default is False. vw_cmd (List[str], optional): Command line arguments for the VW model. policy (Type[VwPolicy]): Policy used by the chain. vw_logs (Optional[Union[str, os.PathLike]]): Path for the VW logs. metrics_step (int): Step for the metrics tracker. Default is -1. If set without metrics_window_size, average metrics will be tracked, otherwise rolling window metrics will be tracked. metrics_window_size (int): Window size for the metrics tracker. Default is -1. If set, rolling window metrics will be tracked. Notes
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.base.RLChain.html
6bfcced260ee-1
Notes The class initializes the VW model using the provided arguments. If selection_scorer is not provided, a warning is logged, indicating that no reinforcement learning will occur unless the update_with_delayed_score method is called. 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 active_policy: Policy = <langchain_experimental.rl_chain.base.RLChain._NoOpPolicy object>¶ param auto_embed: bool = False¶ 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 llm_chain: Chain [Required]¶ 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¶ 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 metrics: Optional[Union[MetricsTrackerRollingWindow, MetricsTrackerAverage]] = None¶
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.base.RLChain.html
6bfcced260ee-2
param prompt: BasePromptTemplate [Required]¶ param selection_scorer: Union[SelectionScorer, None] = None¶ param selection_scorer_activated: bool = True¶ 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]¶ Execute the chain. Parameters inputs – 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 – 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 – 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.
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.base.RLChain.html
6bfcced260ee-3
these runtime callbacks will propagate to calls to other objects. tags – List of string tags to pass to all callbacks. These will be passed in addition to tags passed to the chain during construction, but only these runtime tags will propagate to calls to other objects. metadata – Optional metadata associated with the chain. Defaults to None include_run_info – Whether to include run info in the response. Defaults to False. Returns A dict of named outputs. Should contain all outputs specified inChain.output_keys. 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. async acall(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]¶ Asynchronously execute the chain. Parameters inputs – 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 – 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
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.base.RLChain.html
6bfcced260ee-4
returned. If False, both input keys and new keys generated by this chain will be returned. Defaults to False. callbacks – 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. tags – List of string tags to pass to all callbacks. These will be passed in addition to tags passed to the chain during construction, but only these runtime tags will propagate to calls to other objects. metadata – Optional metadata associated with the chain. Defaults to None include_run_info – Whether to include run info in the response. Defaults to False. Returns A dict of named outputs. Should contain all outputs specified inChain.output_keys. activate_selection_scorer() → None[source]¶ Activates the selection scorer, meaning that the chain will attempt to use the selection scorer to score responses. async ainvoke(input: Dict[str, Any], config: Optional[RunnableConfig] = None, **kwargs: Any) → Dict[str, Any]¶ 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. apply(input_list: List[Dict[str, Any]], callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None) → List[Dict[str, str]]¶ Call the chain on all inputs in the list. async arun(*args: Any, callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶ Convenience method for executing chain.
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.base.RLChain.html
6bfcced260ee-5
Convenience method for executing chain. The main difference between this method and Chain.__call__ is that this method expects inputs to be passed directly in as positional arguments or keyword arguments, whereas Chain.__call__ expects a single input dictionary with all the inputs Parameters *args – If the chain expects a single input, it can be passed in as the sole positional argument. callbacks – 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. tags – List of string tags to pass to all callbacks. These will be passed in addition to tags passed to the chain during construction, but only these runtime tags will propagate to calls to other objects. **kwargs – If the chain expects multiple inputs, they can be passed in directly as keyword arguments. Returns The chain output. Example # Suppose we have a single-input chain that takes a 'question' string: await chain.arun("What's the temperature in Boise, Idaho?") # -> "The temperature in Boise is..." # Suppose we have a multi-input chain that takes a 'question' string # and 'context' string: question = "What's the temperature in Boise, Idaho?" context = "Weather report for Boise, Idaho on 07/03/23..." await chain.arun(question=question, context=context) # -> "The temperature in Boise is..." async astream(input: Input, config: Optional[RunnableConfig] = None, **kwargs: Optional[Any]) → AsyncIterator[Output]¶ Default implementation of astream, which calls ainvoke. Subclasses should override this method if they support streaming output.
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.base.RLChain.html
6bfcced260ee-6
Subclasses should override this method if they support streaming output. async astream_log(input: Any, config: Optional[RunnableConfig] = None, *, diff: bool = True, include_names: Optional[Sequence[str]] = None, include_types: Optional[Sequence[str]] = None, include_tags: Optional[Sequence[str]] = None, exclude_names: Optional[Sequence[str]] = None, exclude_types: Optional[Sequence[str]] = None, exclude_tags: Optional[Sequence[str]] = None, **kwargs: Optional[Any]) → Union[AsyncIterator[RunLogPatch], AsyncIterator[RunLog]]¶ Stream all output from a runnable, as reported to the callback system. This includes all inner runs of LLMs, Retrievers, Tools, etc. Output is streamed as Log objects, which include a list of jsonpatch ops that describe how the state of the run has changed in each step, and the final state of the run. 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 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 runs invoke in parallel using a thread pool executor. 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.
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.base.RLChain.html
6bfcced260ee-7
e.g., if the underlying runnable uses an API which supports a batch mode. bind(**kwargs: Any) → Runnable[Input, Output]¶ Bind arguments to a Runnable, returning a new Runnable. config_schema(*, include: Optional[Sequence[str]] = None) → Type[BaseModel]¶ The type of config this runnable accepts specified as a pydantic model. To mark a field as configurable, see the configurable_fields and configurable_alternatives methods. Parameters include – A list of fields to include in the config schema. Returns A pydantic model that can be used to validate config. configurable_alternatives(which: ConfigurableField, default_key: str = 'default', **kwargs: Union[Runnable[Input, Output], Callable[[], Runnable[Input, Output]]]) → RunnableSerializable[Input, Output]¶ configurable_fields(**kwargs: Union[ConfigurableField, ConfigurableFieldSingleOption, ConfigurableFieldMultiOption]) → RunnableSerializable[Input, Output]¶ 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 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 – fields to include in new model exclude – fields to exclude from new model, as with values this takes precedence over include
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.base.RLChain.html
6bfcced260ee-8
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 deactivate_selection_scorer() → None[source]¶ Deactivates the selection scorer, meaning that the chain will no longer attempt to use the selection scorer to score responses. dict(**kwargs: Any) → Dict¶ Dictionary representation of chain. Expects Chain._chain_type property to be implemented and for memory to benull. Parameters **kwargs – Keyword arguments passed to default pydantic.BaseModel.dict method. Returns A dictionary representation of the chain. Example chain.dict(exclude_unset=True) # -> {"_type": "foo", "verbose": False, ...} classmethod from_orm(obj: Any) → Model¶ 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 – A config to use when generating the schema. Returns A pydantic model that can be used to validate input. 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”]
lang/api.python.langchain.com/en/latest/rl_chain/langchain_experimental.rl_chain.base.RLChain.html